//package com.sckw.slope.detection.common.config.dateSource;
//
//import com.baomidou.mybatisplus.annotation.DbType;
//import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
//import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
//import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//import java.util.Collections;
//
///**
// * @author lfdc
// * @description mysql配置类
// * @date 2023-11-19 10:11:19
// */
//@Configuration
//@MapperScan(basePackages = {"com.sckw.slope.detection.dao.mysql"}, sqlSessionTemplateRef  = "mysqlSqlSessionTemplate")
//public class MysqlServerConfig {
//    @Autowired
//    private PaginationInnerInterceptor paginationInnerInterceptor;
//
//    private static final String MAPPER_LOCATION = "classpath:mapper/mysql/*.xml";
//    @Bean(name = "mysqlDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.master")
//    @Primary
//    public DataSource mysqlDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "mysqlSqlSessionFactory")
//    @Primary
//    public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource dataSource) throws Exception {
//        //注意这里一定要用MybatisSqlSessionFactoryBean，如果用SqlSessionFactory，配置无效
//        MybatisSqlSessionFactoryBean bean = new MybatisSqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        bean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));
//
//        //不在这里注入分页插件，会失效，（MyBatisPlusConfig只负责注册分页插件）
//        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
//        paginationInnerInterceptor.setMaxLimit(-1L);
//        paginationInnerInterceptor.setDbType(DbType.MYSQL);
//        // 开启 count 的 join 优化,只针对部分 left join
//        paginationInnerInterceptor.setOptimizeJoin(true);
//        mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor));
//        bean.setPlugins(mybatisPlusInterceptor);
//
//        return bean.getObject();
//    }
//
//    @Bean(name = "mysqlTransactionManager")
//    @Primary
//    public DataSourceTransactionManager mysqlTransactionManager(@Qualifier("mysqlDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//    @Bean(name = "mysqlSqlSessionTemplate")
//    @Primary
//    public SqlSessionTemplate mysqlSqlSessionTemplate(@Qualifier("mysqlSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//}
