|
|
|
|
@ -22,6 +22,9 @@ import com.zcloud.gbscommon.zcloudcorp.response.ZcloudCorpInfoCO;
|
|
|
|
|
import com.zcloud.gbscommon.zclouddepartment.face.ZcloudDepartmentFacade;
|
|
|
|
|
import com.zcloud.gbscommon.zclouddepartment.request.ZcloudDepartmentPageQry;
|
|
|
|
|
import com.zcloud.gbscommon.zclouddepartment.response.ZcloudDepartmentInfoCo;
|
|
|
|
|
import com.zcloud.gbscommon.zcloudpost.facade.ZcloudPostFacade;
|
|
|
|
|
import com.zcloud.gbscommon.zcloudpost.request.ZcloudPostQry;
|
|
|
|
|
import com.zcloud.gbscommon.zcloudpost.response.ZcloudPostCO;
|
|
|
|
|
import com.zcloud.gbscommon.zclouduser.facade.ZcloudUserFacade;
|
|
|
|
|
import com.zcloud.gbscommon.zclouduser.request.ZcloudUserAddCmd;
|
|
|
|
|
import com.zcloud.gbscommon.zclouduser.request.ZcloudUserInfoQry;
|
|
|
|
|
@ -133,6 +136,9 @@ public class HumanUserSyncExe {
|
|
|
|
|
private ZcloudCorpFacade zcloudCorpFacade;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private ZcloudDepartmentFacade zcloudDepartmentFacade;
|
|
|
|
|
@DubboReference
|
|
|
|
|
private ZcloudPostFacade zcloudPostFacade;
|
|
|
|
|
|
|
|
|
|
private final HumanUserGateway humanUserGateway;
|
|
|
|
|
private final HumanUserRepository humanUserRepository;
|
|
|
|
|
|
|
|
|
|
@ -435,6 +441,51 @@ public class HumanUserSyncExe {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String, Long> getDeptPostNameIdMap(Long corpId, Long deptId) {
|
|
|
|
|
if (corpId == null || deptId == null) {
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
ZcloudPostQry qry = new ZcloudPostQry();
|
|
|
|
|
qry.setCorpinfoId(corpId);
|
|
|
|
|
qry.setDepartmentId(deptId);
|
|
|
|
|
MultiResponse<ZcloudPostCO> response = zcloudPostFacade.listByPostIds(qry);
|
|
|
|
|
if (response == null || !response.isSuccess() || response.getData() == null) {
|
|
|
|
|
log.warn("获取岗位列表失败,corpId={},deptId={}", corpId, deptId);
|
|
|
|
|
return Collections.emptyMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Long> result = new HashMap<>();
|
|
|
|
|
for (ZcloudPostCO post : response.getData()) {
|
|
|
|
|
if (post == null || !corpId.equals(post.getCorpinfoId())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (!isPostBelongsToDept(post, deptId)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
String postName = normalizeLookupName(post.getPostName());
|
|
|
|
|
if (StringUtils.isEmpty(postName) || post.getId() == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
result.put(postName, post.getId());
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isPostBelongsToDept(ZcloudPostCO post, Long deptId) {
|
|
|
|
|
if (post == null || deptId == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (deptId.equals(post.getDepartmentId())) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (post.getDepartmentList() == null) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return post.getDepartmentList().stream()
|
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
|
.anyMatch(item -> deptId.equals(item.getDepartmentId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据部门ID和人员姓名判断人员是否已经存在,并返回人员ID。
|
|
|
|
|
*
|
|
|
|
|
@ -1074,25 +1125,61 @@ public class HumanUserSyncExe {
|
|
|
|
|
skipCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String syncDeptName = StringUtils.isNotEmpty(realDeptName) ? realDeptName : deptName;
|
|
|
|
|
String syncPostName = StringUtils.isNotEmpty(realPostName) ? realPostName : postName;
|
|
|
|
|
Map<String, Long> deptNameIdMap = corpId == null ? Collections.emptyMap() : getTargetCorpDeptNameIdMap(corpId);
|
|
|
|
|
Long deptId = StringUtils.isEmpty(realDeptName) || deptNameIdMap == null ? null : deptNameIdMap.get(realDeptName);
|
|
|
|
|
if (deptId == null) {
|
|
|
|
|
log.info("未找到目标部门,跳过同步,三方企业名={},三方部门名={},映射部门名={},corpId={},原始数据={}",
|
|
|
|
|
corporationName, deptName, realDeptName, corpId, jsonObject);
|
|
|
|
|
skipCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Map<String, Long> postNameIdMap = getDeptPostNameIdMap(corpId, deptId);
|
|
|
|
|
Long postId = postNameIdMap.get(realPostName);
|
|
|
|
|
if (corpId == null || deptId == null || postId == null) {
|
|
|
|
|
log.info("跳过用户状态同步:企业、部门或岗位未匹配,身份证号={},三方企业名={},三方部门名={},三方岗位名={},映射企业名={},映射部门名={},映射岗位名={},corpId={},deptId={},postId={},原始数据={}",
|
|
|
|
|
idCardNumber, corporationName, deptName, postName, realCorpName, realDeptName, realPostName, corpId, deptId, postId, jsonObject);
|
|
|
|
|
skipCount++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
HumanUserE existingHumanUser = humanUserGateway.getByIdCardNumber(idCardNumber);
|
|
|
|
|
|
|
|
|
|
if (existingHumanUser == null) {
|
|
|
|
|
Long linkedUserId = resolveZcloudUserId(idCardNumber, phoneNumber);
|
|
|
|
|
if (linkedUserId == null && canCreateZcloudUser(corpId, deptId, postId)) {
|
|
|
|
|
linkedUserId = addThirdPartyUser(jsonObject, corpId, deptId, postId);
|
|
|
|
|
if (linkedUserId != null) {
|
|
|
|
|
userUpdateCount++;
|
|
|
|
|
log.info("用户状态同步新增统一用户成功,身份证号={},userId={}", idCardNumber, linkedUserId);
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("用户状态同步新增统一用户失败,身份证号={},原始数据={}", idCardNumber, jsonObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
existingHumanUser = buildHumanUser(jsonObject);
|
|
|
|
|
existingHumanUser.setUserId(null);
|
|
|
|
|
existingHumanUser.setUserId(linkedUserId);
|
|
|
|
|
humanUserGateway.add(existingHumanUser);
|
|
|
|
|
localUpdateCount++;
|
|
|
|
|
log.info("用户状态同步新增本地human_user成功,身份证号={},corpId={},部门名={},岗位名={}",
|
|
|
|
|
idCardNumber, corpId, syncDeptName, syncPostName);
|
|
|
|
|
log.info("用户状态同步新增本地human_user成功,身份证号={},userId={}", idCardNumber, linkedUserId);
|
|
|
|
|
|
|
|
|
|
HumanUserRecordE record = buildHumanUserRecord(jsonObject, null);
|
|
|
|
|
if (linkedUserId != null) {
|
|
|
|
|
HumanUserRecordE record = buildHumanUserRecord(jsonObject, linkedUserId);
|
|
|
|
|
humanUserRecordGateway.add(record);
|
|
|
|
|
recordCount++;
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (existingHumanUser.getUserId() == null) {
|
|
|
|
|
Long linkedUserId = resolveZcloudUserId(idCardNumber, phoneNumber);
|
|
|
|
|
if (linkedUserId == null) {
|
|
|
|
|
linkedUserId = addThirdPartyUser(jsonObject, corpId, deptId, postId);
|
|
|
|
|
}
|
|
|
|
|
existingHumanUser.setUserId(linkedUserId);
|
|
|
|
|
if (linkedUserId != null) {
|
|
|
|
|
userUpdateCount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HumanUserRecordE record = buildHumanUserRecord(jsonObject, existingHumanUser.getUserId());
|
|
|
|
|
humanUserRecordGateway.add(record);
|
|
|
|
|
recordCount++;
|
|
|
|
|
@ -1101,21 +1188,13 @@ public class HumanUserSyncExe {
|
|
|
|
|
humanUserGateway.update(existingHumanUser);
|
|
|
|
|
localUpdateCount++;
|
|
|
|
|
|
|
|
|
|
Long resolvedUserId = resolveZcloudUserId(idCardNumber, phoneNumber);
|
|
|
|
|
if (resolvedUserId != null) {
|
|
|
|
|
existingHumanUser.setUserId(resolvedUserId);
|
|
|
|
|
humanUserGateway.update(existingHumanUser);
|
|
|
|
|
log.info("开始统一用户更新,userId={},corpId={},部门名={},岗位名={}",
|
|
|
|
|
resolvedUserId, corpId, syncDeptName, syncPostName);
|
|
|
|
|
if (updateBasicInfodUser(existingHumanUser, corpId,syncDeptName, syncPostName)) {
|
|
|
|
|
if (existingHumanUser.getUserId() != null) {
|
|
|
|
|
log.info("开始统一用户更新,userId={}", existingHumanUser.getUserId());
|
|
|
|
|
if (updateBasicInfodUser(existingHumanUser, deptId, corpId, postId, postName)) {
|
|
|
|
|
userUpdateCount++;
|
|
|
|
|
} else {
|
|
|
|
|
log.warn("统一用户更新未成功,userId={},身份证号={},corpId={},部门名={},岗位名={}",
|
|
|
|
|
resolvedUserId, idCardNumber, corpId, syncDeptName, syncPostName);
|
|
|
|
|
log.warn("统一用户更新未成功,userId={},身份证号={}", existingHumanUser.getUserId(), idCardNumber);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("未反查到统一用户,跳过统一用户更新,身份证号={},手机号={},corpId={},部门名={},岗位名={}",
|
|
|
|
|
idCardNumber, phoneNumber, corpId, syncDeptName, syncPostName);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("处理人员变更数据失败,原始数据={}", item, e);
|
|
|
|
|
@ -1149,12 +1228,16 @@ public class HumanUserSyncExe {
|
|
|
|
|
return trimmedValue.matches("^\\d{17}[0-9Xx]$");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean canCreateZcloudUser(Long corpId, Long deptId, Long postId) {
|
|
|
|
|
return corpId != null && deptId != null && postId != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Long resolveZcloudUserId(String idCardNumber, String phoneNumber) {
|
|
|
|
|
String encodedIdCardNumber = StringUtils.isNotEmpty(idCardNumber) ? Base64.encodeToString(idCardNumber) : null;
|
|
|
|
|
return isUserExists(encodedIdCardNumber, phoneNumber);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean updateBasicInfodUser(HumanUserE humanUser, Long corpId, String syncDeptName,String postName) {
|
|
|
|
|
private boolean updateBasicInfodUser(HumanUserE humanUser, Long deptId, Long corpId, Long postId, String postName) {
|
|
|
|
|
|
|
|
|
|
String phoneNumber = StringUtils.isNotEmpty(humanUser.getPhoneNumber()) ? humanUser.getPhoneNumber() : null;
|
|
|
|
|
String idCardNumber = StringUtils.isNotEmpty(humanUser.getIdCardNumber()) ? Base64.encodeToString(humanUser.getIdCardNumber()) :null;
|
|
|
|
|
@ -1183,11 +1266,15 @@ public class HumanUserSyncExe {
|
|
|
|
|
if (corpId != null) {
|
|
|
|
|
cmd.setCorpinfoId(corpId);
|
|
|
|
|
}
|
|
|
|
|
if (deptId != null) {
|
|
|
|
|
cmd.setDepartmentId(deptId);
|
|
|
|
|
}
|
|
|
|
|
if (postId != null) {
|
|
|
|
|
cmd.setPostId(postId);
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isNotEmpty(postName)) {
|
|
|
|
|
cmd.setPostName(postName);
|
|
|
|
|
}
|
|
|
|
|
// cmd.setDepartmentId(humanUser.getde);
|
|
|
|
|
cmd.setDepartmentName(syncDeptName);
|
|
|
|
|
cmd.setRzFlag(1);
|
|
|
|
|
UserEmploymentFlagEnum byDesc = UserEmploymentFlagEnum.getByDesc(humanUser.getEmployeeStatus());
|
|
|
|
|
cmd.setEmploymentFlag(byDesc==null?null:byDesc.getCode());
|
|
|
|
|
|