k94314517
2024-10-30 47a53d22a025c0ed095c9c4ed2e1ce35ce54184e
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基类
@@ -30,17 +35,10 @@
     * @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)) {
@@ -64,5 +62,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;
    }
}