package com.sunxung.factoring.component.config;

import com.sunxung.factoring.component.interceptor.AuthenticationInterceptor;
import com.sunxung.factoring.component.util.FileUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * 系统自定义相关配置
 */
@Configuration
public class CustomConfiguration extends WebMvcConfigurerAdapter {

//
//    @Bean
//    public LoginFilter loginFilter(AuthorityService authorityService){
//
//        return new LoginFilter(authorityService);
//    }
//
//    @Bean
//    public FilterRegistrationBean loginFilterRegistration(LoginFilter loginFilter) {
//        FilterRegistrationBean fitler = new FilterRegistrationBean();
//        fitler.setFilter(loginFilter);
//        fitler.setOrder(0);
//        fitler.addUrlPatterns("/*");
//        fitler.addInitParameter("excludeUrls", "/user/do_login,/user/login,/purchContract/confirm/doAuth,/purchContract/confirm/signBack," +
//                        "/api/cashFlow/loanRecord/add," + "/api/financialInstitution/addFinancialInstitution," + "/api/underlyingBasicInfo/allFile"
//                        + ",/api/fileStorage/downloadFile" + ",/api/**");
//                fitler.addInitParameter("excludePrefixs", "/druid/,/authority/,/frontEnd/");
//        fitler.addInitParameter("excludeSuffixs", ".js,.gif,.jpg,.png,.css,.ico,.map,.svg,.eot,.ttf,.woff,.woff2");
//        return fitler;
//    }

    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {

        return new AuthenticationInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor());
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/" + FileUtil.DIR + "/**")
                .addResourceLocations("file:" + FileUtil.getAbsoluteDir() + "/" + FileUtil.DIR + "/");
        //vue前端代码地址
        registry.addResourceHandler("/frontEnd/**").addResourceLocations("classpath:/frontEnd/");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringToDateConverter());
    }
}
