zjh
2025-02-07 80ad0e7aeda408ced18f203921e8ad2edf57975e
zjh20250207
3个文件已修改
43 ■■■■■ 已修改文件
ltkj-framework/src/main/java/com/ltkj/framework/config/WebConfig.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ltkj-hosp/src/main/java/com/ltkj/db/DataSourceConfig.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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/**"
                });
    }
}
ltkj-framework/src/main/java/com/ltkj/framework/interceptor/DBChangeInterceptor.java
@@ -40,10 +40,12 @@
            response.getWriter().write("{\"message\":\"401:找不到院区编号\"}");
            return false;
        }
        DictHosp hosp = null;
        try {
        DataSourceContextHolder.setDataSourceKey("default");
        LambdaQueryWrapper<DictHosp> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DictHosp::getCode,hospId);
        DictHosp hosp = dictHospService.getOne(wrapper);
            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");
@@ -51,6 +53,9 @@
            return false;
        }
        dataSourceConfig.addDataSource(hosp.getDatabase());
        } catch (IOException e) {
            return false;
        }
        DataSourceContextHolder.setDataSourceKey(hosp.getDatabase());
        return true;
    }
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;