diff --git a/mesnac-auth/src/main/java/com/mesnac/auth/service/SysLoginService.java b/mesnac-auth/src/main/java/com/mesnac/auth/service/SysLoginService.java index 8037e9b..54ea754 100644 --- a/mesnac-auth/src/main/java/com/mesnac/auth/service/SysLoginService.java +++ b/mesnac-auth/src/main/java/com/mesnac/auth/service/SysLoginService.java @@ -18,9 +18,11 @@ import com.mesnac.system.api.RemoteUserService; import com.mesnac.system.api.domain.SysUser; import com.mesnac.system.api.model.LoginUser; +import java.util.concurrent.TimeUnit; + /** * 登录校验方法 - * + * * @author ruoyi */ @Component @@ -83,7 +85,7 @@ public class SysLoginService { throw new ServiceException(userResult.getMsg()); } - + LoginUser userInfo = userResult.getData(); SysUser user = userResult.getData().getSysUser(); if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) @@ -96,6 +98,10 @@ public class SysLoginService recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); throw new ServiceException("对不起,您的账号:" + username + " 已停用"); } + + redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, userInfo.getPoolName(), + CacheConstants.REFRESH_TIME, TimeUnit.MINUTES); + passwordService.validate(user, password); recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); return userInfo; diff --git a/mesnac-common/mesnac-common-core/src/main/java/com/mesnac/common/core/constant/CacheConstants.java b/mesnac-common/mesnac-common-core/src/main/java/com/mesnac/common/core/constant/CacheConstants.java index e91cb99..7f28d70 100644 --- a/mesnac-common/mesnac-common-core/src/main/java/com/mesnac/common/core/constant/CacheConstants.java +++ b/mesnac-common/mesnac-common-core/src/main/java/com/mesnac/common/core/constant/CacheConstants.java @@ -2,7 +2,7 @@ package com.mesnac.common.core.constant; /** * 缓存常量信息 - * + * * @author ruoyi */ public class CacheConstants @@ -56,4 +56,6 @@ public class CacheConstants * 登录IP黑名单 cache key */ public static final String SYS_LOGIN_BLACKIPLIST = SYS_CONFIG_KEY + "sys.login.blackIPList"; + + public static final String USER_POOL_NAME_CURRENT = "user_pool_name_current:"; } diff --git a/mesnac-modules/mesnac-system/src/main/java/com/mesnac/system/controller/SysUserController.java b/mesnac-modules/mesnac-system/src/main/java/com/mesnac/system/controller/SysUserController.java index 900dd55..f0a6c47 100644 --- a/mesnac-modules/mesnac-system/src/main/java/com/mesnac/system/controller/SysUserController.java +++ b/mesnac-modules/mesnac-system/src/main/java/com/mesnac/system/controller/SysUserController.java @@ -4,9 +4,10 @@ import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import javax.servlet.http.HttpServletResponse; - +import com.mesnac.common.core.constant.CacheConstants; import com.mesnac.common.core.text.Convert; import com.mesnac.common.redis.service.RedisService; import com.mesnac.system.domain.SysUserDatasource; @@ -179,7 +180,7 @@ public class SysUserController extends BaseController // 园区集合 List> poolNameList = userService.getPoolNameList(user); // 缓存用户园区 - String poolName = redisService.getCacheObject("user_pool_name_current:"+ user.getUserName()); + String poolName = redisService.getCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + user.getUserName()); user.setPoolName(poolName); AjaxResult ajax = AjaxResult.success(); @@ -374,6 +375,15 @@ public class SysUserController extends BaseController return success(deptService.selectDeptTreeList(dept)); } + @PutMapping("/changePoolName") + public AjaxResult changePoolName(@RequestBody SysUser user) { + String username = SecurityUtils.getUsername(); + // 缓存用户数据源 + redisService.setCacheObject(CacheConstants.USER_POOL_NAME_CURRENT + username, user.getPoolName(), + CacheConstants.REFRESH_TIME, TimeUnit.MINUTES); + return success(); + } + /** * 根据用户ID获取数据源ID * @param sysUser