package com.ym.mec.common.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;

/**
 * @author hgw
 * Created by 2021-12-02
 */
@Configuration
public class MyBatisPlusConfig {

    @Autowired
    private MybatisPlusProperties plusProperties;

    /**
     * 分页插件
     */
    @Bean
    @Primary
    public PaginationInterceptor paginationInterceptor() {
        plusProperties.setMapperLocations(new String[]{"classpath*:/config/mybatis/*.xml"});
        plusProperties.setTypeAliasesPackage("com.ym.mec.biz.dal.entity");
        MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
        mybatisConfiguration.setMapUnderscoreToCamelCase(true);
        mybatisConfiguration.setCacheEnabled(false);
        plusProperties.setConfiguration(mybatisConfiguration);
        return new PaginationInterceptor();
    }


    /**
     * 性能分析插件
     */
    @Bean
    @Profile({"dev","test"})
    public PerformanceInterceptor performanceInterceptor() {
        return new PerformanceInterceptor();
    }

}
