天海优化数据库名
This commit is contained in:
@@ -11,12 +11,12 @@ public enum DataSourceEnum {
|
|||||||
/**
|
/**
|
||||||
* 主数据源
|
* 主数据源
|
||||||
*/
|
*/
|
||||||
WMS("wms"),
|
WMS_TH("wms_th"),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据源
|
* 从数据源
|
||||||
*/
|
*/
|
||||||
WMS2("wms2");
|
WMS_QL("wms_ql");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public abstract class AbstractLoginHandler<T extends LoginReq> implements LoginH
|
|||||||
// 设置数据源(如果用户未配置,则使用默认主库)
|
// 设置数据源(如果用户未配置,则使用默认主库)
|
||||||
String dataSource = user.getDataSource();
|
String dataSource = user.getDataSource();
|
||||||
if (dataSource == null || dataSource.isEmpty()) {
|
if (dataSource == null || dataSource.isEmpty()) {
|
||||||
dataSource = "wms"; // 默认主库
|
dataSource = "wms_th"; // 默认主库
|
||||||
}
|
}
|
||||||
userContext.setDataSource(dataSource);
|
userContext.setDataSource(dataSource);
|
||||||
DataSourceContextHolder.setDataSource(dataSource);
|
DataSourceContextHolder.setDataSource(dataSource);
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ public class UserDO extends BaseDO {
|
|||||||
private Long equipmentId;
|
private Long equipmentId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据源标识(wms/wms2)
|
* 数据源标识(wms/wms_ql)
|
||||||
*/
|
*/
|
||||||
private String dataSource;
|
private String dataSource;
|
||||||
}
|
}
|
||||||
@@ -23,23 +23,23 @@ import java.util.Map;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class DynamicDataSourceConfig {
|
public class DynamicDataSourceConfig {
|
||||||
|
|
||||||
@Value("${spring.datasource.wms.url}")
|
@Value("${spring.datasource.wms_th.url}")
|
||||||
private String wmsUrl;
|
private String wmsUrl;
|
||||||
|
|
||||||
@Value("${spring.datasource.wms.username}")
|
@Value("${spring.datasource.wms_th.username}")
|
||||||
private String wmsUsername;
|
private String wmsUsername;
|
||||||
|
|
||||||
@Value("${spring.datasource.wms.password}")
|
@Value("${spring.datasource.wms_th.password}")
|
||||||
private String wmsPassword;
|
private String wmsPassword;
|
||||||
|
|
||||||
@Value("${spring.datasource.wms2.url}")
|
@Value("${spring.datasource.wms_ql.url}")
|
||||||
private String wms2Url;
|
private String wms_qlUrl;
|
||||||
|
|
||||||
@Value("${spring.datasource.wms2.username}")
|
@Value("${spring.datasource.wms_ql.username}")
|
||||||
private String wms2Username;
|
private String wms_qlUsername;
|
||||||
|
|
||||||
@Value("${spring.datasource.wms2.password}")
|
@Value("${spring.datasource.wms_ql.password}")
|
||||||
private String wms2Password;
|
private String wms_qlPassword;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主数据源(wms)
|
* 主数据源(wms)
|
||||||
@@ -60,15 +60,15 @@ public class DynamicDataSourceConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从数据源(wms2)
|
* 从数据源(wms_ql)
|
||||||
*/
|
*/
|
||||||
@Bean("wms2DataSource")
|
@Bean("wms_qlDataSource")
|
||||||
public DataSource wms2DataSource() {
|
public DataSource wms_qlDataSource() {
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig config = new HikariConfig();
|
||||||
config.setDriverClassName("com.p6spy.engine.spy.P6SpyDriver");
|
config.setDriverClassName("com.p6spy.engine.spy.P6SpyDriver");
|
||||||
config.setJdbcUrl(wms2Url);
|
config.setJdbcUrl(wms_qlUrl);
|
||||||
config.setUsername(wms2Username);
|
config.setUsername(wms_qlUsername);
|
||||||
config.setPassword(wms2Password);
|
config.setPassword(wms_qlPassword);
|
||||||
config.setMaximumPoolSize(20);
|
config.setMaximumPoolSize(20);
|
||||||
config.setConnectionTimeout(30000);
|
config.setConnectionTimeout(30000);
|
||||||
config.setIdleTimeout(600000);
|
config.setIdleTimeout(600000);
|
||||||
@@ -82,7 +82,7 @@ public class DynamicDataSourceConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean("dynamicDataSource")
|
@Bean("dynamicDataSource")
|
||||||
@Primary
|
@Primary
|
||||||
public DataSource dynamicDataSource(DataSource wmsDataSource, DataSource wms2DataSource) {
|
public DataSource dynamicDataSource(DataSource wmsDataSource, DataSource wms_qlDataSource) {
|
||||||
DynamicRoutingDataSource dynamicRoutingDataSource = new DynamicRoutingDataSource();
|
DynamicRoutingDataSource dynamicRoutingDataSource = new DynamicRoutingDataSource();
|
||||||
|
|
||||||
// 设置默认数据源
|
// 设置默认数据源
|
||||||
@@ -90,8 +90,8 @@ public class DynamicDataSourceConfig {
|
|||||||
|
|
||||||
// 设置数据源映射
|
// 设置数据源映射
|
||||||
Map<Object, Object> dataSourceMap = new HashMap<>();
|
Map<Object, Object> dataSourceMap = new HashMap<>();
|
||||||
dataSourceMap.put("wms", wmsDataSource);
|
dataSourceMap.put("wms_th", wmsDataSource);
|
||||||
dataSourceMap.put("wms2", wms2DataSource);
|
dataSourceMap.put("wms_ql", wms_qlDataSource);
|
||||||
dynamicRoutingDataSource.setTargetDataSources(dataSourceMap);
|
dynamicRoutingDataSource.setTargetDataSources(dataSourceMap);
|
||||||
|
|
||||||
// 必须调用此方法,否则首次获取数据源时会失败
|
// 必须调用此方法,否则首次获取数据源时会失败
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class DynamicDataSourceInterceptor implements HandlerInterceptor {
|
|||||||
// 认证相关接口始终使用主库(wms),确保用户验证和权限获取在主库进行
|
// 认证相关接口始终使用主库(wms),确保用户验证和权限获取在主库进行
|
||||||
if (requestUri.contains("/auth/login") || requestUri.contains("/auth/user/info") || requestUri
|
if (requestUri.contains("/auth/login") || requestUri.contains("/auth/user/info") || requestUri
|
||||||
.contains("/auth/user/route") || requestUri.contains("/auth/logout")) {
|
.contains("/auth/user/route") || requestUri.contains("/auth/logout")) {
|
||||||
DataSourceContextHolder.setDataSource("wms");
|
DataSourceContextHolder.setDataSource("wms_th");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
--- ### 项目配置
|
--- ### 项目配置
|
||||||
project:
|
project:
|
||||||
# URL(跨域配置默认放行此 URL,第三方登录回调默认使用此 URL 为前缀,请注意更改为你实际的前端 URL)
|
# URL(跨域配置默认放行此 URL,第三方登录回调默认使用此 URL 为前缀,请注意更改为你实际的前端 URL)
|
||||||
url: http://localhost:6609
|
url: http://localhost:80
|
||||||
|
|
||||||
--- ### 服务器配置
|
--- ### 服务器配置
|
||||||
server:
|
server:
|
||||||
@@ -16,14 +16,14 @@ spring:
|
|||||||
|
|
||||||
--- ### 数据源配置
|
--- ### 数据源配置
|
||||||
spring.datasource:
|
spring.datasource:
|
||||||
# 主数据源(wms)
|
# 主数据源(wms_th)
|
||||||
wms:
|
wms_th:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms_th?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
username: root
|
username: root
|
||||||
# password: root
|
# password: root
|
||||||
password: test123$
|
password: SQLth7410!DD
|
||||||
# Hikari 连接池配置
|
# Hikari 连接池配置
|
||||||
hikari:
|
hikari:
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
@@ -31,14 +31,14 @@ spring.datasource:
|
|||||||
idle-timeout: 600000
|
idle-timeout: 600000
|
||||||
keepaliveTime: 30000
|
keepaliveTime: 30000
|
||||||
max-lifetime: 1800000
|
max-lifetime: 1800000
|
||||||
# 从数据源(wms2)
|
# 从数据源(wms_ql)
|
||||||
wms2:
|
wms_ql:
|
||||||
type: com.zaxxer.hikari.HikariDataSource
|
type: com.zaxxer.hikari.HikariDataSource
|
||||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||||
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms2?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
url: jdbc:p6spy:mysql://127.0.0.1:3306/wms_ql?serverTimezone=Asia/Shanghai&useSSL=false&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&autoReconnect=true&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
|
||||||
username: root
|
username: root
|
||||||
# password: root
|
# password: root
|
||||||
password: test123$
|
password: SQLth7410!DD
|
||||||
# Hikari 连接池配置
|
# Hikari 连接池配置
|
||||||
hikari:
|
hikari:
|
||||||
maximum-pool-size: 20
|
maximum-pool-size: 20
|
||||||
@@ -63,7 +63,7 @@ spring.data:
|
|||||||
# 端口(默认 6379)
|
# 端口(默认 6379)
|
||||||
port: ${REDIS_PORT:6379}
|
port: ${REDIS_PORT:6379}
|
||||||
# 密码(未设置密码时请注释掉)
|
# 密码(未设置密码时请注释掉)
|
||||||
# password: ${REDIS_PWD:redis2025}
|
password: ${REDIS_PWD:food}
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: ${REDIS_DB:0}
|
database: ${REDIS_DB:0}
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
@@ -156,7 +156,10 @@ logging:
|
|||||||
continew-starter.web.cors:
|
continew-starter.web.cors:
|
||||||
enabled: true
|
enabled: true
|
||||||
# 配置允许跨域的域名
|
# 配置允许跨域的域名
|
||||||
allowed-origins: '*'
|
allowed-origins:
|
||||||
|
- ${project.url}
|
||||||
|
- http://127.0.0.1:80
|
||||||
|
- http://:80
|
||||||
# 配置允许跨域的请求方式
|
# 配置允许跨域的请求方式
|
||||||
allowed-methods: '*'
|
allowed-methods: '*'
|
||||||
# 配置允许跨域的请求头
|
# 配置允许跨域的请求头
|
||||||
|
|||||||
Reference in New Issue
Block a user