//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.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//import java.util.Collections;
//
///**
// * @author lfdc
// * @description TDengine配置类
// * @date 2023-11-19 10:11:24
// */
//@Configuration
//@MapperScan(basePackages = "com.sckw.slope.detection.dao.tdengine", sqlSessionTemplateRef = "tdengineSqlSessionTemplate")
//
//public class TDengineServerConfig {
//    @Autowired
//    private PaginationInnerInterceptor paginationInnerInterceptor;
//
//    private static final String MAPPER_LOCATION = "classpath:mapper/tdengine/*.xml";
//
//    @Bean(name = "tdengineDataSource")
//    @ConfigurationProperties(prefix = "spring.datasource.td")
//    public DataSource tdengineDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "tdengineSqlSessionFactory")
//    public SqlSessionFactory tdengineSqlSessionFactory(@Qualifier("tdengineDataSource") DataSource dataSource) throws Exception {
//        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.TDENGINE);
//        // 开启 count 的 join 优化,只针对部分 left join
//        paginationInnerInterceptor.setOptimizeJoin(true);
//        mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor));
//        bean.setPlugins(mybatisPlusInterceptor);
//
//        return bean.getObject();
//    }
//
//    @Bean(name = "tdengineTransactionManager")
//    public DataSourceTransactionManager tdengineTransactionManager(@Qualifier("tdengineDataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//
//
//    @Bean(name = "tdengineSqlSessionTemplate")
//    public SqlSessionTemplate tdengineSqlSessionTemplate(@Qualifier("tdengineSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//
//}
