//package cn.wisenergy.web.config.hanlder;
//
//import cn.wisenergy.common.utils.RedisUtil;
//import cn.wisenergy.common.utils.exception.BASE_RESP_CODE_ENUM;
//import cn.wisenergy.common.utils.exception.BaseCustomException;
//import org.apache.commons.lang.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpSession;
//import java.io.IOException;
//import java.util.Arrays;
//import java.util.List;
//
///**
// * @description:
// * @author: nh
// * @create: 2021-04-01 10:44
// **/
//@Component
//public class LoginFilter implements Filter {
//
//    @Autowired
//    private RedisUtil redisUtil;
//
//    private static final int SESSION_EXPIRE = 30 * 60;
//
//    private final static List<String> URI_LIST = Arrays.asList("/login","/webjars","/swagger-resources",
//            "/null","/v2","/swagger-ui.html","/work/collect","/work/order/addOrder","/work/order/examine","/work/order/getDeptNotOrderInfo",
//            "/work/order/getExamineApplets","/work/order/getProject","/work/order/noSubmit","/work/order/query","/work/order/reject",
//            "/changePassword","/getUserInfo","/statistics/getCurrentMonthWorkTimeCollect","/statistics/getMonthlyWorkingHours");
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
//        HttpSession session = httpServletRequest.getSession(false);
//
//        // 请求接口不为指定接口再过滤
//         String requestURI = ((HttpServletRequest) request).getRequestURI();
//        System.out.println("requestURI = " + requestURI);
//        for (String s : URI_LIST) {
//            if (requestURI.startsWith(s)) {
//                chain.doFilter(request,response);
//                return;
//            }
//        }
//
//        // 请求没有携带session
//        if (session == null) {
//            System.out.println("session Is Null");
//            throw new BaseCustomException(BASE_RESP_CODE_ENUM.PLEASE_RE_LOGIN);
//        }
//        System.out.println("session.getId() = " + session.getId());
//        // 获取redis中存储的登录时存放的session
//        String sessionCache = redisUtil.get(session.getId());
//        // session为空，session与登录时的session不一致提示重新登录，不为空则进行下一个过滤
//        if (StringUtils.isBlank(sessionCache)) {
//            throw new BaseCustomException(BASE_RESP_CODE_ENUM.PLEASE_RE_LOGIN);
//        } else if (!sessionCache.equals(session)) {
//            throw new BaseCustomException(BASE_RESP_CODE_ENUM.PLEASE_RE_LOGIN);
//        } else {
//            redisUtil.set(session.getId(), session.toString(), SESSION_EXPIRE);
//            chain.doFilter(request, response);
//        }
//
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
