|
@@ -10,7 +10,12 @@ import com.kingdee.bos.metadata.entity.FilterInfo;
|
|
|
import com.kingdee.bos.metadata.entity.FilterItemInfo;
|
|
|
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
|
|
|
import com.kingdee.bos.metadata.query.util.CompareType;
|
|
|
-import com.kingdee.eas.basedata.org.*;
|
|
|
+import com.kingdee.eas.basedata.org.AdminOrgUnitCollection;
|
|
|
+import com.kingdee.eas.basedata.org.AdminOrgUnitFactory;
|
|
|
+import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
|
|
|
+import com.kingdee.eas.basedata.org.IAdminOrgUnit;
|
|
|
+import com.kingdee.eas.basedata.person.PersonCollection;
|
|
|
+import com.kingdee.eas.basedata.person.PersonFactory;
|
|
|
import com.kingdee.eas.common.EASBizException;
|
|
|
import com.kingdee.eas.custom.log.ISyncLog;
|
|
|
import com.kingdee.eas.custom.log.SyncLogFactory;
|
|
@@ -20,9 +25,9 @@ import com.kingdee.eas.custom.log.app.DockingSystemEnum;
|
|
|
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.custom.synctask.entity.PositionEntity;
|
|
|
import com.kingdee.eas.hr.ats.AtsUtil;
|
|
|
import com.kingdee.eas.util.app.DbUtil;
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
import com.kingdee.util.StringUtils;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -32,6 +37,7 @@ import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.sql.SQLException;
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
@@ -221,7 +227,7 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
private String getToken() throws BOSException {
|
|
|
String key = this.propt.getProperty("key");
|
|
|
if (StringUtils.isEmpty(key)) {
|
|
|
- throw new BOSException("获取token key不能为空!");
|
|
|
+ throw new BOSException("获取token key不能为空!");
|
|
|
}
|
|
|
long l = System.currentTimeMillis();//时间戳毫秒数
|
|
|
String code = key.concat(Long.toString(l));
|
|
@@ -233,7 +239,6 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
return JSONObject.toJSONString(map);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 同步职位信息
|
|
|
*
|
|
@@ -244,125 +249,70 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
*/
|
|
|
@Override
|
|
|
protected void _syncPositionToOA(Context ctx, String billds, ActionTypeEnum action) throws BOSException, EASBizException {
|
|
|
- ISyncLog iSyncLog = SyncLogFactory.getLocalInstance(ctx);
|
|
|
- SyncLogInfo syncLogInfo = new SyncLogInfo();
|
|
|
- syncLogInfo.setEntityName(SyncEntityNameEnum.postiton);
|
|
|
- syncLogInfo.setDataDirection(DataDirectionEnum.outflow);
|
|
|
- syncLogInfo.setDockingSystem(DockingSystemEnum.OA);
|
|
|
- try {
|
|
|
- super._syncPositionToOA(ctx, billds, action);
|
|
|
- logger.error("_syncPositionToOA---billds: " + billds);
|
|
|
- String data = getPositionColData(ctx, billds);
|
|
|
- String syncPositionApiUrl = this.propt.getProperty("syncPositionApiUrl");
|
|
|
- synScyRequest(ctx,data, syncPositionApiUrl,syncLogInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- syncLogInfo.setSyncStatus(SyncStatusEnum.ERROR);
|
|
|
- syncLogInfo.setSyncResult(e.getMessage());
|
|
|
- iSyncLog.save(syncLogInfo);
|
|
|
- throw new BOSException(e.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ super._syncPositionToOA(ctx, billds, action);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取岗位信息
|
|
|
+ * 同步员工信息
|
|
|
+ *
|
|
|
* @param ctx
|
|
|
- * @param billIds
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
+ * @param billds
|
|
|
+ * @param action
|
|
|
* @throws BOSException
|
|
|
*/
|
|
|
- protected String getPositionColData(Context ctx,String billIds) throws IOException, BOSException {
|
|
|
- List list = new ArrayList();
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- Set positionIds = new HashSet();
|
|
|
- PositionCollection positionCollection = new PositionCollection();
|
|
|
- IPosition localInstance = PositionFactory.getLocalInstance(ctx);
|
|
|
- if (org.apache.commons.lang.StringUtils.isNotBlank(billIds)){
|
|
|
- String[] split = billIds.split(",");
|
|
|
- for (int i = 0; i < split.length; i++) {
|
|
|
- positionIds.add(split[i]);
|
|
|
- }
|
|
|
- positionCollection = localInstance.getPositionCollection("where id in( " + AtsUtil.convertSetToString(positionIds) + ")");
|
|
|
- }else {
|
|
|
- positionCollection = localInstance.getPositionCollection();
|
|
|
- }
|
|
|
- for (int i = 0; i < positionCollection.size(); i++) {
|
|
|
- PositionEntity positionEntity = new PositionEntity();
|
|
|
- PositionInfo positionInfo = positionCollection.get(i);
|
|
|
- DeletedStatusEnum deletedStatus = positionInfo.getDeletedStatus();
|
|
|
- if ("2".equals(deletedStatus.getValue())){ // 失效
|
|
|
- positionEntity.setAction("delete");
|
|
|
- }else {
|
|
|
- positionEntity.setAction("add");
|
|
|
- }
|
|
|
- positionEntity.setJobtitlecode(positionInfo.getNumber());
|
|
|
- positionEntity.setJobtitlename(positionInfo.getName());
|
|
|
- positionEntity.setJobtitleremark(positionInfo.getName());
|
|
|
- list.add(positionEntity);
|
|
|
- }
|
|
|
- //封装请求参数
|
|
|
- String data = mapper.writeValueAsString(list);
|
|
|
- logger.error("_syncPositionToOA----------------------data" + data);
|
|
|
- return data;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 同步请求方法
|
|
|
- * @param param
|
|
|
- * @param aipUrl
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- public void synScyRequest(Context ctx,String param, String aipUrl, SyncLogInfo syncLogInfo) throws IOException, BOSException, EASBizException {
|
|
|
- OkHttpClient client = new OkHttpClient();
|
|
|
- MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
|
|
- String data = String.format("token = %s &data = %s", getToken(), param);
|
|
|
- //logger.error("synAdminOrgRequest----------------------date" + data);
|
|
|
- RequestBody body = RequestBody.create(mediaType, data);
|
|
|
- Request request = new Request.Builder()
|
|
|
- .url(aipUrl)
|
|
|
- .post(body)
|
|
|
- .addHeader("Content-Type", "application/json")
|
|
|
- .addHeader("Accept", "*/*")
|
|
|
- //.addHeader("Accept-Encoding", "gzip, deflate, br")
|
|
|
- .addHeader("User-Agent", "PostmanRuntime-ApipostRuntime/1.1.0")
|
|
|
- .addHeader("Connection", "keep-alive")
|
|
|
- .build();
|
|
|
- //处理响应结果,写入日志
|
|
|
- Response response = client.newCall(request).execute();
|
|
|
- handlerResponse(ctx, response, syncLogInfo);
|
|
|
+ @Override
|
|
|
+ protected void _syncPersonToOA(Context ctx, String billds, ActionTypeEnum action) throws BOSException, EASBizException {
|
|
|
+ super._syncPersonToOA(ctx, billds, action);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 同步员工信息
|
|
|
+ * 根据id从OA系统同步人员信息
|
|
|
*
|
|
|
* @param ctx
|
|
|
- * @param billds
|
|
|
- * @param action
|
|
|
+ * @param personIds
|
|
|
* @throws BOSException
|
|
|
+ * @throws EASBizException
|
|
|
*/
|
|
|
@Override
|
|
|
- protected void _syncPersonToOA(Context ctx, String billds, ActionTypeEnum action) throws BOSException, EASBizException {
|
|
|
- super._syncPersonToOA(ctx, billds, action);
|
|
|
+ protected void _syncPersonFromOAById(Context ctx, String personIds) throws BOSException, EASBizException {
|
|
|
+ super._syncPersonFromOAById(ctx, personIds);
|
|
|
+ if (StringUtils.isEmpty(personIds)) {
|
|
|
+ this._syncPersonFromOAByNumber(ctx, null);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ String query = "select fnumber from t_bd_person where fid in (" + AtsUtil.getStrFromString(personIds) + ")";
|
|
|
+ IRowSet iRowSet = DbUtil.executeQuery(ctx, query);
|
|
|
+ StringBuilder personNumbers = new StringBuilder();
|
|
|
+ while (iRowSet.next()) {
|
|
|
+ String fnumber = iRowSet.getString("fnumber");
|
|
|
+ personNumbers.append(fnumber).append(",");
|
|
|
+ }
|
|
|
+ personNumbers.deleteCharAt(personNumbers.lastIndexOf(","));
|
|
|
+ this._syncPersonFromOAByNumber(ctx, personNumbers.toString());
|
|
|
+ } catch (SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new BOSException("根据id从OA系统同步人员信息方法报错: " + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 从OA系统同步人员信息
|
|
|
+ * 根据工号从OA系统同步人员信息
|
|
|
+ *
|
|
|
* @param ctx
|
|
|
+ * @param personNumbers
|
|
|
* @throws BOSException
|
|
|
* @throws EASBizException
|
|
|
*/
|
|
|
@Override
|
|
|
- protected void _syncPersonFromOA(Context ctx) throws BOSException, EASBizException {
|
|
|
- super._syncPersonFromOA(ctx);
|
|
|
+ protected void _syncPersonFromOAByNumber(Context ctx, String personNumbers) throws BOSException, EASBizException {
|
|
|
+ super._syncPersonFromOAByNumber(ctx, personNumbers);
|
|
|
ISyncLog iSyncLog = SyncLogFactory.getLocalInstance(ctx);
|
|
|
SyncLogInfo syncLogInfo = new SyncLogInfo();
|
|
|
syncLogInfo.setEntityName(SyncEntityNameEnum.person);
|
|
|
syncLogInfo.setDataDirection(DataDirectionEnum.flowInto);
|
|
|
syncLogInfo.setDockingSystem(DockingSystemEnum.OA);
|
|
|
+ logger.error("_syncPersonFromOAByNumber -> personNumbers" + personNumbers);
|
|
|
try {
|
|
|
String updatePersonSql = "update t_bd_person set cfOAId = ? where fnumber = ?";
|
|
|
int pagesize = 2000;//每页数量
|
|
@@ -372,7 +322,7 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
List<Object[]> updateParams = new ArrayList<Object[]>();
|
|
|
boolean flag = true;
|
|
|
do {
|
|
|
- totalSize = executeSyncPersonFromOA(updateParams, curpage, pagesize);
|
|
|
+ totalSize = executeSyncPersonFromOA(updateParams, curpage, pagesize, personNumbers);
|
|
|
if (flag) {
|
|
|
totalPage = totalSize % pagesize == 0 ? totalSize / pagesize : totalSize / pagesize + 1;
|
|
|
flag = false;
|
|
@@ -395,6 +345,7 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 执行从OA系统同步人员信息
|
|
|
*
|
|
@@ -402,10 +353,15 @@ public class SyncTranForOAFacadeControllerBean extends AbstractSyncTranForOAFaca
|
|
|
* @param curpage
|
|
|
* @return
|
|
|
*/
|
|
|
- public Integer executeSyncPersonFromOA(List<Object[]> updateParams, int curpage, int pagesize)
|
|
|
+ public Integer executeSyncPersonFromOA(List<Object[]> updateParams, int curpage, int pagesize, String personNumbers)
|
|
|
throws IOException, BOSException, EASBizException {
|
|
|
//封装请求参数
|
|
|
- String params = String.format("token = %s ¶ms = {\"pagesize\":%d,\"curpage\":%d}", getToken(), pagesize, curpage);
|
|
|
+ String params = null;
|
|
|
+ if (StringUtils.isEmpty(personNumbers)) {
|
|
|
+ params = String.format("token = %s ¶ms = {\"pagesize\":%d,\"curpage\":%d}", getToken(), pagesize, curpage);
|
|
|
+ } else {
|
|
|
+ params = String.format("token = %s ¶ms = {\"workcode\":\"%s\",\"pagesize\":%d,\"curpage\":%d}", getToken(), personNumbers, pagesize, curpage);
|
|
|
+ }
|
|
|
logger.error("executeSyncPersonFromOA----------------------params" + params);
|
|
|
//封装请求参数
|
|
|
String syncPersonFromApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
|