登录恢复guava cache同步缓存

This commit is contained in:
gaoqr
2025-07-31 11:54:19 +08:00
parent b102c88ef4
commit fdb119f672
3 changed files with 9 additions and 9 deletions
@@ -1,12 +1,10 @@
package com.cf.imes.framework.common.util.cache;
import com.alibaba.ttl.threadpool.TtlExecutors;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import java.time.Duration;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
/**
@@ -41,7 +41,7 @@ public class OrganFrameworkServiceImpl implements OrganFrameworkService {
/**
* 针对 {@link #validOrgan(Long)} 的缓存
*/
private final LoadingCache<Long, CommonResult<Boolean>> validOrganCache = CacheUtils.buildAsyncReloadingCache(
private final LoadingCache<Long, CommonResult<Boolean>> validOrganCache = CacheUtils.buildCache(
Duration.ofMinutes(1L), // 过期时间 1 分钟
new CacheLoader<>() {
@@ -55,7 +55,7 @@ public class OrganFrameworkServiceImpl implements OrganFrameworkService {
/**
* 针对 {@link #validDept(Long)} 的缓存
*/
private final LoadingCache<Long, CommonResult<Boolean>> validOrganDept = CacheUtils.buildAsyncReloadingCache(
private final LoadingCache<Long, CommonResult<Boolean>> validOrganDept = CacheUtils.buildCache(
Duration.ofMinutes(1L), // 过期时间 1 分钟
new CacheLoader<>() {
@@ -81,6 +81,6 @@ public class OrganFrameworkServiceImpl implements OrganFrameworkService {
@Override
@SneakyThrows
public void validDept(Long id) {
deptApi.validateDept(id).checkError();
validOrganDept.get(id).checkError();
}
}
@@ -12,6 +12,8 @@ import com.cf.imes.framework.common.util.servlet.ServletUtils;
import com.cf.imes.framework.common.util.validation.ValidationUtils;
import com.cf.imes.framework.ip.core.service.IPQueryService;
import com.cf.imes.framework.ip.core.service.dto.IPQueryDataRespDTO;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
import com.cf.imes.framework.organ.core.service.OrganFrameworkService;
import com.cf.imes.module.system.api.logger.dto.LoginLogCreateReqDTO;
import com.cf.imes.module.system.api.sms.SmsCodeApi;
import com.cf.imes.module.system.api.social.dto.SocialUserRespDTO;
@@ -29,7 +31,6 @@ import com.cf.imes.module.system.enums.logger.LoginLogTypeEnum;
import com.cf.imes.module.system.enums.logger.LoginResultEnum;
import com.cf.imes.module.system.enums.oauth2.OAuth2ClientConstants;
import com.cf.imes.module.system.enums.sms.SmsSceneEnum;
import com.cf.imes.module.system.service.dept.DeptService;
import com.cf.imes.module.system.service.logger.LoginLogService;
import com.cf.imes.module.system.service.member.MemberService;
import com.cf.imes.module.system.service.oauth2.OAuth2TokenService;
@@ -85,7 +86,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
@Resource
private OrganService organService;
@Resource
private DeptService deptService;
private OrganFrameworkService organFrameworkService;
@Resource
private SmsCodeService smsCodeService;
@@ -122,9 +123,10 @@ public class AdminAuthServiceImpl implements AdminAuthService {
}
Long organId = user.getOrganId();
// 校验机构有效性
organService.validOrgan(organId);
organFrameworkService.validOrgan(organId);
// 校验部门有效性
deptService.validUserLoginDept(user.getDeptId());
OrganContextHolder.setOrganId(organId);
organFrameworkService.validDept(user.getDeptId());
// 校验密码
if (!userService.isPasswordMatch(password, user.getPassword())) {
createLoginLog(user.getId(), username, organId, logTypeEnum, LoginResultEnum.BAD_CREDENTIALS);