//package com.mortals.xhx.config;
//
//import com.alibaba.druid.filter.config.ConfigTools;
//import com.alibaba.druid.pool.DruidDataSource;
//import lombok.Data;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Value;
//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;
//import java.sql.SQLException;
//import java.util.Properties;
//
//
//@Configuration
//@Data
//public class DruidDatsSourceConfig {
//
//    private Logger logger = LoggerFactory.getLogger(DruidDatsSourceConfig.class);
//
//    @Value("${spring.datasource.url}")
//    private String url;
//
//    @Value("${spring.datasource.driver-class-name}")
//    private String driverClassName;
//
//    @Value("${spring.datasource.username}")
//    private String username;
//
//    @Value("${spring.datasource.password}")
//    private String password;
//
//    @Value("${spring.datasource.type}")
//    private String type;
//
////    @Value("${spring.datasource.publicKey}")
////    private String publicKey;
//
//    @Value("${spring.datasource.druid.initial-size}")
//    private Integer initialSize;
//
//    @Value("${spring.datasource.druid.min-idle}")
//    private Integer minIdle;
//
//    @Value("${spring.datasource.druid.max-active}")
//    private Integer maxActive;
//
//    @Value("${spring.datasource.druid.max-wait}")
//    private Integer maxWait;
//
//    @Value("${spring.datasource.druid.time-between-eviction-runs-millis}")
//    private Integer timeBetweenEvictionRunsMillis;
//
//    @Value("${spring.datasource.druid.min-evictable-idle-time-millis}")
//    private Integer minEvictableIdleTimeMillis;
//
//    @Value("${spring.datasource.druid.validation-query}")
//    private String validationQuery;
//
//    @Value("${spring.datasource.druid.test-while-idle}")
//    private Boolean testWhileIdle;
//
//    @Value("${spring.datasource.druid.test-on-borrow}")
//    private Boolean testOnBorrow;
//
//    @Value("${spring.datasource.druid.test-on-return}")
//    private Boolean testOnReturn;
//
//    @Value("${spring.datasource.druid.pool-prepared-statements}")
//    private Boolean poolPreparedStatements;
//
//    @Value("${spring.datasource.druid.max-pool-prepared-statement-per-connection-size}")
//    private Integer maxPoolPreparedStatementPerConnectionSize;
//
//    @Value("${spring.datasource.druid.filters}")
//    private String filters;
//
//    @Value("${spring.datasource.druid.use-global-data-source-stat}")
//    private Boolean useGlobalDataSourceStat;
//
//    @Value("${spring.datasource.druid.connect-properties}")
//    private Properties connectProperties;
//
//    @Bean
//    @Primary
//    public DataSource druidDataSource() throws Exception {
//        DruidDataSource datasource = new DruidDataSource();
//        datasource.setUrl(url);
//        datasource.setDriverClassName(driverClassName);
//        datasource.setUsername(username);
//        datasource.setPassword(password);
//       // logger.info("密码：" + ConfigTools.decrypt(publicKey, password));
//        datasource.setInitialSize(initialSize);
//        datasource.setMinIdle(minIdle);
//        datasource.setMaxActive(maxActive);
//        datasource.setMaxWait(maxWait);
//        datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
//        datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
//        datasource.setValidationQuery(validationQuery);
//        datasource.setTestWhileIdle(testWhileIdle);
//        datasource.setTestOnBorrow(testOnBorrow);
//        datasource.setTestOnReturn(testOnReturn);
//        datasource.setUseGlobalDataSourceStat(useGlobalDataSourceStat);
//        datasource.setConnectProperties(connectProperties);
//
//        try {
//            datasource.setFilters(filters);
//        } catch (SQLException e) {
//            logger.error("========druid configuration initialization filter========", e);
//        }
//        return datasource;
//    }
//
//
//    public static void main(String[] args) throws Exception {
//        String password = "xxxx";
//        String[] arr = ConfigTools.genKeyPair(512);
//        System.out.println("password:" + password);
//        System.out.println("privateKey:" + arr[0]);
//        System.out.println("publicKey:" + arr[1]);
//        System.out.println("password:" + ConfigTools.encrypt(arr[0], password));
//    }
//}
