合并xuanran组织架构同步

main
youHong.ai 2022-11-23 22:27:10 +08:00
parent ad3eed6d87
commit 4abb771154
2 changed files with 74 additions and 11 deletions

View File

@ -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<String, Object> synResult;
private List<String> unAsyncDepIdList = new ArrayList<>();
public void getUnAsyncDepIdList() {
HrmAsyncJobMapper mapper = Util.getMapper(HrmAsyncJobMapper.class);
List<String> unableConfig = mapper.getUnableConfig();
List<Map<String, Object>> 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<Department> departmentList = getOrganizationResult.getDepartmentList();
Collections.sort(departmentList);
List<Map<String, Object>> synResultlist = new ArrayList<>();
departmentList.forEach(department -> {
for (Department department : departmentList) {
// 如果不启用就不执行
if (unAsyncDepIdList.contains(String.valueOf(department.getDEPARTMENTID()))) {
continue;
}
Map<String, String> 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<Employee> employeeList = getOrganizationResult.getEmployeeList();
List<Map<String, Object>> synResultlist = new ArrayList<>();
Collections.sort(employeeList);
employeeList.forEach(employee -> {
for (Employee employee : employeeList) {
if (unAsyncDepIdList.contains(String.valueOf(employee.getDEPARTMENTID()))) {
continue;
}
Map<String, String> 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<String, Object> buildItemMap(String pkcode, String pk, String memo, String succ, String error) {
//保存结果
HashMap<String, Object> 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<String> res, List<Map<String, Object>> info, String unAsyncId) {
List<String> 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<Map<String, Object>> collect = info.stream().filter(item ->
id.get(0).equals(String.valueOf(item.get("supdepid")))
).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)) {
for (Map<String, Object> map : collect) {
String outKey = String.valueOf(map.get("outkey"));
res.add(outKey);
getUnAsyncId(res, info, outKey);
}
}
}
}
}

View File

@ -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<Map<String, Object>> getDepartInfo();
@Select("select frist_company from uf_sub_mapping where enable = 1")
List<String> getUnableConfig();
}