diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java index 465d9df..99198e3 100644 --- a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/SyncOrganizationForOtherAPI.java @@ -2,7 +2,9 @@ package weaver.youhong.ai.pcn.hrorganization.wesmat; import aiyh.utils.Util; import aiyh.utils.zwl.common.ToolUtil; +import com.alibaba.fastjson.JSONObject; import com.weaver.esb.server.cache.ResourceComInfo; +import org.apache.commons.collections.CollectionUtils; import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.SubCompanyComInfo; import weaver.hrm.job.JobTitlesComInfo; @@ -11,6 +13,7 @@ import weaver.integration.logging.Logger; import weaver.integration.logging.LoggerFactory; import weaver.interfaces.hrm.*; import weaver.matrix.MatrixUtil; +import weaver.youhong.ai.pcn.hrorganization.wesmat.mapper.HrmAsyncJobMapper; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Department; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Employee; import weaver.youhong.ai.pcn.hrorganization.wesmat.model.Position; @@ -18,21 +21,30 @@ import weaver.youhong.ai.pcn.hrorganization.wesmat.result.GetOrganizationResult; import weaver.youhong.ai.pcn.hrorganization.wesmat.util.SyncOrganizationUtils; import java.util.*; - +import java.util.stream.Collectors; /** * @author EBU7-dev1-ayh * @create 2021/7/20 0020 15:16 * 同步第三方系统人员组织结构 */ - - public class SyncOrganizationForOtherAPI extends ToolUtil implements HrmSynService { private final Logger log = LoggerFactory.getLogger(SyncOrganizationForOtherAPI.class); private final GetOrganizationResult getOrganizationResult = new GetOrganizationResult(); private final SyncOrganizationUtils organizationUtils = new SyncOrganizationUtils(); String className = "SyncOrganizationForOtherAPI"; private HashMap synResult; + private List unAsyncDepIdList = new ArrayList<>(); + + public void getUnAsyncDepIdList() { + HrmAsyncJobMapper mapper = Util.getMapper(HrmAsyncJobMapper.class); + List unableConfig = mapper.getUnableConfig(); + List> departInfo = mapper.getDepartInfo(); + for (String id : unableConfig) { + getUnAsyncId(unAsyncDepIdList, departInfo, id); + } + writeDebuggerLog(className, "UnAsyncSubIdList => " + JSONObject.toJSONString(unAsyncDepIdList)); + } public SyncOrganizationForOtherAPI() { this.writeDebuggerLog(className, "===========> create Object! <============"); @@ -56,14 +68,20 @@ public class SyncOrganizationForOtherAPI extends ToolUtil implements HrmSynServi @Override public String SynTimingToOADepartment() { this.writeDebuggerLog(className, "===========> synchronous department to OA system starts <============"); + unAsyncDepIdList.clear(); + getUnAsyncDepIdList(); try { List departmentList = getOrganizationResult.getDepartmentList(); Collections.sort(departmentList); List> synResultlist = new ArrayList<>(); - departmentList.forEach(department -> { + for (Department department : departmentList) { + // 如果不启用就不执行 + if (unAsyncDepIdList.contains(String.valueOf(department.getDEPARTMENTID()))) { + continue; + } Map stringStringMap = organizationUtils.asyncDepartment(department); synResultlist.add(buildItemMap("", "", department.getDEPARTMENTNAME(), stringStringMap.get("code"), stringStringMap.get("msg"))); - }); + } this.writeDebuggerLog(className, departmentList.size() + " data pieces are updated this time"); //清除OA中分部的缓存记录 SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); @@ -123,10 +141,15 @@ public class SyncOrganizationForOtherAPI extends ToolUtil implements HrmSynServi List employeeList = getOrganizationResult.getEmployeeList(); List> synResultlist = new ArrayList<>(); Collections.sort(employeeList); - employeeList.forEach(employee -> { + for (Employee employee : employeeList) { + if (unAsyncDepIdList.contains(String.valueOf(employee.getDEPARTMENTID()))) { + continue; + } Map stringStringMap = organizationUtils.asyncEmployee(employee); synResultlist.add(buildItemMap(employee.getUSERCODE(), employee.getUSERCODE(), employee.getPreferred_Name() + "/" + employee.getUSERNAMECN(), stringStringMap.get("code"), stringStringMap.get("msg"))); - }); + } +// employeeList.forEach(employee -> { +// }); this.writeDebuggerLog(className, employeeList.size() + " data pieces are updated this time"); // 清除人员缓存 try { @@ -203,11 +226,31 @@ public class SyncOrganizationForOtherAPI extends ToolUtil implements HrmSynServi private Map buildItemMap(String pkcode, String pk, String memo, String succ, String error) { //保存结果 HashMap itemMap = new HashMap<>(); - itemMap.put(HrmSynDAO.OUTPK, pkcode); - itemMap.put(HrmSynDAO.PK, pk); - itemMap.put(HrmSynDAO.Memo, memo); - itemMap.put(HrmSynDAO.Success, succ); + itemMap.put(weaver.hrm.resource.HrmSynDAO.OUTPK, pkcode); + itemMap.put(weaver.hrm.resource.HrmSynDAO.PK, pk); + itemMap.put(weaver.hrm.resource.HrmSynDAO.Memo, memo); + itemMap.put(weaver.hrm.resource.HrmSynDAO.Success, succ); itemMap.put(HrmSynDAO.ErrorMessage, error); return itemMap; } + + public void getUnAsyncId(List res, List> info, String unAsyncId) { + List id = info.stream() + .filter(item -> + unAsyncId.equals(String.valueOf(item.get("outkey")))) + .map(item -> String.valueOf(item.get("id"))) + .collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(id)) { + List> collect = info.stream().filter(item -> + id.get(0).equals(String.valueOf(item.get("supdepid"))) + ).collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(collect)) { + for (Map map : collect) { + String outKey = String.valueOf(map.get("outkey")); + res.add(outKey); + getUnAsyncId(res, info, outKey); + } + } + } + } } diff --git a/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/mapper/HrmAsyncJobMapper.java b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/mapper/HrmAsyncJobMapper.java new file mode 100644 index 0000000..9c634c5 --- /dev/null +++ b/src/main/java/weaver/youhong/ai/pcn/hrorganization/wesmat/mapper/HrmAsyncJobMapper.java @@ -0,0 +1,20 @@ +package weaver.youhong.ai.pcn.hrorganization.wesmat.mapper; + +import aiyh.utils.annotation.recordset.Select; +import aiyh.utils.annotation.recordset.SqlMapper; + +import java.util.List; +import java.util.Map; + +/** + * @Author xuanran.wang + * @Date 2022/10/10 16:25 + */ +@SqlMapper +public interface HrmAsyncJobMapper { + @Select("select id, supdepid, outkey from hrmdepartment") + List> getDepartInfo(); + + @Select("select frist_company from uf_sub_mapping where enable = 1") + List getUnableConfig(); +}