|
@@ -14,7 +14,8 @@ 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.custom.synctask.ActionTypeEnum;
|
|
|
-import com.kingdee.eas.custom.synctask.entry.AdminOrg;
|
|
|
+import com.kingdee.eas.custom.synctask.entity.AdminOrg;
|
|
|
+import com.kingdee.eas.hr.ats.AtsUtil;
|
|
|
import com.kingdee.util.StringUtils;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
@@ -35,8 +36,8 @@ public class SynctaskUtils {
|
|
|
|
|
|
public SynctaskUtils() {
|
|
|
try {
|
|
|
- this.propt.load(new FileInputStream("E:\\Kingdee\\eas\\server\\properties\\scy\\synOAConfig.properties"));
|
|
|
- //propt.load(new FileInputStream(System.getProperty("EAS_HOME") + "/server/properties/scy/synOAConfig.properties"));
|
|
|
+ this.propt.load(new FileInputStream("E:\\Kingdee\\eas\\server\\properties\\scy\\syncOAConfig.properties"));
|
|
|
+ //propt.load(new FileInputStream(System.getProperty("EAS_HOME") + "/server/properties/scy/syncOAConfig.properties"));
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -55,149 +56,87 @@ public class SynctaskUtils {
|
|
|
* @throws BOSException
|
|
|
*/
|
|
|
public void _syncOrgUnitToOA(Context ctx, String billds, ActionTypeEnum action) throws BOSException, IOException {
|
|
|
- Set adminOrgIds = new HashSet();
|
|
|
+ logger.error("_syncOrgUnitToOA----------------------start");
|
|
|
+ logger.error("_syncOrgUnitToOA----------------------billds: " + billds);
|
|
|
IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
|
|
|
+ List dataList = new ArrayList();
|
|
|
String actionType = action == null ? "" : action.getValue().toLowerCase();
|
|
|
//当参数billIds不为空值时,增量同步参数中的部门数据到OA
|
|
|
+ FilterInfo filterInfo = null;
|
|
|
if (!StringUtils.isEmpty(billds)) {
|
|
|
- String[] split = billds.split(",");
|
|
|
- for (String adminOrgId : split) {
|
|
|
- adminOrgIds.add(adminOrgId);
|
|
|
- }
|
|
|
- ////当参数action为空时,判断部门状态是否为失效,如果失效就执行删除同步,否则就执行编辑同步
|
|
|
- //if (!StringUtils.isEmpty(billds) && action == null) {
|
|
|
- // logger.error("_syncOrgUnitToOA---------incrementalQuery");
|
|
|
- // AdminOrgUnitCollection adminOrgColl = getAdminOrgColl(ctx, adminOrgIds);
|
|
|
- // saveSynOrgUnit(adminOrgColl, actionType);
|
|
|
- //
|
|
|
- //} else if (!StringUtils.isEmpty(billds) && action != null) {//当参数action不为空时,根据操作类型同步数据
|
|
|
- // logger.error("_syncOrgUnitToOA---------saveQuery");
|
|
|
- // //新增同步
|
|
|
- // if (ActionTypeEnum.ADD.getValue().equals(action.getValue())) {
|
|
|
- // logger.error("_syncOrgUnitToOA---------add");
|
|
|
- // AdminOrgUnitCollection adminOrgColl = getAdminOrgColl(ctx, adminOrgIds);
|
|
|
- // saveSynOrgUnit(adminOrgColl, actionType);
|
|
|
- // }
|
|
|
- // //编辑同步
|
|
|
- // if (ActionTypeEnum.EDIT.getValue().equals(action.getValue())) {
|
|
|
- // logger.error("_syncOrgUnitToOA---------edit");
|
|
|
- // AdminOrgUnitCollection adminOrgColl = getAdminOrgColl(ctx, adminOrgIds);
|
|
|
- // saveSynOrgUnit(adminOrgColl, actionType);
|
|
|
- // }
|
|
|
- //}
|
|
|
- AdminOrgUnitCollection adminOrgColl = getAdminOrgColl(ctx, adminOrgIds);
|
|
|
- saveSynOrgUnit(adminOrgColl, actionType);
|
|
|
- } else {
|
|
|
- if (StringUtils.isEmpty(billds) && action == null) { //当参数billIds为空时,全量同步所有组织数据到OA
|
|
|
- logger.error("_syncOrgUnitToOA---------batchQuery");
|
|
|
- SelectorItemCollection sic = new SelectorItemCollection();
|
|
|
- sic.add("*");
|
|
|
- sic.add("parent.*");
|
|
|
- AdminOrgUnitCollection adminOrgUnitCollection = iAdminOrgUnit.getAdminOrgUnitCollection(EntityViewInfo.getInstance(null, sic, null));
|
|
|
- if (adminOrgUnitCollection.size() > 0) {
|
|
|
- saveSynOrgUnit(adminOrgUnitCollection, actionType);
|
|
|
- }
|
|
|
- }
|
|
|
+ Set<String> adminOrgIds = AtsUtil.toSet(billds);
|
|
|
+ filterInfo = new FilterInfo();
|
|
|
+ filterInfo.getFilterItems().add(new FilterItemInfo("id", adminOrgIds, CompareType.INCLUDE));
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量查询行政组织数据
|
|
|
- *
|
|
|
- * @param ctx
|
|
|
- * @param adminOrgIds
|
|
|
- * @return
|
|
|
- * @throws BOSException
|
|
|
- */
|
|
|
- public AdminOrgUnitCollection getAdminOrgColl(Context ctx, Set adminOrgIds) throws BOSException {
|
|
|
- IAdminOrgUnit iAdminOrgUnit = AdminOrgUnitFactory.getLocalInstance(ctx);
|
|
|
SelectorItemCollection sic = new SelectorItemCollection();
|
|
|
sic.add("*");
|
|
|
- sic.add("parent.*");
|
|
|
- FilterInfo filterInfo = new FilterInfo();
|
|
|
- filterInfo.getFilterItems().add(new FilterItemInfo("id", adminOrgIds, CompareType.INCLUDE));
|
|
|
+ sic.add("parent.number");
|
|
|
EntityViewInfo entityViewInfo = EntityViewInfo.getInstance(filterInfo, sic, null);
|
|
|
- return iAdminOrgUnit.getAdminOrgUnitCollection(entityViewInfo);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增方法
|
|
|
- *
|
|
|
- * @param adminOrgUnitCollection
|
|
|
- */
|
|
|
- public void saveSynOrgUnit(AdminOrgUnitCollection adminOrgUnitCollection, String action) throws IOException {
|
|
|
- ObjectMapper mapper = new ObjectMapper();
|
|
|
- //mapper.writeValueAsString();
|
|
|
- //mapper.readValue(paramData, Map.class)
|
|
|
- logger.error("saveSynOrgUnit----------------------start");
|
|
|
- List saveList = new ArrayList();
|
|
|
+ AdminOrgUnitCollection adminOrgUnitCollection = iAdminOrgUnit.getAdminOrgUnitCollection(entityViewInfo);
|
|
|
for (int i = 0; i < adminOrgUnitCollection.size(); i++) {
|
|
|
AdminOrgUnitInfo adminOrgUnitInfo = adminOrgUnitCollection.get(i);
|
|
|
+ String orgName = adminOrgUnitInfo.getName();
|
|
|
AdminOrg adminOrg = new AdminOrg();
|
|
|
boolean isSealUp = adminOrgUnitInfo.isIsSealUp();
|
|
|
if (isSealUp) {
|
|
|
adminOrg.setAction("delete");
|
|
|
+ adminOrg.setCanceled("0");
|
|
|
} else {
|
|
|
adminOrg.setAction("add");
|
|
|
}
|
|
|
adminOrg.setCode(adminOrgUnitInfo.getNumber());
|
|
|
- adminOrg.setShortname(adminOrgUnitInfo.getName());
|
|
|
- adminOrg.setFullname(adminOrgUnitInfo.getName());
|
|
|
- adminOrg.setParent_code("ITCS");
|
|
|
+ adminOrg.setShortname(orgName);
|
|
|
+ adminOrg.setFullname(orgName);
|
|
|
+ //adminOrg.setParent_code("ITCS");
|
|
|
adminOrg.setOrg_code("0");
|
|
|
- //adminOrg.setParent_code(adminOrgUnitInfo.getParent().getNumber());
|
|
|
- adminOrg.setCanceled(adminOrgUnitInfo.isIsSealUp() == true ? "1" : "0");
|
|
|
+ adminOrg.setParent_code(adminOrgUnitInfo.getParent().getNumber());
|
|
|
//adminOrg.setOrder((String.valueOf(adminOrgUnitInfo.getIndex())));
|
|
|
- saveList.add(adminOrg);
|
|
|
+ dataList.add(adminOrg);
|
|
|
}
|
|
|
- //封装请求参数
|
|
|
- String data = mapper.writeValueAsString(saveList);
|
|
|
- logger.error("saveSynOrgUnit----------------------data" + data);
|
|
|
- String adminOrgApiUrl = "/api/hrm/resful/synDepartment";
|
|
|
- Response response = synScyRequest(data, adminOrgApiUrl);
|
|
|
- logger.error("response----------------------data" + mapper.writeValueAsString(response));
|
|
|
+ //调用执行同步组织到OA
|
|
|
+ executeSyncOrgUnitToOA(dataList);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- //public static void main(String[] args) throws JsonProcessingException {
|
|
|
- // ObjectMapper mapper = new ObjectMapper();
|
|
|
- // List saveList = new ArrayList();
|
|
|
- // for (int i = 0; i < 2; i++) {
|
|
|
- // AdminOrg adminOrg = new AdminOrg();
|
|
|
- // adminOrg.setAction("add");
|
|
|
- // saveList.add(adminOrg);
|
|
|
- // }
|
|
|
- // String s = mapper.writeValueAsString(saveList);
|
|
|
- // System.out.println(s);
|
|
|
- // System.out.println(ActionTypeEnum.EDIT.getValue().toLowerCase());
|
|
|
- //
|
|
|
- //}
|
|
|
-
|
|
|
/**
|
|
|
- * 同步请求方法
|
|
|
+ * 执行同步组织到OA
|
|
|
*
|
|
|
- * @param param
|
|
|
- * @param aipUrl
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
+ * @param dataList
|
|
|
*/
|
|
|
- public Response synScyRequest(String param, String aipUrl) throws IOException {
|
|
|
- String url = this.propt.getProperty("url");
|
|
|
- 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(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();
|
|
|
- return client.newCall(request).execute();
|
|
|
+ public void executeSyncOrgUnitToOA(List dataList) throws IOException, BOSException {
|
|
|
+ if (dataList != null && dataList.size() > 0) {
|
|
|
+ ObjectMapper mapper = new ObjectMapper();
|
|
|
+ //封装请求参数
|
|
|
+ String data = mapper.writeValueAsString(dataList);
|
|
|
+ String params = String.format("token = %s &data = %s", getToken(), data);
|
|
|
+ logger.error("executeSyncOrgUnitToOA----------------------params" + params);
|
|
|
+ //封装请求参数
|
|
|
+ //String syncOrgUnitApiUrl = "/api/hrm/resful/synDepartment";
|
|
|
+ String syncOrgUnitApiUrl = this.propt.getProperty("syncOrgUnitApiUrl");
|
|
|
+ String url = this.propt.getProperty("url");
|
|
|
+ logger.error("executeSyncOrgUnitToOA----------------------syncOrgUnitApiUrl" + syncOrgUnitApiUrl);
|
|
|
+ if (StringUtils.isEmpty(syncOrgUnitApiUrl)) {
|
|
|
+ throw new BOSException("同步组织到OA接口地址不能为空!");
|
|
|
+ }
|
|
|
+ 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(url + syncOrgUnitApiUrl)
|
|
|
+ .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();
|
|
|
+ String respBody = response.body().string();
|
|
|
+ if (response.isSuccessful()) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -211,7 +150,6 @@ public class SynctaskUtils {
|
|
|
String code = key.concat(Long.toString(l));
|
|
|
//String s = DigestUtils.md5Hex(code).toUpperCase();
|
|
|
String s = DigestUtils.md5Hex(code).toUpperCase();
|
|
|
- System.out.println(s);
|
|
|
Map<String, String> map = new HashMap<>();
|
|
|
map.put("key", s);
|
|
|
map.put("ts", Long.toString(l));
|