From d1681dc18c786ff97b24b0849d453e896af7b8fc Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 17 八月 2022 18:19:48 +0800 Subject: [PATCH] 👀 发布 4.3.0-beta2 公测版 --- ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java | 23 ++++++++++++----------- 1 files changed, 12 insertions(+), 11 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java index 75277c2..d6268eb 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/listener/UserActionListener.java @@ -3,22 +3,19 @@ import cn.dev33.satoken.config.SaTokenConfig; import cn.dev33.satoken.listener.SaTokenListener; import cn.dev33.satoken.stp.SaLoginModel; -import cn.dev33.satoken.stp.StpUtil; import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; -import com.ruoyi.common.constant.Constants; +import com.ruoyi.common.constant.CacheNames; import com.ruoyi.common.core.domain.dto.UserOnlineDTO; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.enums.UserType; import com.ruoyi.common.helper.LoginHelper; import com.ruoyi.common.utils.ServletUtils; +import com.ruoyi.common.utils.redis.CacheUtils; import com.ruoyi.common.utils.ip.AddressUtils; -import com.ruoyi.common.utils.redis.RedisUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; - -import java.util.concurrent.TimeUnit; /** * 鐢ㄦ埛琛屼负 渚﹀惉鍣ㄧ殑瀹炵幇 @@ -36,13 +33,12 @@ * 姣忔鐧诲綍鏃惰Е鍙� */ @Override - public void doLogin(String loginType, Object loginId, SaLoginModel loginModel) { + public void doLogin(String loginType, Object loginId, String tokenValue, SaLoginModel loginModel) { UserType userType = UserType.getUserType(loginId.toString()); if (userType == UserType.SYS_USER) { UserAgent userAgent = UserAgentUtil.parse(ServletUtils.getRequest().getHeader("User-Agent")); String ip = ServletUtils.getClientIP(); LoginUser user = LoginHelper.getLoginUser(); - String tokenValue = StpUtil.getTokenValueByLoginId(loginId); UserOnlineDTO dto = new UserOnlineDTO(); dto.setIpaddr(ip); dto.setLoginLocation(AddressUtils.getRealAddressByIP(ip)); @@ -52,7 +48,12 @@ dto.setTokenId(tokenValue); dto.setUserName(user.getUsername()); dto.setDeptName(user.getDeptName()); - RedisUtils.setCacheObject(Constants.ONLINE_TOKEN_KEY + tokenValue, dto, tokenConfig.getTimeout(), TimeUnit.SECONDS); + String cacheNames = CacheNames.ONLINE_TOKEN; + if (tokenConfig.getTimeout() > 0) { + // 澧炲姞 ttl 杩囨湡鏃堕棿 鍗曚綅绉� + cacheNames = CacheNames.ONLINE_TOKEN + "#" + tokenConfig.getTimeout() + "s"; + } + CacheUtils.put(cacheNames, tokenValue, dto); log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue); } else if (userType == UserType.APP_USER) { // app绔� 鑷鏍规嵁涓氬姟缂栧啓 @@ -64,7 +65,7 @@ */ @Override public void doLogout(String loginType, Object loginId, String tokenValue) { - RedisUtils.deleteObject(Constants.ONLINE_TOKEN_KEY + tokenValue); + CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue); log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue); } @@ -73,7 +74,7 @@ */ @Override public void doKickout(String loginType, Object loginId, String tokenValue) { - RedisUtils.deleteObject(Constants.ONLINE_TOKEN_KEY + tokenValue); + CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue); log.info("user doLogoutByLoginId, userId:{}, token:{}", loginId, tokenValue); } @@ -82,7 +83,7 @@ */ @Override public void doReplaced(String loginType, Object loginId, String tokenValue) { - RedisUtils.deleteObject(Constants.ONLINE_TOKEN_KEY + tokenValue); + CacheUtils.evict(CacheNames.ONLINE_TOKEN, tokenValue); log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue); } -- Gitblit v1.9.3