feat(human): 更新人资用户状态同步功能
parent
02f479a7db
commit
8442b0d976
|
|
@ -39,3 +39,5 @@ archives:
|
||||||
humanresources:
|
humanresources:
|
||||||
appKey: A5EF205479D2DFB5E621E159AA8FF34B
|
appKey: A5EF205479D2DFB5E621E159AA8FF34B
|
||||||
appSecret: 53130AAAAC791D5B7AFD6D89C51853510190C903405242C49B83DECBBA0ADA5E
|
appSecret: 53130AAAAC791D5B7AFD6D89C51853510190C903405242C49B83DECBBA0ADA5E
|
||||||
|
commonCorpRoleId: 2008483569812549634
|
||||||
|
stockCorpRoleId: 2008483240551297026
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ openapi:
|
||||||
protocol: HTTP
|
protocol: HTTP
|
||||||
defaultPlatform: true
|
defaultPlatform: true
|
||||||
##ciphertext plaintext
|
##ciphertext plaintext
|
||||||
|
humanresources:
|
||||||
|
commonCorpRoleId: 2008483569812549634
|
||||||
|
stockCorpRoleId: 2008483240551297026
|
||||||
type: plaintext
|
type: plaintext
|
||||||
apiPlatform:
|
apiPlatform:
|
||||||
- name: default
|
- name: default
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.zcloud.human.user.command;
|
package com.zcloud.human.user.command;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import cn.hutool.json.JSONArray;
|
import cn.hutool.json.JSONArray;
|
||||||
import cn.hutool.json.JSONConfig;
|
import cn.hutool.json.JSONConfig;
|
||||||
|
|
@ -315,16 +316,19 @@ public class HumanUserSyncExe {
|
||||||
String employeeName = jsonObject.getStr("employee_name");
|
String employeeName = jsonObject.getStr("employee_name");
|
||||||
String phone = jsonObject.getStr("phone_number");
|
String phone = jsonObject.getStr("phone_number");
|
||||||
String postName = resolvePostName(jsonObject);
|
String postName = resolvePostName(jsonObject);
|
||||||
|
String idCardNumber = jsonObject.getStr("id_card_number");
|
||||||
|
String encodedIdCardNumber = StringUtils.isNotEmpty(idCardNumber) ? Base64.encodeToString(idCardNumber) : null;
|
||||||
|
|
||||||
ZcloudUserAddCmd cmd = new ZcloudUserAddCmd();
|
ZcloudUserAddCmd cmd = new ZcloudUserAddCmd();
|
||||||
cmd.setPhone(phone);
|
cmd.setPhone(phone);
|
||||||
cmd.setName(employeeName);
|
cmd.setName(employeeName);
|
||||||
|
cmd.setUserIdCard(encodedIdCardNumber);
|
||||||
cmd.setCorpinfoId(corpId);
|
cmd.setCorpinfoId(corpId);
|
||||||
cmd.setCorpinfoName(SYSTEM_CORP_NAME);
|
cmd.setCorpinfoName(SYSTEM_CORP_NAME);
|
||||||
cmd.setDepartmentId(deptId);
|
cmd.setDepartmentId(deptId);
|
||||||
cmd.setPostId(postId);
|
cmd.setPostId(postId);
|
||||||
cmd.setPostName(postName);
|
cmd.setPostName(postName);
|
||||||
cmd.setRoleId(getDefaultRoleId());
|
cmd.setRoleId(getCorpRoleId(corpId));
|
||||||
SingleResponse<Long> result = zcloudUserFacade.addHumanUser(cmd);
|
SingleResponse<Long> result = zcloudUserFacade.addHumanUser(cmd);
|
||||||
if (result.getData() != null) {
|
if (result.getData() != null) {
|
||||||
return result.getData();
|
return result.getData();
|
||||||
|
|
@ -336,6 +340,18 @@ public class HumanUserSyncExe {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long getCorpRoleId(Long corpId) {
|
||||||
|
ZcloudCorpInfoCO corpInfo = getCorpInfo(corpId);
|
||||||
|
if (corpInfo == null) {
|
||||||
|
log.warn("未找到企业信息,无法按企业类型匹配角色,corpId={}", corpId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (Integer.valueOf(2).equals(corpInfo.getType())) {
|
||||||
|
return humanResourcesConfig.getStockCorpRoleId();
|
||||||
|
}
|
||||||
|
return humanResourcesConfig.getCommonCorpRoleId();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取默认角色ID。
|
* 获取默认角色ID。
|
||||||
*/
|
*/
|
||||||
|
|
@ -355,17 +371,31 @@ public class HumanUserSyncExe {
|
||||||
* 获取公司ID。
|
* 获取公司ID。
|
||||||
*/
|
*/
|
||||||
private Long getTargetCorpId(String corpName) {
|
private Long getTargetCorpId(String corpName) {
|
||||||
MultiResponse<ZcloudCorpInfoCO> response = zcloudCorpFacade.getCorpList();
|
return getCorpList().stream()
|
||||||
if (response == null || !response.isSuccess() || response.getData() == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return response.getData().stream()
|
|
||||||
.filter(corp -> corpName.equals(corp.getCorpName()))
|
.filter(corp -> corpName.equals(corp.getCorpName()))
|
||||||
.map(ZcloudCorpInfoCO::getId)
|
.map(ZcloudCorpInfoCO::getId)
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ZcloudCorpInfoCO getCorpInfo(Long corpId) {
|
||||||
|
if (corpId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return getCorpList().stream()
|
||||||
|
.filter(corp -> corpId.equals(corp.getId()))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ZcloudCorpInfoCO> getCorpList() {
|
||||||
|
MultiResponse<ZcloudCorpInfoCO> response = zcloudCorpFacade.getCorpList();
|
||||||
|
if (response == null || !response.isSuccess() || response.getData() == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return response.getData();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据企业ID获取该企业下的部门名称与部门ID映射。
|
* 根据企业ID获取该企业下的部门名称与部门ID映射。
|
||||||
*
|
*
|
||||||
|
|
@ -1185,22 +1215,28 @@ public class HumanUserSyncExe {
|
||||||
|
|
||||||
String phoneNumber = StringUtils.isNotEmpty(humanUser.getPhoneNumber()) ? humanUser.getPhoneNumber() : null;
|
String phoneNumber = StringUtils.isNotEmpty(humanUser.getPhoneNumber()) ? humanUser.getPhoneNumber() : null;
|
||||||
String idCardNumber = StringUtils.isNotEmpty(humanUser.getIdCardNumber()) ? Base64.encodeToString(humanUser.getIdCardNumber()) :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);
|
ZcloudUserInfoQry qry = new ZcloudUserInfoQry();
|
||||||
if (infoByUserId == null || !infoByUserId.isSuccess() || infoByUserId.getData() == null) {
|
qry.setUserIdCard(idCardNumber);
|
||||||
log.warn("获取统一用户详情失败,userId={}", humanUser.getUserId());
|
qry.setPhone(phoneNumber);
|
||||||
|
MultiResponse<ZcloudUserCo> response = zcloudUserFacade.listUserByInfo(qry);
|
||||||
|
if (response == null || !response.isSuccess() || response.getData() == null || CollUtil.isEmpty(response.getData())) {
|
||||||
|
log.error("获取统一用户列表失败,userIdCard={},phone={}", idCardNumber, phoneNumber);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
List<ZcloudUserCo> data = response.getData();
|
||||||
|
ZcloudUserCo detail = data.get(0);
|
||||||
|
|
||||||
ZcloudUserCo detail = infoByUserId.getData();
|
|
||||||
String employeeName = StringUtils.isNotEmpty(humanUser.getEmployeeName()) ? humanUser.getEmployeeName() : detail.getName();
|
String employeeName = StringUtils.isNotEmpty(humanUser.getEmployeeName()) ? humanUser.getEmployeeName() : detail.getName();
|
||||||
|
|
||||||
ZcloudUserUpdateCmd cmd = new ZcloudUserUpdateCmd();
|
ZcloudUserUpdateCmd cmd = new ZcloudUserUpdateCmd();
|
||||||
|
|
||||||
cmd.setId(existingUserId);
|
cmd.setId(detail.getId());
|
||||||
cmd.setName(employeeName);
|
cmd.setName(employeeName);
|
||||||
cmd.setPhone(phoneNumber);
|
cmd.setPhone(phoneNumber);
|
||||||
cmd.setUserIdCard(idCardNumber);
|
cmd.setUserIdCard(idCardNumber);
|
||||||
|
cmd.setRoleId(getCorpRoleId(corpId));
|
||||||
|
|
||||||
if (corpId != null) {
|
if (corpId != null) {
|
||||||
cmd.setCorpinfoId(corpId);
|
cmd.setCorpinfoId(corpId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,4 +23,8 @@ public class HumanResourcesConfig {
|
||||||
* 人资接口应用密钥。
|
* 人资接口应用密钥。
|
||||||
*/
|
*/
|
||||||
private String appSecret;
|
private String appSecret;
|
||||||
|
|
||||||
|
private Long commonCorpRoleId;
|
||||||
|
|
||||||
|
private Long stockCorpRoleId;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue