package cn.qinys.platform.upms.config;


import cn.qinys.platform.upms.config.mybatisplus.TenantInterceptor;
import cn.qinys.platform.upms.properties.SystemProperties;
import jakarta.annotation.Resource;
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;



/**
 * Description:
 *
 * @author tanlie
 * Date: 2024/3/4 15:44
 */
@Configuration
public class UpmsMvcConfig implements WebMvcConfigurer {

    @Resource
    SystemProperties systemProperties;


    /**
     * 添加静态资源文件，外部可以直接访问地址
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upms/ext/file/**")
                .addResourceLocations(
                        "file:" + systemProperties.getFileDirectory(),
                        "file:" + systemProperties.getTempDirectory(),
                        "file:" + systemProperties.getRichDirectory()
                );
    }

    /**
     * 配置拦截器
     *
     * @param registry 相当于拦截器的注册中心
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //下面这句代码相当于添加一个拦截器   添加的拦截器就是我们刚刚创建的
        registry.addInterceptor(new TenantInterceptor()) //添加租户ID
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**");
    }


}
