【安眼】用户信息同步
This commit is contained in:
+7
-6
@@ -34,10 +34,7 @@ import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -342,14 +339,18 @@ public class AnYanClientExecutor implements AnYanClient {
|
||||
|
||||
@Override
|
||||
public List<AnYanUpdateUserBatchInfo> updateUserBatch(List<String> employeeNumList) {
|
||||
AnYanResult<Object> result = RestTemplateUtil.postExchange(AnYanApiEnum.QUERY_EMPLOYEE_CARE_PERSON, buildTokenHeader(), employeeNumList);
|
||||
Map<String,List<String>> map = new HashMap<>(1);
|
||||
map.put("employeeNumList",employeeNumList);
|
||||
AnYanResult<Object> result = RestTemplateUtil.postExchange(AnYanApiEnum.FIND_VITAL_INFO, buildTokenHeader(), map);
|
||||
List<Object> listMaps = (List<Object>) result.getData();
|
||||
return listMaps.stream().map(lMap -> BeanUtil.toBean(lMap, AnYanUpdateUserBatchInfo.class)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnYanUserEmployee updateEmployeeNum(String employeeNum) {
|
||||
AnYanResult<Object> result = RestTemplateUtil.postExchange(AnYanApiEnum.FIND_BY_EMPLOYEENUM, buildTokenHeader(), employeeNum);
|
||||
Map<String,String> map = new HashMap<>(1);
|
||||
map.put("employeeNum",employeeNum);
|
||||
AnYanResult<Object> result = RestTemplateUtil.postExchange(AnYanApiEnum.FIND_BY_EMPLOYEENUM, buildTokenHeader(), map);
|
||||
return BeanUtil.toBean(result.getData(), AnYanUserEmployee.class);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -94,27 +94,27 @@ public enum AnYanApiEnum {
|
||||
/**
|
||||
* 17.一人一案分页列表接口 (用大屏首页重点关爱趋势二级弹窗列表)
|
||||
*/
|
||||
CARE_PERSON_PAGE_LIST("aygc-znhpt-sys/0/api/empPersonFile/findPage", "", HttpMethod.POST),
|
||||
CARE_PERSON_PAGE_LIST("/aygc-znhpt-sys/0/api/empPersonFile/findPage", "", HttpMethod.POST),
|
||||
|
||||
/**
|
||||
* 18.查询关爱联络员信息及急救人员查询接口
|
||||
*/
|
||||
QUERY_EMPLOYEE_CARE_PERSON("aygc-znhpt-sys/0/api/empCareEmp/findPageByIdNo", "", HttpMethod.POST),
|
||||
QUERY_EMPLOYEE_CARE_PERSON("/aygc-znhpt-sys/0/api/empCareEmp/findPageByIdNo", "", HttpMethod.POST),
|
||||
|
||||
/**
|
||||
* 19.批量更新员工关键信息接口
|
||||
*/
|
||||
FIND_VITAL_INFO("aygc-znhpt-sys/0/api/empBasicInfo/find-vital-info","", HttpMethod.POST),
|
||||
FIND_VITAL_INFO("/aygc-znhpt-sys/0/api/empBasicInfo/find-vital-info","", HttpMethod.POST),
|
||||
|
||||
/**
|
||||
* 20.更新单个员工扩展信息
|
||||
*/
|
||||
FIND_BY_EMPLOYEENUM("aygc-znhpt-sys/0/api/empBasicInfo/find-by-employeeNum","", HttpMethod.POST),
|
||||
FIND_BY_EMPLOYEENUM("/aygc-znhpt-sys/0/api/empBasicInfo/find-by-employeeNum","", HttpMethod.POST),
|
||||
|
||||
/**
|
||||
* 22.体检数据
|
||||
*/
|
||||
HEALTH_CHECK_NEW("aygc-znhpt-sys/0/api/empHealthCheckNew/findPage","",HttpMethod.POST);
|
||||
HEALTH_CHECK_NEW("/aygc-znhpt-sys/0/api/empHealthCheckNew/findPage","",HttpMethod.POST);
|
||||
|
||||
/**
|
||||
* 接口路径
|
||||
|
||||
+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