Authored by mali

版本升级

@@ -6,6 +6,7 @@ package com.yoho.ufo.interceptor; @@ -6,6 +6,7 @@ package com.yoho.ufo.interceptor;
6 import java.util.ArrayList; 6 import java.util.ArrayList;
7 import java.util.List; 7 import java.util.List;
8 8
  9 +import javax.annotation.Resource;
9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse; 11 import javax.servlet.http.HttpServletResponse;
11 12
@@ -13,6 +14,7 @@ import com.yoho.ufo.constants.CodeEnum; @@ -13,6 +14,7 @@ import com.yoho.ufo.constants.CodeEnum;
13 import com.yoho.ufo.constants.PlatformConstant; 14 import com.yoho.ufo.constants.PlatformConstant;
14 import com.yoho.ufo.login.model.OperatorBean; 15 import com.yoho.ufo.login.model.OperatorBean;
15 import com.yoho.ufo.login.model.UserInfoResponseBO; 16 import com.yoho.ufo.login.model.UserInfoResponseBO;
  17 +import com.yoho.ufo.login.service.LoginSessionService;
16 import org.apache.commons.lang3.StringUtils; 18 import org.apache.commons.lang3.StringUtils;
17 import org.slf4j.Logger; 19 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 20 import org.slf4j.LoggerFactory;
@@ -29,6 +31,9 @@ import org.springframework.web.servlet.ModelAndView; @@ -29,6 +31,9 @@ import org.springframework.web.servlet.ModelAndView;
29 public class UrlInterceptor implements HandlerInterceptor { 31 public class UrlInterceptor implements HandlerInterceptor {
30 private static final Logger log = LoggerFactory.getLogger(UrlInterceptor.class); 32 private static final Logger log = LoggerFactory.getLogger(UrlInterceptor.class);
31 33
  34 + @Resource
  35 + private LoginSessionService loginSessionService;
  36 +
32 //免过滤列表(不管有没有session都可以访问) 37 //免过滤列表(不管有没有session都可以访问)
33 private List<String> firstNoFilterList = new ArrayList<String>(); 38 private List<String> firstNoFilterList = new ArrayList<String>();
34 39
@@ -64,7 +69,7 @@ public class UrlInterceptor implements HandlerInterceptor { @@ -64,7 +69,7 @@ public class UrlInterceptor implements HandlerInterceptor {
64 return true; 69 return true;
65 } 70 }
66 //过滤session失效的 71 //过滤session失效的
67 - //UserInfoResponseBO user = loginSessionUtil.getLoginSession(request); 72 + //UserInfoResponseBO user = loginSessionService.getLoginSession()
68 UserInfoResponseBO user = (UserInfoResponseBO) request.getSession().getAttribute(PlatformConstant.USER_SESSION); 73 UserInfoResponseBO user = (UserInfoResponseBO) request.getSession().getAttribute(PlatformConstant.USER_SESSION);
69 74
70 if (user == null) { 75 if (user == null) {
@@ -5,6 +5,7 @@ import com.yoho.ufo.login.model.MenuInfoResponseBO; @@ -5,6 +5,7 @@ import com.yoho.ufo.login.model.MenuInfoResponseBO;
5 import com.yoho.ufo.login.model.Response; 5 import com.yoho.ufo.login.model.Response;
6 import com.yoho.ufo.login.model.UserInfoResponseBO; 6 import com.yoho.ufo.login.model.UserInfoResponseBO;
7 import com.yoho.ufo.login.service.LoginService; 7 import com.yoho.ufo.login.service.LoginService;
  8 +import com.yoho.ufo.login.service.LoginSessionService;
8 import org.slf4j.Logger; 9 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
10 import org.springframework.stereotype.Controller; 11 import org.springframework.stereotype.Controller;
@@ -30,6 +31,9 @@ public class LoginController { @@ -30,6 +31,9 @@ public class LoginController {
30 @Resource 31 @Resource
31 private LoginService loginService; 32 private LoginService loginService;
32 33
  34 + @Resource
  35 + private LoginSessionService loginSessionService;
  36 +
33 /** 37 /**
34 * 登录 38 * 登录
35 * @param loginName 39 * @param loginName
@@ -54,6 +58,8 @@ public class LoginController { @@ -54,6 +58,8 @@ public class LoginController {
54 //登录成功,把用户信息存入session 58 //登录成功,把用户信息存入session
55 session.setAttribute(PlatformConstant.USER_SESSION, responseBO.getData()); 59 session.setAttribute(PlatformConstant.USER_SESSION, responseBO.getData());
56 60
  61 + // loginSessionService.setLoginSession(responseBO.getData(), request, responseBO.getData().getPid());
  62 +
57 //获取用户所能见的菜单 63 //获取用户所能见的菜单
58 Response<Map<String, List<MenuInfoResponseBO>>> menuResp = loginService.getUserMenu(responseBO.getData().getPid(), responseBO.getData().getRole_id(), "7"); 64 Response<Map<String, List<MenuInfoResponseBO>>> menuResp = loginService.getUserMenu(responseBO.getData().getPid(), responseBO.getData().getRole_id(), "7");
59 65
@@ -40,7 +40,7 @@ public class LoginSessionService { @@ -40,7 +40,7 @@ public class LoginSessionService {
40 if (StringUtils.isBlank(pid)) { 40 if (StringUtils.isBlank(pid)) {
41 return null; 41 return null;
42 } 42 }
43 - String userRedisValue = yhValueOperations.get(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, Integer.parseInt(pid)))); 43 + String userRedisValue = yhValueOperations.get(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, pid)));
44 logger.info( "getLoginSession userRedisValue is {}.", userRedisValue); 44 logger.info( "getLoginSession userRedisValue is {}.", userRedisValue);
45 if (StringUtils.isBlank(userRedisValue)) { 45 if (StringUtils.isBlank(userRedisValue)) {
46 return null; 46 return null;
@@ -53,16 +53,16 @@ public class LoginSessionService { @@ -53,16 +53,16 @@ public class LoginSessionService {
53 /** 53 /**
54 * 设置登录用户的缓存 54 * 设置登录用户的缓存
55 */ 55 */
56 - public void setLoginSession(UserInfoResponseBO userInfoResponseBO, HttpServletRequest request, int pid) { 56 + public void setLoginSession(UserInfoResponseBO userInfoResponseBO, HttpServletRequest request, String pid) {
57 logger.info( "setLoginSession userInfoResponseBO is {} and pid is {}.", userInfoResponseBO,pid); 57 logger.info( "setLoginSession userInfoResponseBO is {} and pid is {}.", userInfoResponseBO,pid);
58 - yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getPidKey(request)), String.valueOf(pid), 2, TimeUnit.HOURS);  
59 - yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, pid)), JSON.toJSONString(userInfoResponseBO), 2, TimeUnit.HOURS); 58 + //yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getPidKey(request)), String.valueOf(pid), 2, TimeUnit.HOURS);
  59 + yhValueOperations.set(RedisKeyBuilder.newInstance().appendFixed(getUserKey(request, pid)), JSON.toJSONString(userInfoResponseBO), 20, TimeUnit.MINUTES);
60 } 60 }
61 61
62 /** 62 /**
63 * 清除登录用户的缓存 63 * 清除登录用户的缓存
64 */ 64 */
65 - public void clearLoginSession(HttpServletRequest request, int pid){ 65 + public void clearLoginSession(HttpServletRequest request, String pid){
66 logger.info( "clearLoginSession pid is {}.", pid); 66 logger.info( "clearLoginSession pid is {}.", pid);
67 String pidKey = getPidKey(request); 67 String pidKey = getPidKey(request);
68 String userKey = getUserKey(request, pid); 68 String userKey = getUserKey(request, pid);
@@ -75,8 +75,8 @@ public class LoginSessionService { @@ -75,8 +75,8 @@ public class LoginSessionService {
75 return RedisKeyConstants.LOGIN_PID_PRE + getRemoteIp(request); 75 return RedisKeyConstants.LOGIN_PID_PRE + getRemoteIp(request);
76 } 76 }
77 77
78 - public String getUserKey(HttpServletRequest request, int pid) {  
79 - return RedisKeyConstants.LOGIN_USER_PRE + pid + "_" + getRemoteIp(request); 78 + public String getUserKey(HttpServletRequest request, String pid) {
  79 + return RedisKeyConstants.LOGIN_USER_PRE + pid;// + "_" + getRemoteIp(request);
80 } 80 }
81 81
82 private String getRemoteIp(HttpServletRequest request) { 82 private String getRemoteIp(HttpServletRequest request) {