【安眼】用户信息同步
This commit is contained in:
+61
-1
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.renkang.anyan.client.AnYanClient;
|
||||
import com.renkang.anyan.model.vo.AnYanUserEmployee;
|
||||
import com.renkang.anyan.model.vo.AnYanUserInfoResult;
|
||||
import com.renkang.anyan.model.vo.AuthResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -16,8 +17,8 @@ import org.jeecg.common.constant.CommonConstant;
|
||||
import org.jeecg.common.constant.FillRuleConstant;
|
||||
import org.jeecg.common.exception.ExceptionAssertsUtil;
|
||||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.DictModel;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.CheckPasswordUtil;
|
||||
import org.jeecg.common.util.FillRuleUtil;
|
||||
import org.jeecg.common.util.RedisUtil;
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
@@ -141,6 +142,8 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
|
||||
loginService.processUserInfo(sysUser);
|
||||
// 用户登录信息处理
|
||||
userInfo(sysUser, result, clientType);
|
||||
//同步用户其他信息
|
||||
updateEmployeeOtherInfo(sysUser.getWorkNo(), sysUser.getId());
|
||||
// 清除登录失败记录
|
||||
redisUtil.del(CommonConstant.LOGIN_FAIL + username);
|
||||
// 缓存登录用户信息
|
||||
@@ -374,4 +377,61 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
|
||||
}
|
||||
return orgId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 更新员工其他信息
|
||||
* @author PengJ
|
||||
* @date 2025/12/02 16:01
|
||||
*/
|
||||
private void updateEmployeeOtherInfo(String workNo, String userId) {
|
||||
taskExecutor.execute(() -> {
|
||||
try {
|
||||
AnYanUserEmployee anYanUserEmployee = anYanClient.updateEmployeeNum(workNo);
|
||||
if (anYanUserEmployee == null) {
|
||||
log.warn("获取员工扩展信息失败,workNo={}", workNo);
|
||||
return;
|
||||
}
|
||||
// 民族
|
||||
String nation = getDictValueByLabel("nation", anYanUserEmployee.getNationalityValueText());
|
||||
// 婚否
|
||||
String mrState = getDictValueByLabel("mr_state", anYanUserEmployee.getMarriageCodeText());
|
||||
// 学历
|
||||
String empEducation = getDictValueByLabel("emp_education", anYanUserEmployee.getEducationCodeText());
|
||||
healthUserEmployeeExService.update(new LambdaUpdateWrapper<HealthUserEmployeeEx>()
|
||||
.eq(HealthUserEmployeeEx::getId, userId)
|
||||
.set(StringUtils.isNotBlank(nation), HealthUserEmployeeEx::getEmpNation, nation)
|
||||
.set(StringUtils.isNotBlank(mrState), HealthUserEmployeeEx::getEmpMarriage, mrState)
|
||||
.set(StringUtils.isNotBlank(empEducation), HealthUserEmployeeEx::getEmpDegree, empEducation)
|
||||
);
|
||||
sysUserService.update(new LambdaUpdateWrapper<SysUser>()
|
||||
.eq(SysUser::getId, userId)
|
||||
.set(StringUtils.isNotBlank(anYanUserEmployee.getBirthday()), SysUser::getBirthday, anYanUserEmployee.getBirthday())
|
||||
);
|
||||
} catch (Exception e) {
|
||||
log.error("更新员工其他信息异常,userId={}, workNo={}", userId, workNo, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 label 从指定字典项中查找对应的 value
|
||||
*
|
||||
* @param dictCode 字典编码
|
||||
* @param label 显示标签
|
||||
* @return 匹配的 value,未找到则返回 ""
|
||||
*/
|
||||
private String getDictValueByLabel(String dictCode, String label) {
|
||||
if (StringUtils.isBlank(label)) {
|
||||
return "";
|
||||
}
|
||||
List<DictModel> items = sysDictService.getDictItems(dictCode);
|
||||
if (items == null || items.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return items.stream()
|
||||
.filter(dict -> label.equals(dict.getLabel()))
|
||||
.findFirst()
|
||||
.map(DictModel::getValue)
|
||||
.orElse("");
|
||||
}
|
||||
}
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package org.jeecg.modules.system.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.renkang.anyan.client.AnYanClient;
|
||||
import com.renkang.anyan.model.vo.AnYanUpdateUserBatchInfo;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jeecg.modules.system.entity.SysUser;
|
||||
import org.jeecg.modules.system.service.ISysUserService;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @description: 安眼用户信息同步任务
|
||||
* @date 2025/12/2 17:10
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AnYanUserInfoJob {
|
||||
|
||||
private final AnYanClient anYanClient;
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
@XxlJob("an-yan-update-vital_info")
|
||||
public void batchUpdateUserInfo() {
|
||||
log.info("------开始执行用户信息同步任务------");
|
||||
boolean flag = true;
|
||||
int pageNum = 1;
|
||||
while (flag) {
|
||||
Page<SysUser> page = new Page<>(pageNum, 1000);
|
||||
Page<SysUser> sysUserPage = sysUserService.page(page, new LambdaQueryWrapper<SysUser>()
|
||||
.select(SysUser::getId, SysUser::getRealname, SysUser::getWorkNo)
|
||||
.isNotNull(SysUser::getWorkNo)
|
||||
.ne(SysUser::getWorkNo, "")
|
||||
);
|
||||
List<SysUser> records = sysUserPage.getRecords();
|
||||
if (records.isEmpty()) {
|
||||
flag = false;
|
||||
continue;
|
||||
}
|
||||
List<String> workNoList = records.stream()
|
||||
.map(SysUser::getWorkNo)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
if (workNoList.isEmpty()) {
|
||||
pageNum++;
|
||||
continue;
|
||||
}
|
||||
List<AnYanUpdateUserBatchInfo> anYanUpdateUserBatchInfos = null;
|
||||
try {
|
||||
anYanUpdateUserBatchInfos = anYanClient.updateUserBatch(workNoList);
|
||||
} catch (Exception e) {
|
||||
log.error("用户信息查询异常:{}", e.getMessage());
|
||||
}
|
||||
if (CollectionUtils.isEmpty(anYanUpdateUserBatchInfos)) {
|
||||
pageNum++;
|
||||
continue;
|
||||
}
|
||||
// 提前批量加载当前系统中的用户信息
|
||||
Map<String, SysUser> userMapByWorkNo = sysUserService.list(new LambdaQueryWrapper<SysUser>()
|
||||
.in(SysUser::getWorkNo, workNoList))
|
||||
.stream()
|
||||
.filter(u -> u.getWorkNo() != null)
|
||||
.collect(Collectors.toMap(SysUser::getWorkNo, u -> u));
|
||||
for (AnYanUpdateUserBatchInfo userInfo : anYanUpdateUserBatchInfos) {
|
||||
try {
|
||||
String employeeNum = userInfo.getEmployeeNum();
|
||||
if (employeeNum == null) {
|
||||
continue;
|
||||
}
|
||||
SysUser existingUser = userMapByWorkNo.get(employeeNum);
|
||||
if (existingUser == null) {
|
||||
continue;
|
||||
}
|
||||
String phone = userInfo.getPhone();
|
||||
String idNo = userInfo.getIdNo();
|
||||
if ((phone != null && !phone.equals(existingUser.getPhone())) ||
|
||||
(idNo != null && !idNo.equals(existingUser.getIdCard()))) {
|
||||
sysUserService.update(new LambdaUpdateWrapper<SysUser>()
|
||||
.eq(SysUser::getWorkNo, existingUser.getWorkNo())
|
||||
.set(SysUser::getPhone, existingUser.getPhone())
|
||||
.set(SysUser::getIdCard, existingUser.getIdCard())
|
||||
.set(SysUser::getUpdateTime, existingUser.getUpdateTime())
|
||||
);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("用户信息同步任务异常:{}", e.getMessage());
|
||||
}
|
||||
}
|
||||
pageNum++;
|
||||
}
|
||||
log.info("======完成用户信息同步任务======");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user