package com.backendsys.config;

import com.backendsys.modules.common.interceptor.ApiLogInterceptor;
import com.backendsys.config.Mybatis.handler.timezone.TimezoneInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${API_LOG}")
    private Boolean API_LOG;

    @Autowired
    private ApiLogInterceptor apiLogInterceptor;        // 日志拦截器
    @Autowired
    private TimezoneInterceptor timezoneInterceptor;    // 时区拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 日志拦截器
        if (API_LOG) registry.addInterceptor(apiLogInterceptor);

        // 时区拦截器
        registry.addInterceptor(timezoneInterceptor);

    }

    // 静态资源映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/static/images/");
    }

}
