app登录时效修改

master
heminjian502 2 years ago
parent 97624a399a
commit a2ea6bb1d7

@ -71,6 +71,11 @@ public class LoginUser implements UserDetails
*/ */
private SysUser user; private SysUser user;
/**
* 1:app/mp 2:
*/
private String requestFrom;
public Long getUserId() public Long getUserId()
{ {
return userId; return userId;
@ -263,4 +268,12 @@ public class LoginUser implements UserDetails
{ {
return null; return null;
} }
public String getRequestFrom() {
return requestFrom;
}
public void setRequestFrom(String requestFrom) {
this.requestFrom = requestFrom;
}
} }

@ -124,7 +124,8 @@ public class SysLoginService
sysUser.setHospitalId(tDoctor.getHospitalId()); sysUser.setHospitalId(tDoctor.getHospitalId());
loginUser.setUserId(sysUser.getUserId()); loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser); 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"))); AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
recordLoginInfo(sysUser.getUserId()); recordLoginInfo(sysUser.getUserId());
ajax.put(Constants.TOKEN, token); ajax.put(Constants.TOKEN, token);
@ -195,6 +196,7 @@ public class SysLoginService
sysUser.setHospitalId(tDoctor.getHospitalId()); sysUser.setHospitalId(tDoctor.getHospitalId());
loginUser.setUserId(sysUser.getUserId()); loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser); loginUser.setUser(sysUser);
loginUser.setRequestFrom("1");
String token = userTokenService.createTokenForApp(loginUser); String token = userTokenService.createTokenForApp(loginUser);
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"))); AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
AjaxResult ajaxResult = AjaxResult.success(); AjaxResult ajaxResult = AjaxResult.success();

@ -40,6 +40,9 @@ public class TokenService
@Value("${token.expireTime}") @Value("${token.expireTime}")
private int expireTime; private int expireTime;
@Value("${token.appExpireTime}")
private int appExpireTime;
protected static final long MILLIS_SECOND = 1000; protected static final long MILLIS_SECOND = 1000;
protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
@ -140,11 +143,20 @@ public class TokenService
*/ */
public void refreshToken(LoginUser loginUser) public void refreshToken(LoginUser loginUser)
{ {
loginUser.setLoginTime(System.currentTimeMillis()); if ("1".equals(loginUser.getRequestFrom())) {
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); loginUser.setLoginTime(System.currentTimeMillis());
// 根据uuid将loginUser缓存 loginUser.setExpireTime(loginUser.getLoginTime() + appExpireTime * MILLIS_MINUTE);
String userKey = getTokenKey(loginUser.getToken()); // 根据uuid将loginUser缓存
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); 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);
}
} }
/** /**

Loading…
Cancel
Save