feat(human): 更新人资用户状态同步功能
parent
440982b858
commit
02f479a7db
|
|
@ -11,7 +11,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 人资人员数据同步定时任务
|
||||
* 人资用户状态同步定时任务
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Component
|
||||
|
|
@ -22,19 +22,22 @@ public class HumanCorpUserChangeSyncJob implements Job {
|
|||
|
||||
@Override
|
||||
// @JobRegister(cron = "0 30 0 * * ?", jobDesc = "人资部门数据同步任务开始",triggerStatus = 1)
|
||||
@JobRegister(cron = "0 30 0 1 1 ?", jobDesc = "人资用户变更数据同步任务开始",triggerStatus = 1)
|
||||
@JobRegister(cron = "0 30 0 1 1 ?", jobDesc = "人资用户状态同步任务开始", triggerStatus = 1)
|
||||
@XxlJob("com.zcloud.human.user.plan.HumanCorpUserChangeSyncJob")
|
||||
public ReturnT<String> execute(String param) {
|
||||
XxlJobHelper.log("============人资人员变更数据同步任务开始==========");
|
||||
|
||||
XxlJobHelper.log("============人资用户状态同步任务开始,param={}==========", param);
|
||||
log.info("============人资用户状态同步任务开始,param={}==========", param);
|
||||
try {
|
||||
String result = humanUserSyncExe.CorpUserChangeSync(param);
|
||||
XxlJobHelper.log("同步结果:{}", result);
|
||||
XxlJobHelper.log("============人资人员变更数据同步任务结束==========");
|
||||
XxlJobHelper.log("人资用户状态同步结果:{}", result);
|
||||
log.info("人资用户状态同步结果:{}", result);
|
||||
XxlJobHelper.log("============人资用户状态同步任务结束==========");
|
||||
log.info("============人资用户状态同步任务结束==========");
|
||||
return new ReturnT<>(ReturnT.SUCCESS_CODE, result);
|
||||
} catch (Exception e) {
|
||||
XxlJobHelper.log("人资人员变更数据同步任务执行失败:{}", e.getMessage());
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, "人资人员变更数据同步任务执行失败:" + e.getMessage());
|
||||
XxlJobHelper.log("人资用户状态同步任务执行失败:{}", e.getMessage());
|
||||
log.error("人资用户状态同步任务执行失败,param={}", param, e);
|
||||
return new ReturnT<>(ReturnT.FAIL_CODE, "人资用户状态同步任务执行失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,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;
|
||||
|
|
@ -43,9 +46,17 @@ import org.apache.dubbo.config.annotation.DubboReference;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* 人资人员数据同步执行器
|
||||
* <p>
|
||||
|
|
@ -104,6 +115,9 @@ public class HumanUserSyncExe {
|
|||
* 人资人员变更接口标识。
|
||||
*/
|
||||
private static final String HUMAN_RESOURCE_USER_CHANGE_API_ID = "1057031732824408064";
|
||||
private static final int HUMAN_RESOURCE_USER_CHANGE_PAGE_SIZE = 100;
|
||||
private static final String HUMAN_RESOURCE_USER_CHANGE_TEST_FILE_PATH = "D:\\work\\GBS\\统一用户管理\\对接人资系统\\员工变更.json";
|
||||
private static final DateTimeFormatter CHANGE_SYNC_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
|
||||
@DubboReference
|
||||
|
|
@ -119,6 +133,8 @@ public class HumanUserSyncExe {
|
|||
private ZcloudCorpFacade zcloudCorpFacade;
|
||||
@DubboReference
|
||||
private ZcloudDepartmentFacade zcloudDepartmentFacade;
|
||||
@DubboReference
|
||||
private ZcloudPostFacade zcloudPostFacade;
|
||||
|
||||
private final HumanUserGateway humanUserGateway;
|
||||
private final HumanUserRepository humanUserRepository;
|
||||
|
|
@ -291,9 +307,14 @@ public class HumanUserSyncExe {
|
|||
* @return 新增人员在统一用户管理中的ID,如果失败返回null
|
||||
*/
|
||||
private Long addThirdPartyUser(JSONObject jsonObject, Long corpId, Long deptId) {
|
||||
return addThirdPartyUser(jsonObject, corpId, deptId, null);
|
||||
}
|
||||
|
||||
private Long addThirdPartyUser(JSONObject jsonObject, Long corpId, Long deptId, Long postId) {
|
||||
try {
|
||||
String employeeName = jsonObject.getStr("employee_name");
|
||||
String phone = jsonObject.getStr("phone_number");
|
||||
String postName = resolvePostName(jsonObject);
|
||||
|
||||
ZcloudUserAddCmd cmd = new ZcloudUserAddCmd();
|
||||
cmd.setPhone(phone);
|
||||
|
|
@ -301,9 +322,9 @@ public class HumanUserSyncExe {
|
|||
cmd.setCorpinfoId(corpId);
|
||||
cmd.setCorpinfoName(SYSTEM_CORP_NAME);
|
||||
cmd.setDepartmentId(deptId);
|
||||
cmd.setPostId(postId);
|
||||
cmd.setPostName(postName);
|
||||
cmd.setRoleId(getDefaultRoleId());
|
||||
// TODO 暂留岗位
|
||||
// cmd.setPostId(postId);
|
||||
SingleResponse<Long> result = zcloudUserFacade.addHumanUser(cmd);
|
||||
if (result.getData() != null) {
|
||||
return result.getData();
|
||||
|
|
@ -374,6 +395,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。
|
||||
*
|
||||
|
|
@ -763,35 +829,56 @@ public class HumanUserSyncExe {
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String CorpUserChangeSync(String param) {
|
||||
log.info("开始同步人资人员变更数据");
|
||||
JSONArray sourceRows = pullAllCorpUserChangeRows(param);
|
||||
UserChangeSyncRange syncRange = resolveUserChangeSyncRange(param);
|
||||
log.info("开始同步人资人员变更数据,param={},startDate={},endDate={},testFlag={}",
|
||||
param, syncRange.getStartDateText(), syncRange.getEndDateText(), syncRange.isTestFlag());
|
||||
JSONArray sourceRows = pullAllCorpUserChangeRows(param, syncRange);
|
||||
if (sourceRows.isEmpty()) {
|
||||
log.info("未获取到人资人员变更数据");
|
||||
log.info("未获取到人资人员变更数据,startDate={},endDate={}",
|
||||
syncRange.getStartDateText(), syncRange.getEndDateText());
|
||||
return "同步完成:未获取到人资人员变更数据";
|
||||
}
|
||||
log.info("拉取到 {} 条人员变更数据", sourceRows.size());
|
||||
log.info("拉取到 {} 条人员变更数据,startDate={},endDate={}",
|
||||
sourceRows.size(), syncRange.getStartDateText(), syncRange.getEndDateText());
|
||||
|
||||
int[] syncResult = saveCorpUserChangeRows(sourceRows);
|
||||
String message = String.format(
|
||||
"同步完成:拉取 %d 条人员变更数据,新增变更记录 %d 条,更新本地人员 %d 条,更新统一用户 %d 条,跳过 %d 条,失败 %d 条",
|
||||
"同步完成:时间范围[%s,%s],拉取 %d 条人员变更数据,新增变更记录 %d 条,处理本地人员 %d 条,处理统一用户 %d 条,跳过 %d 条,失败 %d 条",
|
||||
syncRange.getStartDateText(), syncRange.getEndDateText(),
|
||||
sourceRows.size(), syncResult[0], syncResult[1], syncResult[2], syncResult[3], syncResult[4]);
|
||||
log.info(message);
|
||||
log.info("结束同步人资人员变更数据");
|
||||
return message;
|
||||
}
|
||||
|
||||
private JSONArray pullAllCorpUserChangeRows(String param) {
|
||||
if (useTestCorpUserData(param)) {
|
||||
log.info("人资人员变更同步使用测试JSON数据,param={}", param);
|
||||
private JSONArray pullAllCorpUserChangeRows(String param, UserChangeSyncRange syncRange) {
|
||||
if (syncRange.isTestFlag() || useTestCorpUserData(param)) {
|
||||
log.info("人资人员变更同步使用测试JSON数据,param={},filePath={}", param, HUMAN_RESOURCE_USER_CHANGE_TEST_FILE_PATH);
|
||||
return getTestCorpUserChangeRows();
|
||||
}
|
||||
return pullCorpUserChangeRows();
|
||||
|
||||
JSONArray allRows = new JSONArray();
|
||||
int pageNum = 1;
|
||||
while (true) {
|
||||
JSONArray pageRows = pullCorpUserChangeRows(syncRange, pageNum);
|
||||
log.info("人资人员变更接口分页拉取完成,pageNum={},pageSize={},pageCount={}",
|
||||
pageNum, HUMAN_RESOURCE_USER_CHANGE_PAGE_SIZE, pageRows.size());
|
||||
if (pageRows.isEmpty()) {
|
||||
break;
|
||||
}
|
||||
allRows.addAll(pageRows);
|
||||
if (pageRows.size() < HUMAN_RESOURCE_USER_CHANGE_PAGE_SIZE) {
|
||||
break;
|
||||
}
|
||||
pageNum++;
|
||||
}
|
||||
return allRows;
|
||||
}
|
||||
|
||||
private JSONArray pullCorpUserChangeRows() {
|
||||
SignUtil signUtil = buildUserChangeSignUtil();
|
||||
private JSONArray pullCorpUserChangeRows(UserChangeSyncRange syncRange, int pageNum) {
|
||||
SignUtil signUtil = buildUserChangeSignUtil(syncRange, pageNum);
|
||||
JSONObject requestBody = buildCorpUserChangeRequest(signUtil);
|
||||
log.info("开始调用人资人员变更接口");
|
||||
log.info("开始调用人资人员变更接口,pageNum={},requestBody={}", pageNum, requestBody);
|
||||
String body = HttpRequest.post(HUMAN_RESOURCE_USER_CHANGE_URL)
|
||||
.timeout(30000)
|
||||
.header("Content-Type", "application/json")
|
||||
|
|
@ -805,15 +892,22 @@ public class HumanUserSyncExe {
|
|||
return extractRemoteRows(body, "人资人员变更接口");
|
||||
}
|
||||
|
||||
private SignUtil buildUserChangeSignUtil() {
|
||||
private SignUtil buildUserChangeSignUtil(UserChangeSyncRange syncRange, int pageNum) {
|
||||
SignUtil signUtil = new SignUtil();
|
||||
signUtil.setAppKey(getAppKey());
|
||||
signUtil.setAppSecret(getAppSecret());
|
||||
signUtil.setEnvType("online");
|
||||
signUtil.setPageNum(pageNum);
|
||||
signUtil.setPageSize(HUMAN_RESOURCE_USER_CHANGE_PAGE_SIZE);
|
||||
signUtil.setNonce(RandomStringUtils.randomAlphanumeric(5));
|
||||
signUtil.setTimeStamp(System.currentTimeMillis());
|
||||
signUtil.setParamMap(new HashMap<>());
|
||||
signUtil.setOrderByList(new ArrayList<>());
|
||||
Map<String, String> paramMap = new HashMap<>();
|
||||
paramMap.put("start_date", syncRange.getStartDateText());
|
||||
paramMap.put("end_date", syncRange.getEndDateText());
|
||||
signUtil.setParamMap(paramMap);
|
||||
List<String> orderByList = new ArrayList<>();
|
||||
orderByList.add("id_card_number,DESC");
|
||||
signUtil.setOrderByList(orderByList);
|
||||
signUtil.buildSignatureParam();
|
||||
return signUtil;
|
||||
}
|
||||
|
|
@ -827,8 +921,11 @@ public class HumanUserSyncExe {
|
|||
.set("signature", signature)
|
||||
.set("signatureParam", null)
|
||||
.set("apiid", HUMAN_RESOURCE_USER_CHANGE_API_ID)
|
||||
.set("pageNum", signUtil.getPageNum())
|
||||
.set("pageSize", signUtil.getPageSize())
|
||||
.set("paramMap", signUtil.getParamMap())
|
||||
.set("orderByList", signUtil.getOrderByList())
|
||||
.set("hasTotal", "Y")
|
||||
.set("envType", signUtil.getEnvType())
|
||||
.set("empNo", "10262589")
|
||||
.set("invokeLogId", null)
|
||||
|
|
@ -838,6 +935,67 @@ public class HumanUserSyncExe {
|
|||
.set("accessIp", null);
|
||||
}
|
||||
|
||||
private UserChangeSyncRange resolveUserChangeSyncRange(String param) {
|
||||
LocalDate defaultDate = LocalDate.now().minusDays(1);
|
||||
LocalDate startDate = defaultDate;
|
||||
LocalDate endDate = defaultDate;
|
||||
boolean testFlag = false;
|
||||
if (StringUtils.isEmpty(param)) {
|
||||
return new UserChangeSyncRange(startDate, endDate, false);
|
||||
}
|
||||
|
||||
String trimmedParam = param.trim();
|
||||
if (HUMAN_RESOURCE_USER_TEST_FLAG.equalsIgnoreCase(trimmedParam)) {
|
||||
return new UserChangeSyncRange(startDate, endDate, true);
|
||||
}
|
||||
|
||||
try {
|
||||
if (trimmedParam.startsWith("{")) {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(trimmedParam);
|
||||
startDate = parseSyncDate(jsonObject.getStr("start_date"), startDate);
|
||||
endDate = parseSyncDate(jsonObject.getStr("end_date"), endDate);
|
||||
String testValue = jsonObject.getStr("test");
|
||||
if (StringUtils.isEmpty(testValue)) {
|
||||
testValue = jsonObject.getStr("mode");
|
||||
}
|
||||
testFlag = HUMAN_RESOURCE_USER_TEST_FLAG.equalsIgnoreCase(testValue);
|
||||
} else {
|
||||
String[] values = trimmedParam.split(",");
|
||||
if (values.length >= 1) {
|
||||
startDate = parseSyncDate(values[0], startDate);
|
||||
}
|
||||
if (values.length >= 2) {
|
||||
endDate = parseSyncDate(values[1], endDate);
|
||||
} else {
|
||||
endDate = startDate;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("解析用户状态同步时间范围失败,param={},改用默认昨天", param, e);
|
||||
startDate = defaultDate;
|
||||
endDate = defaultDate;
|
||||
}
|
||||
|
||||
if (startDate.isAfter(endDate)) {
|
||||
LocalDate temp = startDate;
|
||||
startDate = endDate;
|
||||
endDate = temp;
|
||||
}
|
||||
return new UserChangeSyncRange(startDate, endDate, testFlag);
|
||||
}
|
||||
|
||||
private LocalDate parseSyncDate(String value, LocalDate defaultDate) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return defaultDate;
|
||||
}
|
||||
try {
|
||||
return LocalDate.parse(value.trim(), CHANGE_SYNC_DATE_FORMATTER);
|
||||
} catch (DateTimeParseException e) {
|
||||
log.warn("同步日期格式非法,value={},按默认值处理={}", value, defaultDate);
|
||||
return defaultDate;
|
||||
}
|
||||
}
|
||||
|
||||
private JSONArray extractRemoteRows(String body, String scene) {
|
||||
JSONObject returnJson = JSONUtil.parseObj(body, jsonConfig);
|
||||
String code = returnJson.getStr("code");
|
||||
|
|
@ -885,31 +1043,87 @@ public class HumanUserSyncExe {
|
|||
int userUpdateCount = 0;
|
||||
int skipCount = 0;
|
||||
int failCount = 0;
|
||||
log.info("开始循环对比人员变更数据,{}",JSONUtil.toJsonStr(sourceRows));
|
||||
log.info("开始处理用户状态同步数据,count={}", sourceRows.size());
|
||||
for (Object item : sourceRows) {
|
||||
try {
|
||||
JSONObject jsonObject = JSONUtil.parseObj(item);
|
||||
String employeeName = jsonObject.getStr("employee_name");
|
||||
String idCardNumber = jsonObject.getStr("id_card_number");
|
||||
String corporationName = jsonObject.getStr("corporation_name");
|
||||
if (StringUtils.isEmpty(employeeName) || StringUtils.isEmpty(idCardNumber)) {
|
||||
log.info("跳过无效人员变更数据:姓名或身份证号为空,原始数据:{}", jsonObject);
|
||||
String phoneNumber = jsonObject.getStr("phone_number");
|
||||
if (!isValidMainlandIdCard(idCardNumber)) {
|
||||
log.info("跳过无效身份证数据,身份证号={},原始数据={}", idCardNumber, jsonObject);
|
||||
skipCount++;
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.isEmpty(employeeName) || StringUtils.isEmpty(idCardNumber)|| StringUtils.isEmpty(phoneNumber)) {
|
||||
log.info("跳过无效人员变更数据:姓名或身份证号或手机号为空,原始数据={}", jsonObject);
|
||||
skipCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
HumanUserE existingHumanUser = humanUserGateway.getByIdCardNumber(idCardNumber);
|
||||
if (existingHumanUser == null) {
|
||||
log.info("跳过人员变更数据:本地未找到身份证号为 {} 的人员,原始数据:{}", idCardNumber, jsonObject);
|
||||
Long corpId = getTargetCorpId(corporationName);
|
||||
if (corpId == null) {
|
||||
log.info("未找到目标企业:{},跳过同步", corporationName);
|
||||
skipCount++;
|
||||
continue;
|
||||
}
|
||||
Long corpId = getTargetCorpId(corporationName);
|
||||
log.info("目标企业ID:{}", corpId);
|
||||
Map<String, Long> deptNameIdMap = corpId == null ? Collections.emptyMap() : getTargetCorpDeptNameIdMap(corpId);
|
||||
String deptName = jsonObject.getStr("dept_name");
|
||||
Long deptId = StringUtils.isEmpty(deptName) || deptNameIdMap == null ? null : deptNameIdMap.get(deptName);
|
||||
if (deptId == null) {
|
||||
log.info("未找到目标部门:{},跳过同步", deptName);
|
||||
skipCount++;
|
||||
continue;
|
||||
}
|
||||
String postName = resolvePostName(jsonObject);
|
||||
Map<String, Long> postNameIdMap = getDeptPostNameIdMap(corpId, deptId);
|
||||
Long postId = postNameIdMap.get(normalizeLookupName(postName));
|
||||
if (corpId == null || deptId == null || postId == null) {
|
||||
log.info("跳过用户状态同步:企业、部门或岗位未匹配,身份证号={},corpId={},deptId={},postName={},postId={},原始数据={}",
|
||||
idCardNumber, corpId, deptId, postName, 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(linkedUserId);
|
||||
humanUserGateway.add(existingHumanUser);
|
||||
localUpdateCount++;
|
||||
log.info("用户状态同步新增本地human_user成功,身份证号={},userId={}", idCardNumber, linkedUserId);
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("开始处理本地用户信息,{}",JSONUtil.toJsonStr(existingHumanUser));
|
||||
HumanUserRecordE record = buildHumanUserRecord(jsonObject, existingHumanUser.getUserId());
|
||||
humanUserRecordGateway.add(record);
|
||||
recordCount++;
|
||||
|
|
@ -918,18 +1132,16 @@ public class HumanUserSyncExe {
|
|||
humanUserGateway.update(existingHumanUser);
|
||||
localUpdateCount++;
|
||||
|
||||
String deptName = jsonObject.getStr("dept_name");
|
||||
Long deptId = StringUtils.isEmpty(deptName) || deptNameIdMap == null ? null : deptNameIdMap.get(deptName);
|
||||
// if (existingHumanUser.getUserId() != null) {
|
||||
log.info("开始统一用户更新,userId={}",existingHumanUser.getUserId() );
|
||||
if (updateBasicInfodUser(existingHumanUser, deptId,corpId)) {
|
||||
if (existingHumanUser.getUserId() != null) {
|
||||
log.info("开始统一用户更新,userId={}", existingHumanUser.getUserId());
|
||||
if (updateBasicInfodUser(existingHumanUser, deptId, corpId, postId, postName)) {
|
||||
userUpdateCount++;
|
||||
} else {
|
||||
log.warn("统一用户更新未成功,userId={},身份证号={}", existingHumanUser.getUserId(), idCardNumber);
|
||||
}
|
||||
// }
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理人员变更数据失败,原始数据:{}", item, e);
|
||||
log.error("处理人员变更数据失败,原始数据={}", item, e);
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
|
@ -937,12 +1149,43 @@ public class HumanUserSyncExe {
|
|||
return new int[]{recordCount, localUpdateCount, userUpdateCount, skipCount, failCount};
|
||||
}
|
||||
|
||||
private boolean updateBasicInfodUser(HumanUserE humanUser, Long deptId, Long corpId) {
|
||||
private String resolvePostName(JSONObject jsonObject) {
|
||||
String jobName = normalizeLookupName(jsonObject.getStr("job_name"));
|
||||
if (StringUtils.isNotEmpty(jobName)) {
|
||||
return jobName;
|
||||
}
|
||||
return normalizeLookupName(jsonObject.getStr("position_name"));
|
||||
}
|
||||
|
||||
private String normalizeLookupName(String value) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
return null;
|
||||
}
|
||||
return value.replace("\t", "").trim();
|
||||
}
|
||||
|
||||
private boolean isValidMainlandIdCard(String idCardNumber) {
|
||||
if (StringUtils.isEmpty(idCardNumber)) {
|
||||
return false;
|
||||
}
|
||||
String trimmedValue = idCardNumber.trim();
|
||||
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 deptId, Long corpId, Long postId, String postName) {
|
||||
|
||||
// SingleResponse<UserDetailCO> detailResponse = userFacade.getDetail(humanUser.getUserId());
|
||||
String phoneNumber = StringUtils.isNotEmpty(humanUser.getPhoneNumber()) ? humanUser.getPhoneNumber() : null;
|
||||
String idCardNumber = StringUtils.isNotEmpty(humanUser.getIdCardNumber()) ? Base64.encodeToString(humanUser.getIdCardNumber()) :null;
|
||||
Long existingUserId = isUserExists(idCardNumber,phoneNumber);
|
||||
Long existingUserId = isUserExists(idCardNumber,phoneNumber);
|
||||
SingleResponse<ZcloudUserCo> infoByUserId = zcloudUserFacade.getInfoByUserId(existingUserId);
|
||||
if (infoByUserId == null || !infoByUserId.isSuccess() || infoByUserId.getData() == null) {
|
||||
log.warn("获取统一用户详情失败,userId={}", humanUser.getUserId());
|
||||
|
|
@ -952,7 +1195,6 @@ public class HumanUserSyncExe {
|
|||
ZcloudUserCo detail = infoByUserId.getData();
|
||||
String employeeName = StringUtils.isNotEmpty(humanUser.getEmployeeName()) ? humanUser.getEmployeeName() : detail.getName();
|
||||
|
||||
String postName = StringUtils.isNotEmpty(humanUser.getPositionName()) ? humanUser.getPositionName() : humanUser.getJobName();
|
||||
ZcloudUserUpdateCmd cmd = new ZcloudUserUpdateCmd();
|
||||
|
||||
cmd.setId(existingUserId);
|
||||
|
|
@ -965,6 +1207,9 @@ public class HumanUserSyncExe {
|
|||
if (deptId != null) {
|
||||
cmd.setDepartmentId(deptId);
|
||||
}
|
||||
if (postId != null) {
|
||||
cmd.setPostId(postId);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(postName)) {
|
||||
cmd.setPostName(postName);
|
||||
}
|
||||
|
|
@ -1036,53 +1281,49 @@ public class HumanUserSyncExe {
|
|||
}
|
||||
|
||||
private JSONArray getTestCorpUserChangeRows() {
|
||||
try {
|
||||
Path path = Paths.get(HUMAN_RESOURCE_USER_CHANGE_TEST_FILE_PATH);
|
||||
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
|
||||
if (StringUtils.isEmpty(content)) {
|
||||
log.warn("用户状态同步测试文件为空,filePath={}", HUMAN_RESOURCE_USER_CHANGE_TEST_FILE_PATH);
|
||||
return new JSONArray();
|
||||
}
|
||||
String trimmedContent = content.trim();
|
||||
if (trimmedContent.startsWith("[")) {
|
||||
return JSONUtil.parseArray(trimmedContent);
|
||||
}
|
||||
return extractRemoteRows(trimmedContent, "用户状态同步测试文件");
|
||||
} catch (Exception e) {
|
||||
log.error("读取用户状态同步测试文件失败,filePath={}", HUMAN_RESOURCE_USER_CHANGE_TEST_FILE_PATH, e);
|
||||
HumanUserDO byId = humanUserRepository.getById(1);
|
||||
|
||||
HumanUserDO byId = humanUserRepository.getById(1);
|
||||
String remark = byId.getRemarks();
|
||||
return JSONUtil.parseArray(remark);
|
||||
}
|
||||
}
|
||||
|
||||
String remark = byId.getRemarks();
|
||||
return JSONUtil.parseArray(remark);
|
||||
private static final class UserChangeSyncRange {
|
||||
private final LocalDate startDate;
|
||||
private final LocalDate endDate;
|
||||
private final boolean testFlag;
|
||||
|
||||
private UserChangeSyncRange(LocalDate startDate, LocalDate endDate, boolean testFlag) {
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
this.testFlag = testFlag;
|
||||
}
|
||||
|
||||
/* JSONArray array = new JSONArray();
|
||||
private String getStartDateText() {
|
||||
return CHANGE_SYNC_DATE_FORMATTER.format(startDate);
|
||||
}
|
||||
|
||||
JSONObject first = new JSONObject();
|
||||
first.set("dept_code", "132588b1871341acb51c5638a735dbe7");
|
||||
first.set("corporation_code", "28f4eed3300b431c958bea4d93e49434");
|
||||
first.set("entry_time", "2011-07-05 00:00:00");
|
||||
first.set("employee_gender", "MALE");
|
||||
first.set("position_name", "开发岗位");
|
||||
first.set("dept_name", "开发部门");
|
||||
first.set("employee_images_code", "a101bf6d844b43b9b85aeba419ff0458");
|
||||
first.set("employee_name", "TEST_USER_B");
|
||||
first.set("corporation_name", "zhk分公司");
|
||||
first.set("employee_images", "");
|
||||
first.set("employee_age", 45);
|
||||
first.set("job_name", "TEST_JOB_A");
|
||||
first.set("phone_number", "18700000009");
|
||||
first.set("employee_status", "在职");
|
||||
first.set("job_level", "M9");
|
||||
first.set("id_card_number", "654201197901154618");
|
||||
array.add(first);
|
||||
*//*
|
||||
JSONObject second = new JSONObject();
|
||||
second.set("dept_code", "3cb898c954b947e3acfb8161d23103f7");
|
||||
second.set("corporation_code", "5a472a9d94f84832bc83b93133832f55");
|
||||
second.set("entry_time", "2024-11-01 00:00:00");
|
||||
second.set("employee_gender", "FEMALE");
|
||||
second.set("position_name", "TEST_POSITION_B");
|
||||
second.set("dept_name", "TEST_DEPT_B");
|
||||
second.set("employee_images_code", "de475a7601a9450fb4a1109f70d1f3be");
|
||||
second.set("employee_name", "TEST_USER_B");
|
||||
second.set("corporation_name", "TEST_CORP_B");
|
||||
second.set("employee_images", "");
|
||||
second.set("employee_age", 54);
|
||||
second.set("job_name", "TEST_JOB_B");
|
||||
second.set("phone_number", "16603390000");
|
||||
second.set("employee_status", "劳务派遣");
|
||||
second.set("id_card_number", "E64056788");
|
||||
array.add(second);*//*
|
||||
private String getEndDateText() {
|
||||
return CHANGE_SYNC_DATE_FORMATTER.format(endDate);
|
||||
}
|
||||
|
||||
return array;*/
|
||||
private boolean isTestFlag() {
|
||||
return testFlag;
|
||||
}
|
||||
}
|
||||
|
||||
private String getAppKey() {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
package com.zcloud.human.user.gatewayimpl;
|
||||
|
||||
import com.zcloud.gbscommon.utils.Tools;
|
||||
import com.zcloud.human.user.domain.gateway.HumanUserGateway;
|
||||
import com.zcloud.human.user.domain.model.HumanUserE;
|
||||
import com.zcloud.human.user.persistence.dataobject.HumanUserDO;
|
||||
import com.zcloud.human.user.persistence.repository.HumanUserRepository;
|
||||
import jodd.util.StringUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -45,6 +47,9 @@ public class HumanUserGatewayImpl implements HumanUserGateway {
|
|||
|
||||
@Override
|
||||
public boolean add(HumanUserE humanUserE) {
|
||||
if(StringUtil.isEmpty(humanUserE.getHumanUserId())){
|
||||
humanUserE.setHumanUserId(Tools.get32UUID());
|
||||
}
|
||||
HumanUserDO humanUserDO = convertToDO(humanUserE);
|
||||
humanUserRepository.save(humanUserDO);
|
||||
humanUserE.setId(humanUserDO.getId());
|
||||
|
|
|
|||
Loading…
Reference in New Issue