feat(user): 完善大华系统同步功能
- 新增用户时增加头像URL空值检查,避免无效同步 - 更新用户时支持从数据库获取头像URL进行同步 - 同步大华人脸时补充完整的个人信息字段 - 增加身份证号解析计算年龄和性别功能 - 添加民族编码转换异常处理机制 - 优化同步流程的日志记录和错误处理main_koumen
parent
e682dc86e6
commit
961bf60ad6
|
|
@ -206,6 +206,10 @@ public class UserAddExe {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("用户变更记录保存失败(不影响用户主体), userId: {}, error: {}", userE.getId(), e.getMessage(), e);
|
log.error("用户变更记录保存失败(不影响用户主体), userId: {}, error: {}", userE.getId(), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
String userAvatarUrl = userE.getUserAvatarUrl();
|
||||||
|
if (userAvatarUrl == null || userAvatarUrl.trim().isEmpty()) {
|
||||||
|
log.info("新增用户未传人脸URL,跳过大华同步, userId={}", userE.getId());
|
||||||
|
} else {
|
||||||
log.info("========== 新增用户-开始查询大华是否已存在该人员 ==========");
|
log.info("========== 新增用户-开始查询大华是否已存在该人员 ==========");
|
||||||
Integer queryDahuaId = null;
|
Integer queryDahuaId = null;
|
||||||
String queryDahuaCode = null;
|
String queryDahuaCode = null;
|
||||||
|
|
@ -257,7 +261,7 @@ public class UserAddExe {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("大华未找到该人员,开始执行 syncDaHuaPerson 新增大华人员");
|
log.info("大华未找到该人员,开始执行 syncDaHuaPerson 新增大华人员");
|
||||||
DaHuaSyncResult syncResult = syncDaHuaPerson(userE);
|
DaHuaSyncResult syncResult = syncDaHuaPerson(userE, userAvatarUrl, true);
|
||||||
if (syncResult.dahuaId != null) {
|
if (syncResult.dahuaId != null) {
|
||||||
try {
|
try {
|
||||||
UserE updateDahua = new UserE();
|
UserE updateDahua = new UserE();
|
||||||
|
|
@ -275,6 +279,7 @@ public class UserAddExe {
|
||||||
log.info("大华同步未返回dahuaId,跳过写回操作, userId={}, dahuaCode={}", userE.getId(), syncResult.dahuaCode);
|
log.info("大华同步未返回dahuaId,跳过写回操作, userId={}, dahuaCode={}", userE.getId(), syncResult.dahuaCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (BizException e) {
|
} catch (BizException e) {
|
||||||
log.error("新增用户业务异常: {}", e.getMessage(), e);
|
log.error("新增用户业务异常: {}", e.getMessage(), e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|
|
||||||
|
|
@ -113,10 +113,20 @@ public class UserUpdateExe {
|
||||||
log.info("【getInfoById查询结果】dahuaId={}, dahuaCode={}, name={}, userIdCard={}",
|
log.info("【getInfoById查询结果】dahuaId={}, dahuaCode={}, name={}, userIdCard={}",
|
||||||
userDO.getDahuaId(), userDO.getDahuaCode(), userDO.getName(), userDO.getUserIdCard());
|
userDO.getDahuaId(), userDO.getDahuaCode(), userDO.getName(), userDO.getUserIdCard());
|
||||||
|
|
||||||
if (userUpdateCmd.getUserAvatarUrl() != null && !userUpdateCmd.getUserAvatarUrl().trim().isEmpty()) {
|
String requestUserAvatarUrl = userUpdateCmd.getUserAvatarUrl();
|
||||||
|
String userAvatarUrl = requestUserAvatarUrl;
|
||||||
|
if (userAvatarUrl == null || userAvatarUrl.trim().isEmpty()) {
|
||||||
|
userAvatarUrl = userDO.getUserAvatarUrl();
|
||||||
|
}
|
||||||
|
if (userAvatarUrl != null && !userAvatarUrl.trim().isEmpty()) {
|
||||||
|
userUpdateCmd.setUserAvatarUrl(userAvatarUrl);
|
||||||
|
try {
|
||||||
syncDaHuaInfo(userUpdateCmd, userDO, userE);
|
syncDaHuaInfo(userUpdateCmd, userDO, userE);
|
||||||
|
} finally {
|
||||||
|
userUpdateCmd.setUserAvatarUrl(requestUserAvatarUrl);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("userAvatarUrl为空,跳过大华信息同步, userId={}", userDO.getId());
|
log.info("请求参数和数据库中的userAvatarUrl均为空,跳过大华信息同步, userId={}", userDO.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
UserE oldUserE = new UserE();
|
UserE oldUserE = new UserE();
|
||||||
|
|
@ -892,8 +902,42 @@ public class UserUpdateExe {
|
||||||
|
|
||||||
private boolean updateDaHuaUserFace(UserDO userDO, Integer dahuaId, String userAvatarUrl) {
|
private boolean updateDaHuaUserFace(UserDO userDO, Integer dahuaId, String userAvatarUrl) {
|
||||||
Map<String, Object> personMap = new HashMap<>();
|
Map<String, Object> personMap = new HashMap<>();
|
||||||
|
String plainIdCard = decodeUserIdCard(userDO.getUserIdCard());
|
||||||
|
String dahuaCode = getDaHuaCodeForSave(userDO);
|
||||||
|
|
||||||
personMap.put("id", dahuaId);
|
personMap.put("id", dahuaId);
|
||||||
personMap.put("departmentId", userDO.getCorpinfoId());
|
personMap.put("name", userDO.getName());
|
||||||
|
personMap.put("code", dahuaCode);
|
||||||
|
personMap.put("paperType", 111);
|
||||||
|
personMap.put("paperNumber", plainIdCard);
|
||||||
|
personMap.put("phone", userDO.getPhone());
|
||||||
|
personMap.put("departmentId", userDO.getCorpinfoId() != null ? userDO.getCorpinfoId() : 1L);
|
||||||
|
personMap.put("nationName", userDO.getNationName() != null && !userDO.getNationName().trim().isEmpty()
|
||||||
|
? userDO.getNationName() : "汉族");
|
||||||
|
try {
|
||||||
|
personMap.put("nation", userDO.getNation() != null && !userDO.getNation().trim().isEmpty()
|
||||||
|
? Integer.parseInt(userDO.getNation().trim()) : 1);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
log.warn("同步大华人脸时民族编码转换失败,使用默认值1, userId={}, nation={}",
|
||||||
|
userDO.getId(), userDO.getNation());
|
||||||
|
personMap.put("nation", 1);
|
||||||
|
}
|
||||||
|
personMap.put("service", "evo-thirdParty");
|
||||||
|
|
||||||
|
Integer age = null;
|
||||||
|
Integer sex = null;
|
||||||
|
if (plainIdCard != null && plainIdCard.length() == 18) {
|
||||||
|
try {
|
||||||
|
LocalDate birthDate = LocalDate.parse(plainIdCard.substring(6, 14),
|
||||||
|
DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||||
|
age = Period.between(birthDate, LocalDate.now()).getYears();
|
||||||
|
sex = Integer.parseInt(plainIdCard.substring(16, 17)) % 2 == 0 ? 2 : 1;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("同步大华人脸时解析年龄和性别失败, userId={}", userDO.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
personMap.put("age", age);
|
||||||
|
personMap.put("sex", sex);
|
||||||
addDaHuaFace(personMap, userAvatarUrl);
|
addDaHuaFace(personMap, userAvatarUrl);
|
||||||
|
|
||||||
DaHuaPersonSyncCmd daHuaCmd = cn.hutool.core.bean.BeanUtil.toBean(personMap, DaHuaPersonSyncCmd.class);
|
DaHuaPersonSyncCmd daHuaCmd = cn.hutool.core.bean.BeanUtil.toBean(personMap, DaHuaPersonSyncCmd.class);
|
||||||
|
|
@ -904,6 +948,8 @@ public class UserUpdateExe {
|
||||||
(List<DaHuaPersonSyncCmd.PersonBiosignature>) biosignatures;
|
(List<DaHuaPersonSyncCmd.PersonBiosignature>) biosignatures;
|
||||||
daHuaCmd.setPersonBiosignatures(faceList);
|
daHuaCmd.setPersonBiosignatures(faceList);
|
||||||
}
|
}
|
||||||
|
log.info("同步大华人脸更新参数已补全, userId={}, dahuaId={}, name={}, departmentId={}",
|
||||||
|
userDO.getId(), dahuaId, daHuaCmd.getName(), daHuaCmd.getDepartmentId());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SingleResponse<Boolean> updateResponse = zcloudDaHuaFacade.updatePerson(daHuaCmd);
|
SingleResponse<Boolean> updateResponse = zcloudDaHuaFacade.updatePerson(daHuaCmd);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue