package com.roma.romaapi.config;

import com.roma.romaapi.interceptor.JWTInterceptor;
import com.roma.romaapi.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
import java.util.Map;

/**
 * 拦截器的配置文件
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;
    @Autowired
    PageService pageService;
    @Autowired
    private JWTInterceptor jwtInterceptor;
    @Value("${spring.redis.host}")
    private String redisHost;

    @Value("${spring.redis.port}")
    private String redisPort;

    @Value("${spring.redis.password}")
    private String redisPassword;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        System.out.println("-----redisHost------"+redisHost);
//        System.out.println("-----redisPort------"+redisPort);
//        System.out.println("-----redisPassword------"+redisPassword);
//        String captchaTokenValue = redisTemplate.opsForValue().get("dsdsdsds"); // 缓存中验证码的值
//        System.out.println("---调用redis缓存---"+captchaTokenValue);
//        List pages = pageService.menu();
//        System.out.println("---shujuku---"+pages);
        registry.addInterceptor(jwtInterceptor)
                //拦截的路径
                .addPathPatterns("/**")
                //排除登录接口
                .excludePathPatterns("/login/verifyCode")
                .excludePathPatterns("/api/login")
                .excludePathPatterns("/error")
        ;
    }
}
