From 80ad0e7aeda408ced18f203921e8ad2edf57975e Mon Sep 17 00:00:00 2001 From: zjh <1084500556@qq.com> Date: 星期五, 07 二月 2025 14:53:42 +0800 Subject: [PATCH] zjh20250207 --- ltkj-hosp/src/main/java/com/ltkj/db/DataSourceConfig.java | 20 ++++++++++++++++++-- ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java | 23 ++++++++++++++--------- ltkj-framework/src/main/java/com/ltkj/framework/config/WebConfig.java | 16 +++++++++++++++- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/ltkj-framework/src/main/java/com/ltkj/framework/config/WebConfig.java b/ltkj-framework/src/main/java/com/ltkj/framework/config/WebConfig.java index cefe709..1d73d60 100644 --- a/ltkj-framework/src/main/java/com/ltkj/framework/config/WebConfig.java +++ b/ltkj-framework/src/main/java/com/ltkj/framework/config/WebConfig.java @@ -1,8 +1,10 @@ package com.ltkj.framework.config; +//import com.ltkj.framework.interceptor.DBChangeInterceptor; import com.ltkj.framework.interceptor.DBChangeInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -32,6 +34,18 @@ }); registry.addInterceptor(dbChangeInterceptor) - .addPathPatterns("/**"); + .addPathPatterns("/**") + .excludePathPatterns(new String[]{ + "/system/dict/data/**", + "/system/dict/type/**", + "/captchaImage" +// , +// "/login", "/register", "/captchaImage","/cus/**","/getCaptchaConfigKey","/report/jmreport/**", +// "/sqlserver/getdata/**","/api/His/**","/system/config/zx","/system/config/gxxmpym","/system/report/savePdf", +// "/system/dyjl/saveGjddyjl","/system/dyjl/saveBlGjddyjl","/check/ceshi","/check/pacs","/check/ceshicc", +// "/common/uploadImgExe","/common/listExeVal","/pacs/InvokeRisService/**","/check/dataSynchronizationApi", +// String.valueOf(HttpMethod.GET), "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**", +// "/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**","/jmreport/**","/lis/**","/pacs/**","/callBack/**" + }); } } diff --git a/ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java b/ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java index 006b157..fc7c7f0 100644 --- a/ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java +++ b/ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java @@ -40,17 +40,22 @@ response.getWriter().write("{\"message\":\"401锛氭壘涓嶅埌闄㈠尯缂栧彿\"}"); return false; } - DataSourceContextHolder.setDataSourceKey("default"); - LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>(); - wrapper.eq(DictHosp::getCode,hospId); - DictHosp hosp = dictHospService.getOne(wrapper); - if (hosp == null || hosp.getDatabase() == null || hosp.getDatabase().trim().isEmpty()) { - response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); - response.setContentType("application/json;charset=UTF-8"); - response.getWriter().write("{\"message\":\"401锛氭壘涓嶅埌闄㈠尯鏁版嵁\"}"); + DictHosp hosp = null; + try { + DataSourceContextHolder.setDataSourceKey("default"); + LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(DictHosp::getCode,hospId); + hosp = dictHospService.getOne(wrapper); + if (hosp == null || hosp.getDatabase() == null || hosp.getDatabase().trim().isEmpty()) { + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().write("{\"message\":\"401锛氭壘涓嶅埌闄㈠尯鏁版嵁\"}"); + return false; + } + dataSourceConfig.addDataSource(hosp.getDatabase()); + } catch (IOException e) { return false; } - dataSourceConfig.addDataSource(hosp.getDatabase()); DataSourceContextHolder.setDataSourceKey(hosp.getDatabase()); return true; } diff --git a/ltkj-hosp/src/main/java/com/ltkj/db/DataSourceConfig.java b/ltkj-hosp/src/main/java/com/ltkj/db/DataSourceConfig.java index 6656298..f57d7d6 100644 --- a/ltkj-hosp/src/main/java/com/ltkj/db/DataSourceConfig.java +++ b/ltkj-hosp/src/main/java/com/ltkj/db/DataSourceConfig.java @@ -41,12 +41,28 @@ // @Value("${dbUrl}") private String dbUrl; + private String dbName; + @Bean(name = "hospDynamicDataSources") public DataSource hospDynamicDataSources() { HospDynamicDataSource dynamicDataSource = new HospDynamicDataSource(); - + FileInputStream fis = null; + Properties props = new Properties(); + try { + fis = new FileInputStream(url); + props.load(fis); + fis.close(); + dbUrl = props.getProperty("ip"); + dbName = props.getProperty("name"); + primaryPassword = props.getProperty("password"); + primaryPort = props.getProperty("prot"); + primaryUsername = props.getProperty("username"); + } catch (IOException e) { + throw new RuntimeException("璇诲彇閰嶇疆鏂囦欢澶辫触", e); + } + String url = "jdbc:mysql://" + dbUrl + ":" + primaryPort + "/" + dbName; // 鍒濆鍖栭粯璁ゆ暟鎹簮涓轰富搴� - dynamicDataSource.addTargetDataSource(DEFAULT_DATA_SOURCE_KEY, createDataSource(primaryUrl, primaryUsername, primaryPassword)); + dynamicDataSource.addTargetDataSource(DEFAULT_DATA_SOURCE_KEY, createDataSource(url, primaryUsername, primaryPassword)); dynamicDataSource.setDefaultTargetDataSource(dynamicDataSource.getTargetDataSources().get(DEFAULT_DATA_SOURCE_KEY)); // 璁剧疆榛樿鏁版嵁婧� return dynamicDataSource; -- Gitblit v1.8.0