派生自 projectDept/qhighschool

dengqingliu
2022-11-22 8cac07d66bef9c682f071fcc1df36a6f8c2a0c30
src/main/java/com/qxueyou/scc/base/util/ClientUtils.java
@@ -3,7 +3,11 @@
import java.util.List;
import java.util.Map;
import com.qxueyou.scc.base.dao.AbstractRedisTemplate;
import com.qxueyou.scc.base.dao.CommonRedisTemplate;
import com.qxueyou.scc.base.model.UserInfoWrapper;
import com.qxueyou.scc.base.service.impl.RedisCacheBean;
import com.qxueyou.scc.sys.utils.SpringContextHolder;
import org.apache.commons.lang3.StringUtils;
import com.qxueyou.scc.base.model.Constants;
@@ -11,9 +15,17 @@
import com.qxueyou.scc.sys.model.ResponseResult;
import com.qxueyou.scc.sys.model.SysMenu;
import com.qxueyou.scc.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.cache.RedisCache;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.core.RedisAccessor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@@ -32,18 +44,26 @@
   private static ThreadLocal<UserInfoWrapper> threadLocalUserInfo = new ThreadLocal<UserInfoWrapper>();
   private static UserInfoWrapper wrapper = threadLocalUserInfo.get();
   private static RedisTemplate redisTemplate = (RedisTemplate)SpringContextHolder.getBean("redisTemplate");
   /** 得到用户信息*/
   public static UserInfoWrapper getUserInfo() {
      UserInfoWrapper wrapper = threadLocalUserInfo.get();
      if(wrapper == null){
         wrapper = new UserInfoWrapper();
         User user = new User();
         //默认值,上传可以作为默认上传者
         user.setUserId(Constants.VISITOR_USER_ID);
         user.setName(Constants.VISITOR_USER_ID);
         wrapper.setUser(user);
         setUserInfo(wrapper);
      }
//      UserInfoWrapper wrapper = threadLocalUserInfo.get();
//      if(wrapper == null) {
         wrapper = (UserInfoWrapper)redisTemplate.opsForValue().get(UserInfoWrapper.SESSION_USER_INFO_KEY);
         if (wrapper == null) {
            wrapper = new UserInfoWrapper();
            User user = new User();
            //默认值,上传可以作为默认上传者
            user.setUserId(Constants.VISITOR_USER_ID);
            user.setName(Constants.VISITOR_USER_ID);
            wrapper.setUser(user);
            setUserInfo(wrapper);
         }
//      }
//      else{
//         redisTemplate.opsForValue().set(UserInfoWrapper.SESSION_USER_INFO_KEY,wrapper);
//      }
      return wrapper;
   }
@@ -62,8 +82,6 @@
      String info = getUserInfo().getInfo(UserInfoWrapper.INF_USER_ID);
      if(info.equals("visitor_001")){
         info= (String) session.getAttribute(UserInfoWrapper.INF_USER_ID);
      }else {
         session.setAttribute(UserInfoWrapper.INF_USER_ID,info);
      }
      return info;
   }