zjh
2023-12-12 c98ce463624a858503ae32e63ca128a8923c80cf
zjh 2023/12/12--2
2个文件已修改
159 ■■■■ 已修改文件
ltkj-admin/src/main/resources/application-druid.yml 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java 129 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-admin/src/main/resources/application-druid.yml
@@ -15,27 +15,27 @@
      # 从库数据源
      slavepacs:
        # 从数据源开关/默认关闭
        enabled: true
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
        url: jdbc:sqlserver://192.168.0.111:1433;DatabaseName=Testlg
        username: sa
        password: admin123
#        enabled: true
#        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
#        url: jdbc:sqlserver://192.168.0.111:1433;DatabaseName=Testlg
#        username: sa
#        password: admin123
      # 从库数据源
      slavehis:
        # 从数据源开关/默认关闭
        enabled: true
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
        url: jdbc:sqlserver://192.168.0.111:1433;DatabaseName=Testlg
        username: sa
        password: admin123
#        enabled: true
#        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
#        url: jdbc:sqlserver://192.168.0.111:1433;DatabaseName=Testlg
#        username: sa
#        password: admin123
      # 从库数据源
      slavelis:
        # 从数据源开关/默认关闭
        enabled: true
        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
        url: jdbc:sqlserver://192.168.0.111:1433;DatabaseName=Testlg
        username: sa
        password: admin123
#        enabled: true
#        driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
#        url: jdbc:sqlserver://192.168.0.111:1433;DatabaseName=Testlg
#        username: sa
#        password: admin123
      # 初始连接数
      initialSize: 5
      # 最小连接池数量
ltkj-framework/src/main/java/com/ltkj/framework/config/DruidConfig.java
@@ -59,11 +59,41 @@
                File file = new File("D:\\ltkjprojectconf\\config.properties");
                try {
                        FileWriter fileWriter = new FileWriter(file);
                        fileWriter.write("ip = 你的数据库连接ip地址\n");
                        fileWriter.write("prot = 你的数据库连接端口\n");
                        fileWriter.write("name = 你的数据库连接名称\n");
                        fileWriter.write("username = 你的数据库连接用户名\n");
                        fileWriter.write("password = 你的数据库连接密码\n");
                    fileWriter.write("ip = 你的主数据库连接ip地址\n");
                    fileWriter.write("prot = 你的主数据库连接端口\n");
                    fileWriter.write("name = 你的主数据库连接名称\n");
                    fileWriter.write("username = 你的主数据库连接用户名\n");
                    fileWriter.write("password = 你的主数据库连接密码\n");
                    fileWriter.write("\n");
                    fileWriter.write("hisenabled = 是否开启 his 从库数据库连接 (从数据源开关/默认关闭 fales)\n");
                    fileWriter.write("hisip = 你的 his 数据库连接ip地址\n");
                    fileWriter.write("hisprot = 你的 his 数据库连接端口\n");
                    fileWriter.write("hisname = 你的 his 数据库连接名称\n");
                    fileWriter.write("hisusername = 你的 his 数据库连接用户名\n");
                    fileWriter.write("hispassword = 你的 his 数据库连接密码\n");
                    fileWriter.write("\n");
                    fileWriter.write("pacsenabled = 是否开启pacs从库数据库连接 (从数据源开关/默认关闭 fales)\n");
                    fileWriter.write("pacsip = 你的pacs数据库连接ip地址\n");
                    fileWriter.write("pacsprot = 你的pacs数据库连接端口\n");
                    fileWriter.write("pacsname = 你的pacs数据库连接名称\n");
                    fileWriter.write("pacsusername = 你的pacs数据库连接用户名\n");
                    fileWriter.write("pacspassword = 你的pacs数据库连接密码\n");
                    fileWriter.write("\n");
                    fileWriter.write("lisenabled = 是否开启 lis 从库数据库连接 (从数据源开关/默认关闭 fales)\n");
                    fileWriter.write("lisip = 你的 lis 数据库连接ip地址\n");
                    fileWriter.write("lisprot = 你的 lis 数据库连接端口\n");
                    fileWriter.write("lisname = 你的 lis 数据库连接名称\n");
                    fileWriter.write("lisusername = 你的 lis 数据库连接用户名\n");
                    fileWriter.write("lispassword = 你的 lis 数据库连接密码\n");
                        fileWriter.close();
                        log.info("数据库连接文件创建成功!");
                } catch (IOException ioException) {
@@ -78,7 +108,7 @@
            Properties properties = new Properties();
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            properties.setProperty("druid.url","jdbc:mysql://"+props.getProperty("ip")+":"+props.getProperty("prot")+"/"+props.getProperty("name")+"" +
                    "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8");
                    "?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8");
            properties.setProperty("druid.username",props.getProperty("username"));
            properties.setProperty("druid.password",props.getProperty("password"));
            dataSource.restart(properties);
@@ -91,26 +121,101 @@
    }
    @Bean
    @ConfigurationProperties("spring.datasource.druid.slavehis")
    @ConditionalOnProperty(prefix = "spring.datasource.druid.slavehis", name = "enabled", havingValue = "true")
//    @ConfigurationProperties("spring.datasource.druid.slavehis")
//    @ConditionalOnProperty(prefix = "spring.datasource.druid.slavehis", name = "enabled", havingValue = "true")
    public DataSource slaveHisDataSource(DruidProperties druidProperties) {
        DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
        Properties props = new Properties();
        try {
            // 从文件中读取配置信息
            FileInputStream fis = null;
            try {
                fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties");
            } catch (FileNotFoundException e) {
                log.info("数据库连接文件找不到!");
            }
            props.load(fis);
            fis.close();
            // 获取属性值并赋值
            Properties properties = new Properties();
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            properties.setProperty("druid.enabled",props.getProperty("hisenabled"));
            properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver");
            properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("hisip")+":"+props.getProperty("hisprot")+";DatabaseName="+props.getProperty("hisname"));
            properties.setProperty("druid.username",props.getProperty("hisusername"));
            properties.setProperty("druid.password",props.getProperty("hispassword"));
            dataSource.restart(properties);
            log.info("数据库连接成功!!!");
        } catch (Exception e) {
            log.info("数据库连接失败  请联系管理员!");
            e.printStackTrace();
        }
        return druidProperties.dataSource(dataSource);
    }
    @Bean
    @ConfigurationProperties("spring.datasource.druid.slavelis")
    @ConditionalOnProperty(prefix = "spring.datasource.druid.slavelis", name = "enabled", havingValue = "true")
//    @ConfigurationProperties("spring.datasource.druid.slavelis")
//    @ConditionalOnProperty(prefix = "spring.datasource.druid.slavelis", name = "enabled", havingValue = "true")
    public DataSource slaveDataLisSource(DruidProperties druidProperties) {
        DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
        Properties props = new Properties();
        try {
            // 从文件中读取配置信息
            FileInputStream fis = null;
            try {
                fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties");
            } catch (FileNotFoundException e) {
                log.info("数据库连接文件找不到!");
            }
            props.load(fis);
            fis.close();
            // 获取属性值并赋值
            Properties properties = new Properties();
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            properties.setProperty("druid.enabled",props.getProperty("lisenabled"));
            properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver");
            properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("lisip")+":"+props.getProperty("lisprot")+";DatabaseName="+props.getProperty("lisname"));
            properties.setProperty("druid.username",props.getProperty("lisusername"));
            properties.setProperty("druid.password",props.getProperty("lispassword"));
            dataSource.restart(properties);
            log.info("数据库连接成功!!!");
        } catch (Exception e) {
            log.info("数据库连接失败  请联系管理员!");
            e.printStackTrace();
        }
        return druidProperties.dataSource(dataSource);
    }
    @Bean
    @ConfigurationProperties("spring.datasource.druid.slavepacs")
    @ConditionalOnProperty(prefix = "spring.datasource.druid.slavepacs", name = "enabled", havingValue = "true")
//    @ConfigurationProperties("spring.datasource.druid.slavepacs")
//    @ConditionalOnProperty(prefix = "spring.datasource.druid.slavepacs", name = "enabled", havingValue = "true")
    public DataSource slaveDataPacsSource(DruidProperties druidProperties) {
        DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
        Properties props = new Properties();
        try {
            // 从文件中读取配置信息
            FileInputStream fis = null;
            try {
                fis = new FileInputStream("D:\\ltkjprojectconf\\config.properties");
            } catch (FileNotFoundException e) {
                log.info("数据库连接文件找不到");
            }
            props.load(fis);
            fis.close();
            // 获取属性值并赋值
            Properties properties = new Properties();
            // 这里是测试写法,具体的value可以通过请求参数传递过来
            properties.setProperty("druid.enabled",props.getProperty("pacsenabled"));
            properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver");
            properties.setProperty("druid.url","jdbc:sqlserver://"+props.getProperty("pacsip")+":"+props.getProperty("pacsprot")+";DatabaseName="+props.getProperty("pacsname"));
            properties.setProperty("druid.username",props.getProperty("pacsusername"));
            properties.setProperty("druid.password",props.getProperty("pacspassword"));
            dataSource.restart(properties);
            log.info("数据库连接成功!!!");
        } catch (Exception e) {
            log.info("数据库连接失败  请联系管理员!");
            e.printStackTrace();
        }
        return druidProperties.dataSource(dataSource);
    }