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); + } + } /**