package com.ywt.config.jpa;

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.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * Created by huangguoping.
 */
@Configuration
public class Datasources {
    /**
     * glasses 数据库的配置
     */
    @Bean(name = "glassesDataSource")
    @Qualifier("glassesDataSource")
    @ConfigurationProperties(prefix="spring.datasource.glasses")
    @Primary
    public DataSource glassesDataSource(){
        return DataSourceBuilder.create().build();
    }


    /**
     * ywt_center 数据库的配置
     */
    @Bean(name = "ywtCenterDataSource")
    @Qualifier("ywtCenterDataSource")
    @ConfigurationProperties(prefix="spring.datasource.ywtcenter")
    public DataSource ywtCenterDataSource(){
        return DataSourceBuilder.create().build();
    }


    /**
     * 注入 glasses 数据库
     * @param dataSource
     * @return
     */
    @Bean(name = "glassesJdbcTemplate")
    public JdbcTemplate glassesJdbcTemplate(@Qualifier("glassesDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    /**
     * 注入 ywt_center 数据库
     * @param dataSource
     * @return
     */
    @Bean(name = "ywtCenterJdbcTemplate")
    public JdbcTemplate ywtCenterJdbcTemplate(@Qualifier("ywtCenterDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }


}
