From a2ea6bb1d7cd231385bef5254afaa3d4025bbd80 Mon Sep 17 00:00:00 2001 From: heminjian502 Date: Thu, 11 Aug 2022 14:45:02 +0800 Subject: [PATCH] =?UTF-8?q?app=E7=99=BB=E5=BD=95=E6=97=B6=E6=95=88?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/domain/model/LoginUser.java | 13 +++++++++++ .../web/service/SysLoginService.java | 4 +++- .../framework/web/service/TokenService.java | 22 ++++++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java index db4d2a5..7612bc5 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/model/LoginUser.java @@ -71,6 +71,11 @@ public class LoginUser implements UserDetails */ private SysUser user; + /** + * 1:app/mp 2:管理台 + */ + private String requestFrom; + public Long getUserId() { return userId; @@ -263,4 +268,12 @@ public class LoginUser implements UserDetails { return null; } + + public String getRequestFrom() { + return requestFrom; + } + + public void setRequestFrom(String requestFrom) { + this.requestFrom = requestFrom; + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 302bc0a..34d3ed0 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -124,7 +124,8 @@ public class SysLoginService sysUser.setHospitalId(tDoctor.getHospitalId()); loginUser.setUserId(sysUser.getUserId()); loginUser.setUser(sysUser); - String token = userTokenService.createToken(loginUser); + loginUser.setRequestFrom("1"); + String token = userTokenService.createTokenForApp(loginUser); AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); recordLoginInfo(sysUser.getUserId()); ajax.put(Constants.TOKEN, token); @@ -195,6 +196,7 @@ public class SysLoginService sysUser.setHospitalId(tDoctor.getHospitalId()); loginUser.setUserId(sysUser.getUserId()); loginUser.setUser(sysUser); + loginUser.setRequestFrom("1"); String token = userTokenService.createTokenForApp(loginUser); AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); AjaxResult ajaxResult = AjaxResult.success(); diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java index bf28e0f..7bdc28d 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/TokenService.java @@ -40,6 +40,9 @@ public class TokenService @Value("${token.expireTime}") private int expireTime; + @Value("${token.appExpireTime}") + private int appExpireTime; + protected static final long MILLIS_SECOND = 1000; protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; @@ -140,11 +143,20 @@ public class TokenService */ public void refreshToken(LoginUser loginUser) { - loginUser.setLoginTime(System.currentTimeMillis()); - loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); - // 根据uuid将loginUser缓存 - String userKey = getTokenKey(loginUser.getToken()); - redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); + if ("1".equals(loginUser.getRequestFrom())) { + loginUser.setLoginTime(System.currentTimeMillis()); + loginUser.setExpireTime(loginUser.getLoginTime() + appExpireTime * MILLIS_MINUTE); + // 根据uuid将loginUser缓存 + String userKey = getTokenKey(loginUser.getToken()); + redisCache.setCacheObject(userKey, loginUser, appExpireTime, TimeUnit.MINUTES); + } else { + loginUser.setLoginTime(System.currentTimeMillis()); + loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); + // 根据uuid将loginUser缓存 + String userKey = getTokenKey(loginUser.getToken()); + redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); + } + } /**