package com.reyun.saas.web.config;

import com.reyun.saas.common.framework.ApiPathProperties;
import com.reyun.saas.common.framework.ApiRestController;
import com.reyun.saas.common.framework.OpenapiCpRestController;
import com.reyun.saas.common.framework.ReportRestController;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 配置统一的后台接口访问路径的前缀
 */
@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {

    @Resource
    private ApiPathProperties apiPathProperties;

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer
                .addPathPrefix(apiPathProperties.getGlobalPrefix(),c -> c.isAnnotationPresent(ApiRestController.class))
                .addPathPrefix(apiPathProperties.getReportPrefix(),c -> c.isAnnotationPresent(ReportRestController.class))
                .addPathPrefix(apiPathProperties.getOpenApiCpPrefix(),c -> c.isAnnotationPresent(OpenapiCpRestController.class));
    }

}
