From a2746876e81443d52bc4cb6f35bf8554741a6b4c Mon Sep 17 00:00:00 2001 From: liukangdong <898885815@qq.com> Date: 星期五, 18 十月 2024 14:28:33 +0800 Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/dmvisit --- server/system_service/src/main/java/com/doumee/api/BaseController.java | 32 +++++++++++++++++++++----------- 1 files changed, 21 insertions(+), 11 deletions(-) diff --git a/server/system_service/src/main/java/com/doumee/api/BaseController.java b/server/system_service/src/main/java/com/doumee/api/BaseController.java index 61f1a43..3001582 100644 --- a/server/system_service/src/main/java/com/doumee/api/BaseController.java +++ b/server/system_service/src/main/java/com/doumee/api/BaseController.java @@ -1,6 +1,7 @@ package com.doumee.api; import com.alibaba.fastjson.JSONObject; +import com.doumee.config.jwt.JwtProperties; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.LoginUserInfo; @@ -13,7 +14,11 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; /** * Controller鍩虹被 @@ -25,22 +30,17 @@ @Autowired private RedisTemplate<String,Object> stringRedisTemplate; + @Resource + private JwtProperties jwtProperties; /** * 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛 * @author Eva.Caesar Liu * @date 2023/03/21 14:49 */ - protected LoginUserInfo getLoginUser () { - return (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); - } - /** - * 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛 - * @author Eva.Caesar Liu - * @date 2023/03/21 14:49 - */ - protected LoginUserInfo getLoginUser (String token) { + public LoginUserInfo getLoginUser (String token) { if (token == null || token.isEmpty()) { - throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�"); + return (LoginUserInfo)SecurityUtils.getSubject().getPrincipal(); +// throw new BusinessException(ResponseStatus.NO_LOGIN.getCode(),"鏈櫥褰�"); } String userinfo =(String) stringRedisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY + token); if (StringUtils.isBlank(userinfo)) { @@ -51,6 +51,9 @@ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐢ㄦ埛鐧婚檰宸插け鏁堬紝璇烽噸鏂扮櫥闄嗭紒"); } return user; + } + public void updateLoginUser (String token,LoginUserInfo userInfo) { + stringRedisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY+token,JSONObject.toJSONString(userInfo),jwtProperties.getExpiration(), TimeUnit.MILLISECONDS); } @@ -64,5 +67,12 @@ return request; } - + public List<Integer> getIdList(String ids){ + String [] idArray = ids.split(","); + List<Integer> idList = new ArrayList<>(); + for (String id : idArray) { + idList.add(Integer.valueOf(id)); + } + return idList; + } } -- Gitblit v1.9.3