package com.nantian.cloud.query.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @author suixin
 * @date 2022/2/19
 */
@Configuration
public class DataSourceConfig {
    /**
     * @Description: 主数据源配置
     * @Author: suixin
     * @Date: 2022/2/19
     * @Return: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
     * @Param: []
     */
    @Primary
    @Bean(name = "ds1DataSourceProperties")
    @ConfigurationProperties(prefix = "spring.datasource.druid.datasource1")
    public DataSourceProperties ds1DataSourceProperties() {
        return new DataSourceProperties();
    }

    /**
     * @Description: 第一数据源 energy_record
     * @Author: suixin
     * @Date: 2022/2/19
     * @Return: javax.sql.DataSource
     * @Param: [dataSourceProperties]
     */
    @Primary
    @Bean(name = "dataSource1")
    public DataSource ds1DataSource(@Qualifier("ds1DataSourceProperties") DataSourceProperties dataSourceProperties) {
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }


    /**
     * @Description: 第二数据源配置 jly_app
     * @Author: suixin
     * @Date: 2022/2/19
     * @Return: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
     * @Param: []
     */
    @Bean(name = "ds2DataSourceProperties")
    @ConfigurationProperties(prefix = "spring.datasource.druid.datasource2")
    public DataSourceProperties ds2DataSourceProperties() {
        return new DataSourceProperties();
    }
    /**
     * @Description: 第二数据源 jly_app
     * @Author: suixin
     * @Date: 2022/2/19
     * @Return: javax.sql.DataSource
     * @Param: [dataSourceProperties]
     */
    @Bean(name = "dataSource2")
    public DataSource ds2DataSource(@Qualifier("ds2DataSourceProperties") DataSourceProperties dataSourceProperties) {
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }

    /**
     * @Description: 第三数据源配置 jnjc
     * @Author: suixin
     * @Date: 2022/2/19
     * @Return: org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
     * @Param: []
     */
    @Bean(name = "ds3DataSourceProperties")
    @ConfigurationProperties(prefix = "spring.datasource.druid.datasource3")
    public DataSourceProperties ds3DataSourceProperties() {
        return new DataSourceProperties();
    }

    /**
     * @Description: 第三数据源 jnjc
     * @Author: suixin
     * @Date: 2022/2/19
     * @Return: javax.sql.DataSource
     * @Param: [dataSourceProperties]
     */
    @Bean(name = "dataSource3")
    public DataSource ds3DataSource(@Qualifier("ds3DataSourceProperties") DataSourceProperties dataSourceProperties) {
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }
}
