

package com.tuoheng.admin.interceptor;

//@Component
//@Slf4j
//public class UserInterceptor implements HandlerInterceptor {
//
//    @Autowired
//    private IUserService userService;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        log.info("开始执行过滤器");
//        String username = SecurityUserUtils.username();
//
//        if (StringUtils.isEmpty(username)) {
//            throw new ServiceException(HttpStatus.BAD_REQUEST.value(),"username不能为空");
//        }
//
//        if(userService==null){
//            log.info("userService is null!!!");
//            BeanFactory factory = WebApplicationContextUtils
//                    .getRequiredWebApplicationContext(request.getServletContext());
//            userService = (IUserService) factory
//                    .getBean("UserServiceImpl");
//        }
//        User user = userService.getOne(Wrappers.<User>lambdaQuery()
//                .eq(User::getMark, 1)
//                .eq(User::getStatus, 1)
//                .eq(StringUtils.isNotEmpty(username), User::getUsername, username));
//        if (StringUtils.isNull(user)) {
//            log.error("用户信息不存在:{}", user);
//            return false;
//        }
//        ThreadLocalUtil.set(user);
//        log.info("执行完毕");
//        return true;
//    }
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//       //结束方法清理内存
//        ThreadLocalUtil.remove();
//        log.info("清理ThreadLocal内存完毕");
//    }
//}

