| | |
| | | } |
| | | |
| | | |
| | | @Bean |
| | | // @ConfigurationProperties("spring.datasource.druid.slavepacs") |
| | | // @ConditionalOnProperty(prefix = "spring.datasource.druid.slavepacs", name = "enabled", havingValue = "true") |
| | | public DataSource slaveDataWsSource(DruidProperties druidProperties) { |
| | | DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); |
| | | Properties props = new Properties(); |
| | | try { |
| | | // 从文件中读取配置信息 |
| | | FileInputStream fis = null; |
| | | try { |
| | | fis = new FileInputStream(url); |
| | | } catch (FileNotFoundException e) { |
| | | log.info("数据库连接文件找不到"); |
| | | } |
| | | props.load(fis); |
| | | fis.close(); |
| | | // 这里是测试写法,具体的value可以通过请求参数传递过来 |
| | | String pacsenabled = props.getProperty("pacsenabled"); |
| | | if (pacsenabled.equals("false")) |
| | | return null; |
| | | String pacsdbtype = props.getProperty("wsdbtype"); |
| | | switch (pacsdbtype){ |
| | | case "sqlserver": |
| | | dataSource = creatSqlServer(pacsenabled, props.getProperty("wsip"),props.getProperty("wsprot"), |
| | | props.getProperty("wsname"),props.getProperty("wsusername"),props.getProperty("wspassword")); |
| | | break; |
| | | case "mysql": |
| | | dataSource = creatMysql(pacsenabled, props.getProperty("wsip"), |
| | | props.getProperty("wsprot"),props.getProperty("wsname"),props.getProperty("wsusername"),props.getProperty("wspassword")); |
| | | break; |
| | | case "oracle": |
| | | dataSource = creatOracle(pacsenabled, props.getProperty("wsip"), |
| | | props.getProperty("wsprot"),props.getProperty("wsname"),props.getProperty("wsusername"),props.getProperty("wspassword")); |
| | | break; |
| | | default: |
| | | dataSource = creatOracle(pacsenabled, props.getProperty("wsip"),props.getProperty("wsprot"),props.getProperty("wsname"),props.getProperty("wsusername") |
| | | ,props.getProperty("wspassword")); |
| | | break; |
| | | } |
| | | log.info("数据库连接成功!!!"); |
| | | } catch (Exception e) { |
| | | log.info("数据库连接失败 请联系管理员!"); |
| | | e.printStackTrace(); |
| | | } |
| | | return druidProperties.dataSource(dataSource); |
| | | } |
| | | |
| | | |
| | | private DruidDataSource creatSqlServer(String enabled, String ip,String port,String db,String user,String password) throws SQLException { |
| | | DruidDataSource dataSource = DruidDataSourceBuilder.create().build(); |
| | | Properties properties = new Properties(); |
| | | properties.setProperty("druid.enabled", enabled); |
| | | properties.setProperty("druid.driverClassName","com.microsoft.sqlserver.jdbc.SQLServerDriver"); |
| | | properties.setProperty("druid.url","jdbc:sqlserver://"+ ip+":"+ port+";DatabaseName="+ db+ |
| | | ";&characterEncoding=utf8"); |
| | | ";encrypt=true;trustServerCertificate=true;sslProtocol=TLSv1.2;"); |
| | | properties.setProperty("druid.username", user); |
| | | properties.setProperty("druid.password", password); |
| | | dataSource.restart(properties); |
| | |
| | | setDataSource(targetDataSources, DataSourceType.SLAVE_HIS.name(), "slaveHisDataSource"); |
| | | setDataSource(targetDataSources, DataSourceType.SLAVE_LIS.name(), "slaveDataLisSource"); |
| | | setDataSource(targetDataSources, DataSourceType.SLAVE_PACS.name(), "slaveDataPacsSource"); |
| | | setDataSource(targetDataSources, DataSourceType.SLAVE_WS.name(), "slaveDataWsSource"); |
| | | return new DynamicDataSource(masterDataSource, targetDataSources); |
| | | } |
| | | |