//package com.yeejoin.amos.boot.module.jxiop.biz.config;
//import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.apache.ibatis.type.JdbcType;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.mybatis.spring.boot.autoconfigure.MybatisProperties;
//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.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//import java.io.IOException;
//import java.util.Optional;
//import java.util.stream.Stream;
//@Configuration
//@MapperScan(value = { "org.typroject.tyboot.demo.face.orm.dao*", "org.typroject.tyboot.face.*.orm.dao*",
//        "org.typroject.tyboot.core.auth.face.orm.dao*", "org.typroject.tyboot.component.*.face.orm.dao*",
//        "com.yeejoin.amos.boot.module.**.api.mapper", "com.yeejoin.amos.boot.biz.common.dao.mapper","com.yeejoin.amos.boot.module.common.biz.*" },sqlSessionFactoryRef = "sql1SessionFactory")
//public class PrimaryDataSourceConfig {
//
//    @Bean(name = "db1DataSource")
//   // @ConfigurationProperties(prefix = "spring.db1.datasource")
//    @Primary
//    public DataSource db1DataSource() {
//        return DruidDataSourceBuilder.create().build();
//    }
//
//    @Bean(name = "sql1SessionFactory")
//    @ConfigurationProperties(prefix = "mybatis")
//    @Primary
//    public SqlSessionFactory sql1SessionFactory(@Qualifier("db1DataSource") DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
//        bean.setDataSource(dataSource);
//        bean.setMapperLocations(
//                new PathMatchingResourcePatternResolver().getResources("classpath*:mappers/*.xml"));
//        return bean.getObject();
//    }
//
//    private Resource[] resolveMapperLocations(String[] mapperLocations) {
//        PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver = new PathMatchingResourcePatternResolver();
//
//        return Stream.of(Optional.ofNullable(mapperLocations).orElse(new String[0]))
//                .flatMap(location -> Stream.of(getResources(pathMatchingResourcePatternResolver, location))).toArray(Resource[]::new);
//    }
//
//    private Resource[] getResources(PathMatchingResourcePatternResolver pathMatchingResourcePatternResolver, String location) {
//        try {
//            return pathMatchingResourcePatternResolver.getResources(location);
//        } catch (IOException e) {
//            return new Resource[0];
//        }
//    }
//
//    @Bean(name = "db1TransactionManager")
//    @Primary
//    public DataSourceTransactionManager testTransactionManager(@Qualifier("db1DataSource") DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
//}
