【安眼】缓存用户部门信息及登录逻辑

This commit is contained in:
2026-02-02 16:08:05 +08:00
parent c9020ee8d3
commit c73c1089ee
3 changed files with 64 additions and 15 deletions
@@ -29,6 +29,7 @@ import org.jeecg.modules.system.bean.UserEmployee;
import org.jeecg.modules.system.entity.HealthUserEmployeeEx;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.manager.DepartCacheManager;
import org.jeecg.modules.system.model.SysLoginModel;
import org.jeecg.modules.system.service.*;
import org.jeecg.util.RSAEncryptUtils;
@@ -58,6 +59,7 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
private final RedisUtil redisUtil;
private final TaskExecutor taskExecutor;
private final LoginService loginService;
private final DepartCacheManager departCacheManager;
private static final String CLIENT_TYPE_PC = "pc";
private static final String CLIENT_TYPE_APP = "app";
@@ -116,14 +118,25 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
return Result.error(anYanAuthResult != null ? anYanAuthResult.getMessage() : "认证服务器无响应");
}
// 授权成功获取用户信息(统一认证的平台接口没有做统一封装,成功和失败均返回一个不同的json字符串, 这里只能判断没有获取到用户信息则认为是失败)
AnYanUserInfoResult anYanUserInfo = anYanClient.getAnYanUserInfo(anYanAuthResult.getAccess_token(), username);
if (anYanUserInfo == null || anYanUserInfo.getEmployeeUnitDTO() == null) {
return Result.error("登录失败,请先联系本单位掌油管理员确认个人机构信息");
AnYanUserInfoResult anYanUserInfo = null;
try {
// 授权成功获取用户信息(统一认证的平台接口没有做统一封装,成功和失败均返回一个不同的json字符串, 这里只能判断没有获取到用户信息则认为是失败)
anYanUserInfo = anYanClient.getAnYanUserInfo(anYanAuthResult.getAccess_token(), username);
if (anYanUserInfo == null || anYanUserInfo.getEmployeeUnitDTO() == null) {
return Result.error("登录失败,请先联系本单位掌油管理员确认个人机构信息");
}
} catch (Exception e) {
log.error("获取用户信息异常: {}", e.getMessage());
}
// 检查并更新用户信息
checkUserAndUpdate(anYanUserInfo, decryptedPassword);
try {
// 检查并更新用户信息
if (anYanUserInfo != null) {
checkUserAndUpdate(anYanUserInfo, decryptedPassword);
}
} catch (Exception e) {
log.error("检查并更新用户信息异常: {}", e.getMessage());
}
// 获取本地用户信息(由于两个平台的密码可能不一致,所以去掉本平台的密码匹配)
SysUser sysUser = sysUserService.getUserByNameOrWorkNo(username, null);
@@ -344,12 +357,19 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
//新增时设置为叶子节点
depart.setIzLeaf(CommonConstant.IS_LEAF);
save = sysDepartService.save(depart);
if (save) {
//缓存
departCacheManager.putCache(depart);
}
} else {
save = sysDepartService.update(new LambdaUpdateWrapper<SysDepart>()
.eq(SysDepart::getId, depart.getId())
.set(SysDepart::getDepartName, orgName)
.set(SysDepart::getUpdateTime, new Date())
);
if (save) {
updateCache(depart);
}
}
if (save) {
SysDepart parentDepart = sysDepartService.getOne(new LambdaQueryWrapper<SysDepart>()
@@ -357,20 +377,26 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
);
// 判断父级组织是否为叶子节点,0不是叶子节点,1是叶子节点,是则更新为非叶子节点
if (parentDepart != null && parentDepart.getIzLeaf().equals(CommonConstant.IS_LEAF)) {
sysDepartService.update(new LambdaUpdateWrapper<SysDepart>()
boolean update = sysDepartService.update(new LambdaUpdateWrapper<SysDepart>()
.eq(SysDepart::getId, parentId)
.set(SysDepart::getIzLeaf, CommonConstant.NOT_LEAF)
);
if (update) {
updateCache(depart);
}
}
long count = sysDepartService.count(new LambdaQueryWrapper<SysDepart>()
.eq(SysDepart::getParentId, depart.getId())
);
// 判断当前节点是否存在子集,不存在则设置为叶子节点
if (count == 0) {
sysDepartService.update(new LambdaUpdateWrapper<SysDepart>()
boolean update = sysDepartService.update(new LambdaUpdateWrapper<SysDepart>()
.eq(SysDepart::getId, depart.getId())
.set(SysDepart::getIzLeaf, CommonConstant.IS_LEAF)
);
if (update) {
updateCache(depart);
}
}
}
// 父id赋值
@@ -381,6 +407,17 @@ public class LoginAnYanServiceImpl implements ILoginAnYanService {
return orgId;
}
/**
* @author: pj
* @description: 更新部门缓存
* @date 2026/2/2 15:46
*/
public void updateCache(SysDepart depart) {
departCacheManager.evictCache(depart);
SysDepart byId = sysDepartService.getById(depart.getId());
departCacheManager.putCache(byId);
}
/**
* @description: 更新员工其他信息
* @author PengJ