package com.fzm.mall.server.admin.config;

import com.fzm.mall.server.admin.config.interceptor.AuthInterceptor;
import com.fzm.mall.server.admin.config.interceptor.TokenInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author wangp
 * @date 2021/2/26 16:06
 * @description 注册自定义拦截器
 * @since JDK 1.8
 */
@Configuration
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class WebMvcConfig implements WebMvcConfigurer {

    private final AuthInterceptor authInterceptor;
    private final TokenInterceptor tokenInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/**")
                .excludePathPatterns(
                        //放行swagger
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-ui.html/**",
                        "/doc.html**",
                        //微信退款回调
                        "/wxpay/refund/return"
                );
//        registry.addInterceptor(authInterceptor).addPathPatterns("/**");
//                .excludePathPatterns(
//                //放行静态资源js,css,图片等
//                "/css/**",
//                "/fonts/**",
//                "/img/**",
//                "/js/**",
//                "/favicon.ico",
//                "/index.html",
//                //放行请求
//                "/admin/common/login/**",
//                "/brand/getByPhone/**",
//                "/system/storeDrawProfit/**",
//                "/system/storeBuyProfit/**"
//        );
    }

}
