parent
8b5a9d6f7f
commit
460679ea62
|
|
@ -235,6 +235,10 @@ public class UserAddExe {
|
||||||
}
|
}
|
||||||
|
|
||||||
private DaHuaSyncResult syncDaHuaPerson(UserE userE) {
|
private DaHuaSyncResult syncDaHuaPerson(UserE userE) {
|
||||||
|
return syncDaHuaPerson(userE, userE.getFaceFile(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private DaHuaSyncResult syncDaHuaPerson(UserE userE, Object avatarSource, boolean throwOnFail) {
|
||||||
Map<String, Object> personMap = new HashMap<>();
|
Map<String, Object> personMap = new HashMap<>();
|
||||||
personMap.put("name", userE.getName());
|
personMap.put("name", userE.getName());
|
||||||
String idCard = userE.getUserIdCard();
|
String idCard = userE.getUserIdCard();
|
||||||
|
|
@ -254,16 +258,28 @@ public class UserAddExe {
|
||||||
personMap.put("departmentId", 1L);
|
personMap.put("departmentId", 1L);
|
||||||
personMap.put("departmentType", 2);
|
personMap.put("departmentType", 2);
|
||||||
personMap.put("type", 3);
|
personMap.put("type", 3);
|
||||||
personMap.put("nation", 1);
|
if (userE.getNation() != null && !userE.getNation().trim().isEmpty()) {
|
||||||
personMap.put("nationName", "汉族");
|
try {
|
||||||
|
personMap.put("nation", Integer.valueOf(userE.getNation().trim()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("用户民族编码转Integer失败,用默认值1,nation={}", userE.getNation());
|
||||||
|
personMap.put("nation", 1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
personMap.put("nation", 1);
|
||||||
|
}
|
||||||
|
personMap.put("nationName", (userE.getNationName() != null && !userE.getNationName().trim().isEmpty()) ? userE.getNationName().trim() : "汉族");
|
||||||
personMap.put("service", "evo-thirdParty");
|
personMap.put("service", "evo-thirdParty");
|
||||||
|
|
||||||
Object faceFile = userE.getFaceFile();
|
Object faceFile = avatarSource != null ? avatarSource : userE.getFaceFile();
|
||||||
|
|
||||||
java.util.function.Function<Object, String> extractThumbFromSingle = (singleObj) -> {
|
java.util.function.Function<Object, String> extractThumbFromSingle = (singleObj) -> {
|
||||||
if (singleObj == null) {
|
if (singleObj == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (singleObj instanceof String) {
|
||||||
|
return singleObj.toString();
|
||||||
|
}
|
||||||
if (singleObj instanceof Map) {
|
if (singleObj instanceof Map) {
|
||||||
Map<String, Object> faceFileMap = (Map<String, Object>) singleObj;
|
Map<String, Object> faceFileMap = (Map<String, Object>) singleObj;
|
||||||
Object thumbUrlObj = faceFileMap.get("thumbUrl");
|
Object thumbUrlObj = faceFileMap.get("thumbUrl");
|
||||||
|
|
@ -447,10 +463,18 @@ public class UserAddExe {
|
||||||
if (plainIdCard != null && plainIdCard.length() >= 14) {
|
if (plainIdCard != null && plainIdCard.length() >= 14) {
|
||||||
maskedIdCard = plainIdCard.substring(0, 6) + "********" + plainIdCard.substring(plainIdCard.length() - 4);
|
maskedIdCard = plainIdCard.substring(0, 6) + "********" + plainIdCard.substring(plainIdCard.length() - 4);
|
||||||
}
|
}
|
||||||
|
result.setDahuaCode(plainIdCard);
|
||||||
|
userE.setDahuaCode(plainIdCard);
|
||||||
if (success == null || !success) {
|
if (success == null || !success) {
|
||||||
String errCode = (String) syncResult.getOrDefault("errCode", "");
|
String errCode = (String) syncResult.getOrDefault("errCode", "");
|
||||||
String errMessage = (String) syncResult.getOrDefault("errMessage", "大华人员同步失败");
|
String errMessage = (String) syncResult.getOrDefault("errMessage", "大华人员同步失败");
|
||||||
throw new BizException("同步大华平台失败:" + errMessage);
|
if (throwOnFail) {
|
||||||
|
throw new BizException("同步大华平台失败:" + errMessage);
|
||||||
|
} else {
|
||||||
|
log.warn("同步大华平台未成功(重复信息或其他原因,不影响本地数据保存): errCode={}, errMessage={}, userId={}, idCardMask={}",
|
||||||
|
errCode, errMessage, userE.getId(), maskedIdCard);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Object data = syncResult.get("data");
|
Object data = syncResult.get("data");
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
|
|
@ -850,12 +874,56 @@ public class UserAddExe {
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public boolean executeXgf(UserXgfAddCmd cmd) {
|
public boolean executeXgf(UserXgfAddCmd cmd) {
|
||||||
|
log.info("开始新增相关方用户,name: {}, corpinfoId: {}, phone: {}", cmd.getName(), cmd.getCorpinfoId(), cmd.getPhone());
|
||||||
|
try {
|
||||||
|
ServletRequestAttributes attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||||
|
if (attrs != null) {
|
||||||
|
HttpServletRequest req = attrs.getRequest();
|
||||||
|
String orgidHeader = req.getHeader("orgid");
|
||||||
|
if (orgidHeader != null && cmd.getCorpinfoId() == null) {
|
||||||
|
try {
|
||||||
|
cmd.setCorpinfoId(Long.parseLong(orgidHeader.trim()));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("orgid 转 Long 失败: {}", orgidHeader);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("获取请求头异常: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
Long tenantId = null;
|
||||||
SSOUser ssoUser = AuthContext.getCurrentUser();
|
SSOUser ssoUser = AuthContext.getCurrentUser();
|
||||||
Long tenantId = ssoUser.getTenantId();
|
if (ssoUser != null) {
|
||||||
|
tenantId = ssoUser.getTenantId();
|
||||||
|
}
|
||||||
UserE userE = new UserE();
|
UserE userE = new UserE();
|
||||||
BeanUtils.copyProperties(cmd, userE);
|
BeanUtils.copyProperties(cmd, userE);
|
||||||
|
// tenantId 优先级:cmd 传值 -> AuthContext 上下文 -> ssoUser
|
||||||
|
if (!ObjectUtils.isEmpty(userE.getTenantId())) {
|
||||||
|
tenantId = userE.getTenantId();
|
||||||
|
} else if (!ObjectUtils.isEmpty(userE.getCorpinfoId())) {
|
||||||
|
tenantId = userE.getCorpinfoId();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Long ctxTenantId = AuthContext.getTenantId();
|
||||||
|
if (ctxTenantId != null) {
|
||||||
|
tenantId = ctxTenantId;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("从 AuthContext 获取 tenantId 失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tenantId == null && ObjectUtils.isEmpty(userE.getCorpinfoId())) {
|
||||||
|
throw new BizException("无法获取租户信息,请登录后重试或在请求中指定 corpinfoId");
|
||||||
|
}
|
||||||
|
if (ObjectUtils.isEmpty(userE.getCorpinfoId())) {
|
||||||
|
userE.setCorpinfoId(tenantId);
|
||||||
|
}
|
||||||
userE.initAdd(tenantId, userE);
|
userE.initAdd(tenantId, userE);
|
||||||
CorpInfoDO corpInfoDO = corpInfoRepository.getById(userE.getCorpinfoId());
|
CorpInfoDO corpInfoDO = corpInfoRepository.getById(userE.getCorpinfoId());
|
||||||
|
if (corpInfoDO == null) {
|
||||||
|
throw new BizException("企业信息不存在,corpinfoId=" + userE.getCorpinfoId());
|
||||||
|
}
|
||||||
userE.setUserType(CorpTypeEnum.getUserTypeByCode(corpInfoDO.getType()));
|
userE.setUserType(CorpTypeEnum.getUserTypeByCode(corpInfoDO.getType()));
|
||||||
Long roleId = userRepository.getDefaultRoleId();
|
Long roleId = userRepository.getDefaultRoleId();
|
||||||
if (roleId == null) {
|
if (roleId == null) {
|
||||||
|
|
@ -928,6 +996,54 @@ public class UserAddExe {
|
||||||
userExpandInfoRepository.updateByPhone(userE.getPhone(),userE.getFlowFlag());
|
userExpandInfoRepository.updateByPhone(userE.getPhone(),userE.getFlowFlag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== 相关方用户同步大华(统一用 /person/sync;重复信息返回false直接跳过不影响本地)==========
|
||||||
|
Long xgfUserId = addFlag ? userE.getId() : userDOUpdate.getId();
|
||||||
|
if (xgfUserId == null) {
|
||||||
|
log.warn("相关方用户保存后未获取到userId,跳过大华同步及dahua信息写回, addFlag={}", addFlag);
|
||||||
|
} else {
|
||||||
|
Object xgfAvatarSource = cmd.getUserImg();
|
||||||
|
if (xgfAvatarSource == null) {
|
||||||
|
xgfAvatarSource = cmd.getUserAvatarUrl();
|
||||||
|
}
|
||||||
|
DaHuaSyncResult xgfSyncResult = null;
|
||||||
|
try {
|
||||||
|
xgfSyncResult = syncDaHuaPerson(userE, xgfAvatarSource, false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("相关方用户同步大华异常(不影响本地保存,继续执行写回身份证号为dahuaCode), userId={}, addFlag={}, error={}",
|
||||||
|
xgfUserId, addFlag, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
// 无论大华同步成功/失败/返回false/抛异常,都尝试写回dahuaId/dahuaCode:
|
||||||
|
// dahuaId = 大华返回的id(成功时才有,失败/异常/重复时为null)
|
||||||
|
// dahuaCode = 前端传的身份证号(经过Base64解码的明文,syncDaHuaPerson里即使失败也已经set到result了)
|
||||||
|
Integer xgfDahuaId = xgfSyncResult != null ? xgfSyncResult.dahuaId : null;
|
||||||
|
String xgfDahuaCode = xgfSyncResult != null ? xgfSyncResult.dahuaCode : null;
|
||||||
|
// 如果xgfSyncResult异常或dahuaCode为空兜底:直接把userE.getUserIdCard()做一次Base64解码写入dahuaCode,保证100%写回
|
||||||
|
if ((xgfDahuaCode == null || xgfDahuaCode.trim().isEmpty()) && userE.getUserIdCard() != null && !userE.getUserIdCard().trim().isEmpty()) {
|
||||||
|
String idCardRaw = userE.getUserIdCard().trim();
|
||||||
|
try {
|
||||||
|
xgfDahuaCode = new String(java.util.Base64.getDecoder().decode(idCardRaw), java.nio.charset.StandardCharsets.UTF_8);
|
||||||
|
} catch (Exception e) {
|
||||||
|
xgfDahuaCode = idCardRaw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (xgfDahuaId != null || (xgfDahuaCode != null && !xgfDahuaCode.trim().isEmpty())) {
|
||||||
|
try {
|
||||||
|
UserE updateDahua = new UserE();
|
||||||
|
updateDahua.setId(xgfUserId);
|
||||||
|
updateDahua.setDahuaId(xgfDahuaId);
|
||||||
|
updateDahua.setDahuaCode(xgfDahuaCode);
|
||||||
|
userRepository.updateDahuaInfo(updateDahua.getId(), updateDahua.getDahuaId(), updateDahua.getDahuaCode());
|
||||||
|
log.info("相关方用户写回dahuaId/dahuaCode成功, userId={}, addFlag={}, dahuaId={}, dahuaCode={}",
|
||||||
|
xgfUserId, addFlag, xgfDahuaId, xgfDahuaCode);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("相关方用户写回dahuaId/dahuaCode失败, userId={}, addFlag={}, dahuaId={}, dahuaCode={}",
|
||||||
|
xgfUserId, addFlag, xgfDahuaId, xgfDahuaCode, e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("相关方用户既无dahuaId也无dahuaCode可写回,跳过update, userId={}, addFlag={}", xgfUserId, addFlag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
//页面相关保存user_corp
|
//页面相关保存user_corp
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue