/*
 * ********************************************************************************************************************
 *
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2019.  北京上格云技术有限公司
 *           ;%@@$=$@@%*       *@@@$=%@@%;
 *              ::;::             ::;::                                              All rights reserved.
 *
 * ********************************************************************************************************************
 */

package com.persagy.labsl

import com.alibaba.fastjson.PropertyNamingStrategy
import com.persagy.service.interceptors.SPageInterceptor
import com.persagy.service.json.SJsonHttpMessageConverter
import org.slf4j.LoggerFactory
import org.springframework.context.annotation.Configuration
import org.springframework.http.converter.HttpMessageConverter
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer

@Configuration
open class WebMvcConfg: WebMvcConfigurer {
    companion object {
        // 日志
        private val logger = LoggerFactory.getLogger(WebMvcConfg::class.java)
    } // Companion object

    /**
     * 配置拦截器
     *
     * @param   registry        拦截器注册器
     */
    override fun addInterceptors(registry : InterceptorRegistry) {
//        registry.addInterceptor(AccessControlAllowOriginInterceptor()).addPathPatterns("/**")

        registry.addInterceptor(SPageInterceptor()).addPathPatterns("/**")
        super.addInterceptors(registry)

    } // Function addInterceptors()

    /**
     * 配置 json 转换使用 FastJson
     *
     * @param   converterList       转换器列表
     */
    override fun configureMessageConverters(converterList: MutableList<HttpMessageConverter<*>>) {
        // 先把JackSon的消息转换器删除.
        converterList.removeIf { item -> item is MappingJackson2HttpMessageConverter }

        val converter = SJsonHttpMessageConverter()
        // 设置 Json 序列化，属性首字母小写
        converter.propertyNamingStrategy = PropertyNamingStrategy.CamelCase
        converterList.add(converter)
    }

} // Class WebMvcConf()