package com.jpsoft.shinestar.config;

import com.jpsoft.shinestar.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
	@Autowired
	private LoginInterceptor loginInterceptor;

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
				.allowedOrigins("*")
				.allowedHeaders("*")
				.allowedMethods("*")
				.allowCredentials(false)
				.exposedHeaders("access-control-allow-headers",
						"access-control-allow-methods",
						"access-control-allow-origin",
						"access-control-max-age",
						"X-Frame-Options",
						"token-status")
				.maxAge(3600);
	}

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");

		registry.addResourceHandler("swagger-ui.html")
				.addResourceLocations("classpath:/META-INF/resources/");

		registry.addResourceHandler("/webjars/**")
				.addResourceLocations("classpath:/META-INF/resources/webjars/");
	}

	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		// registry.addViewController("/login").setViewName("login");
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(loginInterceptor)
				.addPathPatterns("/**")
                .excludePathPatterns("/login",
						"/swagger-resources/**",
                        "/webjars/**",
                        "/swagger-ui.html",
						"/doc.html",
                        "/v2/**",
                        "/mobileApi/**")
				.excludePathPatterns("/wxPay/webPay")
				.excludePathPatterns("/aliPay/tradePrecreatePay")
				.excludePathPatterns("/wxPay/parkingWxPay")
				.excludePathPatterns("/aliPay/parkingTradeWebPay")
				.excludePathPatterns("/aliPay/payNotify")
				.excludePathPatterns("/wxPay/payNotify")
				.excludePathPatterns("/wxPay/wxJsapiPayNotify")
				.excludePathPatterns("/aliPay/**")
				.excludePathPatterns("/wxPay/parkingWxPayNotify")
				.excludePathPatterns("/base/alarmInfo/alarmNotify")
				.excludePathPatterns("/base/informationInfo/addMobile")
				.excludePathPatterns("/base/employeeInfo/mobile/**")
//				.excludePathPatterns("/base/companyInfo/list")
				.excludePathPatterns("/wechat/**")
				.excludePathPatterns("/wxCp/**")
				.excludePathPatterns("/rabbit/**")
				.excludePathPatterns("/mobile/personInfoApi/findByNameAndPhone")
				.excludePathPatterns("/mobile/personInfoApi/getVerifyCode")
				.excludePathPatterns("/mobile/personInfoApi/validateCode")
				.excludePathPatterns("/mobile/personInfoApi/findByOpenId")
				.excludePathPatterns("/mobile/personInfoApi/uploadBase64")
				.excludePathPatterns("/mobile/personDeviceLogApi/detail")
				.excludePathPatterns("/mobile/PersonDeviceFilterLog/queryUnmeasureGroupList")
				.excludePathPatterns("/mobile/healthShowApi/getCompanyToken")
				.excludePathPatterns("/healthPublicity")
                .excludePathPatterns("/healthPublicityCanteen")
				.excludePathPatterns("/static/**")
				.excludePathPatterns("/mobile/guestInfoRecordApi/detail/*")
				.excludePathPatterns("/mobile/guestInfoRecordApi/update")
				.excludePathPatterns("/mobile/guestInfoRecordApi/getInfo")
                .excludePathPatterns("/mobile/guestInfoRecordApi/currentPageList")
				.excludePathPatterns("/mobile/guestInfoRecordApi/save")
				.excludePathPatterns("/mobile/companyInfoApi/schoolServeList")
				.excludePathPatterns("/mobile/companyInfoApi/serviceCompanyIdList")
				.excludePathPatterns("/devOps/login")
				.excludePathPatterns("/mobile/scene/sceneList")
				.excludePathPatterns("/mobile/scene/regionList")
				.excludePathPatterns("/mobile/scene/companyListByRegion")
				.excludePathPatterns("/mobile/scene/personRoleListByScene")
				.excludePathPatterns("/mobile/scene/companyStructureList")
				.excludePathPatterns("/mobile/scene/companyStructureByParentId")
				.excludePathPatterns("/mobile/scene/companyBySceneAndName")
				.excludePathPatterns("/mobile/scene/companyStructureByName")
				.excludePathPatterns("/mobile/personInfoApi/register")
                .excludePathPatterns("/mobile/personInfoApi/relationOlder")
                .excludePathPatterns("/mobile/personInfoApi/olderDetail")
				.excludePathPatterns("/ehome/**")
				.excludePathPatterns("/mobile/personInfoApi/sendMessage")
				.excludePathPatterns("/mobile/personInfoApi/regionList")
				.excludePathPatterns("/mobile/personInfoApi/returnInfoDetail")
				.excludePathPatterns("/mobile/personInfoApi/submitReturnInfo")
				.excludePathPatterns("/mobile/personInfoApi/confirmReturnInfo")
				.excludePathPatterns("/qrcode/**")
				.excludePathPatterns("/mobile/companyInfoApi/link")
				.excludePathPatterns("/mobile/companyInfoApi/link")
				.excludePathPatterns("/mobile/parkingInfoApi/inParkDate")
				.excludePathPatterns("/mobile/parkingInfoApi/outParkDate")
				.excludePathPatterns("/mobile/parkingInfoApi/findByOpenIdAndMerchant")
				.excludePathPatterns("/mobile/parkingInfoApi/carPayDetail")
				.excludePathPatterns("/mobile/parkingInfoApi/channelPayDetail")
				.excludePathPatterns("/mobile/parkingInfoApi/findByCompanyId")
				.excludePathPatterns("/mobile/parkingInfoApi/bindParkMerchant")
		;
	}
}
