| | |
| | | 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; |
| | | |
| | |
| | | }); |
| | | |
| | | 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/**" |
| | | }); |
| | | } |
| | | } |
| | |
| | | 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"); |
| | |
| | | return false; |
| | | } |
| | | dataSourceConfig.addDataSource(hosp.getDatabase()); |
| | | } catch (IOException e) { |
| | | return false; |
| | | } |
| | | DataSourceContextHolder.setDataSourceKey(hosp.getDatabase()); |
| | | return true; |
| | | } |
| | |
| | | // @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; |