|
@@ -1,5 +1,6 @@
|
|
|
package com.kingdee.eas.custom.synctask;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.kingdee.bos.BOSException;
|
|
@@ -23,6 +24,7 @@ import com.kingdee.eas.custom.log.app.SyncEntityNameEnum;
|
|
|
import com.kingdee.eas.custom.log.app.SyncStatusEnum;
|
|
|
import com.kingdee.eas.custom.synctask.entity.AdminOrg;
|
|
|
import com.kingdee.eas.hr.ats.AtsUtil;
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
import com.kingdee.util.StringUtils;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -30,6 +32,8 @@ import org.apache.log4j.Logger;
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.Charset;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@@ -216,12 +220,15 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- private String getToken() {
|
|
|
+ private String getToken() throws BOSException {
|
|
|
String key = this.propt.getProperty("key");
|
|
|
+ if (StringUtils.isEmpty(key)) {
|
|
|
+ throw new BOSException("获取token key不能为空!");
|
|
|
+ }
|
|
|
long l = System.currentTimeMillis();//时间戳毫秒数
|
|
|
String code = key.concat(Long.toString(l));
|
|
|
String s = DigestUtils.md5Hex(code).toUpperCase();
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
+ Map<String, String> map = new HashMap<String, String>();
|
|
|
map.put("key", s);
|
|
|
map.put("ts", Long.toString(l));
|
|
|
logger.error("getToken" + JSONObject.toJSONString(map));
|
|
@@ -254,6 +261,105 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
super._syncPersonToOA(ctx, billds, action);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 从OA系统同步人员信息
|
|
|
+ * @param ctx
|
|
|
+ * @throws BOSException
|
|
|
+ * @throws EASBizException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ protected void _syncPersonFromOA(Context ctx) throws BOSException, EASBizException {
|
|
|
+ super._syncPersonFromOA(ctx);
|
|
|
+ ISyncLog iSyncLog = SyncLogFactory.getLocalInstance(ctx);
|
|
|
+ SyncLogInfo syncLogInfo = new SyncLogInfo();
|
|
|
+ syncLogInfo.setEntityName(SyncEntityNameEnum.person);
|
|
|
+ syncLogInfo.setDataDirection(DataDirectionEnum.flowInto);
|
|
|
+ syncLogInfo.setDockingSystem(DockingSystemEnum.OA);
|
|
|
+ try {
|
|
|
+ String updatePersonSql = "update t_bd_person set cfOAId = ? where fnumber = ?";
|
|
|
+ int pagesize = 2000;//每页数量
|
|
|
+ int curpage = 1;//当前页
|
|
|
+ int totalSize = 0;//总条数
|
|
|
+ int totalPage = 0;//总页数
|
|
|
+ List<Object[]> updateParams = new ArrayList<Object[]>();
|
|
|
+ boolean flag = true;
|
|
|
+ do {
|
|
|
+ totalSize = executeSyncPersonFromOA(updateParams, curpage, pagesize);
|
|
|
+ if (flag) {
|
|
|
+ totalPage = totalSize % pagesize == 0 ? totalSize / pagesize : totalSize / pagesize + 1;
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ curpage++;
|
|
|
+ } while (curpage <= totalPage);
|
|
|
+ if (!updateParams.isEmpty()) {
|
|
|
+ DbUtil.executeBatch(ctx, updatePersonSql, updateParams);
|
|
|
+ }
|
|
|
+ syncLogInfo.setSyncStatus(SyncStatusEnum.SUCCESS);
|
|
|
+ syncLogInfo.setSyncCount(updateParams.size());
|
|
|
+ syncLogInfo.setSuccessNum(updateParams.size());
|
|
|
+ iSyncLog.save(syncLogInfo);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
+ syncLogInfo.setSyncResult(e.getMessage());
|
|
|
+ iSyncLog.save(syncLogInfo);
|
|
|
+ throw new BOSException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 执行从OA系统同步人员信息
|
|
|
+ *
|
|
|
+ * @param updateParams
|
|
|
+ * @param curpage
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Integer executeSyncPersonFromOA(List<Object[]> updateParams, int curpage, int pagesize)
|
|
|
+ throws IOException, BOSException, EASBizException {
|
|
|
+ //封装请求参数
|
|
|
+ String params = String.format("token = %s ¶ms = {\"pagesize\":%d,\"curpage\":%d}", getToken(), pagesize, curpage);
|
|
|
+ logger.error("executeSyncPersonFromOA----------------------params" + params);
|
|
|
+ //封装请求参数
|
|
|
+ String syncPersonFromApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
|
|
|
+ logger.error("executeSyncPersonFromOA----------------------syncOrgUnitApiUrl" + syncPersonFromApiUrl);
|
|
|
+ if (StringUtils.isEmpty(syncPersonFromApiUrl)) {
|
|
|
+ throw new BOSException("获取人员接口地址不能为空!");
|
|
|
+ }
|
|
|
+ OkHttpClient client = new OkHttpClient();
|
|
|
+ MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
+ RequestBody body = RequestBody.create(mediaType, params);
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(syncPersonFromApiUrl)
|
|
|
+ .post(body)
|
|
|
+ .addHeader("content-type", "application/x-www-form-urlencoded")
|
|
|
+ .build();
|
|
|
+ Response response = client.newCall(request).execute();
|
|
|
+ String respBody = response.body().string();
|
|
|
+ JSONObject respMap = JSONObject.parseObject(respBody);
|
|
|
+ logger.error("handlerResponse--------------respMap" + respBody);
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+ String code = respMap.getString("code");
|
|
|
+ String msg = respMap.getString("msg");
|
|
|
+ if ("1".equals(code)) {
|
|
|
+ JSONObject respData = respMap.getJSONObject("data");
|
|
|
+ Integer totalSize = respData.getInteger("totalSize");
|
|
|
+ JSONArray respDataList = respData.getJSONArray("dataList");
|
|
|
+ for (int i = 0; i < respDataList.size(); i++) {
|
|
|
+ JSONObject jsonObject = respDataList.getJSONObject(i);
|
|
|
+ String workcode = jsonObject.getString("workcode");
|
|
|
+ if (!StringUtils.isEmpty(workcode)) {
|
|
|
+ Object[] objects = new Object[2];
|
|
|
+ objects[0] = jsonObject.getString("id");
|
|
|
+ objects[1] = workcode;
|
|
|
+ updateParams.add(objects);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return totalSize;
|
|
|
+ } else {
|
|
|
+ throw new BOSException(msg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BOSException("请求超时");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|