This commit is contained in:
2026-06-17 15:41:13 +08:00
5 changed files with 36 additions and 15 deletions

View File

@@ -1093,10 +1093,14 @@ jeecgboot-vue3/src/views/xslmes/mesXslEquipDowntimeRecord/MesXslEquipDowntimeRec
jeecgboot-vue3/src/views/xslmes/mesXslEquipDowntimeRecord/MesXslEquipDowntimeRecordList.vue jeecgboot-vue3/src/views/xslmes/mesXslEquipDowntimeRecord/MesXslEquipDowntimeRecordList.vue
jeecgboot-vue3/src/views/xslmes/mesXslEquipDowntimeRecord/components/MesXslEquipDowntimeRecordModal.vue jeecgboot-vue3/src/views/xslmes/mesXslEquipDowntimeRecord/components/MesXslEquipDowntimeRecordModal.vue
-- author:GHT---date:20260616--for: 【MES上辅机】生产环境 SQL Server 中间库连接池校验 DUAL 报错修复 --- jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/datasource/McsDataSourceManager.java
原因application-prod.yml 全局 druid.validationQuery 为 SELECT 1 FROM DUAL动态创建的 sqlserver_mcs 数据源继承该配置后在 SQL Server 上报「对象名 DUAL 无效」。
修改prod 全局改为 SELECT 1McsDataSourceManager 创建/恢复 SQL Server 数据源时显式设置 validationQuery=SELECT 1。 -- author:GHT---date:20260616--for: 【MES上辅机】重启后中间库配置未自动加载租户ID硬编码为0---
jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml 原因McsDataSourceInitializer 启动时只查 tenant_id=0页面保存用当前租户如1002重启后查不到配置连接状态回退为 yml
修改:新增 loadStartupConfig 按最近更新时间加载任意租户配置isDbConfigActive 同时校验数据源是否已注册。
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/IMesXslMcsDbConfigService.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/service/impl/MesXslMcsDbConfigServiceImpl.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/config/McsDataSourceInitializer.java
jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/datasource/McsDataSourceManager.java jeecg-boot/jeecg-boot-module/jeecg-module-xslmes/src/main/java/org/jeecg/modules/xslmes/mcs/datasource/McsDataSourceManager.java
-- author:jiangxh---date:20260617--for: 【快检实验标准】补齐 tenant_id 为空的历史数据并恢复租户过滤 --- -- author:jiangxh---date:20260617--for: 【快检实验标准】补齐 tenant_id 为空的历史数据并恢复租户过滤 ---

View File

@@ -28,20 +28,16 @@ public class McsDataSourceInitializer implements ApplicationRunner {
@Override @Override
public void run(ApplicationArguments args) { public void run(ApplicationArguments args) {
try { try {
MesXslMcsDbConfig config = mcsDbConfigService.getOne( MesXslMcsDbConfig config = mcsDbConfigService.loadStartupConfig();
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MesXslMcsDbConfig>()
.eq(MesXslMcsDbConfig::getTenantId, 0)
.orderByDesc(MesXslMcsDbConfig::getUpdateTime)
.last("LIMIT 1"),
false);
if (config != null) { if (config != null) {
mcsDataSourceManager.applyConfig(config); mcsDataSourceManager.applyConfig(config);
log.info("[MCS中间库] 已加载数据库中的中间库配置(含读写开关)"); log.info("[MCS中间库] 已加载数据库中的中间库配置 tenantId={}, status={}, host={}:{}",
config.getTenantId(), config.getStatus(), config.getServerHost(), config.getServerPort());
} else { } else {
log.info("[MCS中间库] 未找到已启用的数据库配置,继续使用 application.yml 中的 sqlserver_mcs"); log.info("[MCS中间库] 数据库中无中间库配置,继续使用 application.yml 中的 sqlserver_mcs");
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("[MCS中间库] 启动加载配置失败,将使用 yml 默认连接: {}", e.getMessage()); log.error("[MCS中间库] 启动加载配置失败,将使用 yml 默认连接", e);
} }
} }
//update-end---author:GHT ---date:20260616 for【MES上辅机】启动时加载中间库可视化配置----------- //update-end---author:GHT ---date:20260616 for【MES上辅机】启动时加载中间库可视化配置-----------

View File

@@ -59,7 +59,11 @@ public class McsDataSourceManager {
public boolean isDbConfigActive() { public boolean isDbConfigActive() {
MesXslMcsDbConfig cfg = cachedConfig.get(); MesXslMcsDbConfig cfg = cachedConfig.get();
return cfg != null && Integer.valueOf(1).equals(cfg.getStatus()); if (cfg == null || !Integer.valueOf(1).equals(cfg.getStatus())) {
return false;
}
DynamicRoutingDataSource routing = (DynamicRoutingDataSource) dataSource;
return routing.getDataSources().containsKey(DS_KEY);
} }
public boolean isReadEnabled() { public boolean isReadEnabled() {
@@ -83,11 +87,11 @@ public class McsDataSourceManager {
* 将配置应用到动态数据源(启用时注册/更新,禁用时移除) * 将配置应用到动态数据源(启用时注册/更新,禁用时移除)
*/ */
public void applyConfig(MesXslMcsDbConfig config) { public void applyConfig(MesXslMcsDbConfig config) {
cachedConfig.set(config);
DynamicRoutingDataSource routing = (DynamicRoutingDataSource) dataSource; DynamicRoutingDataSource routing = (DynamicRoutingDataSource) dataSource;
closeAndRemoveDataSource(routing); closeAndRemoveDataSource(routing);
DataSourceCachePool.removeCache(DS_KEY); DataSourceCachePool.removeCache(DS_KEY);
if (config == null) { if (config == null) {
cachedConfig.set(null);
restoreYmlDataSource(routing); restoreYmlDataSource(routing);
log.info("[MCS中间库] 已清除页面配置"); log.info("[MCS中间库] 已清除页面配置");
return; return;
@@ -98,6 +102,7 @@ public class McsDataSourceManager {
DataSourceProperty property = buildDataSourceProperty(config, plainPassword); DataSourceProperty property = buildDataSourceProperty(config, plainPassword);
DataSource mcsDs = dataSourceCreator.createDataSource(property); DataSource mcsDs = dataSourceCreator.createDataSource(property);
routing.addDataSource(DS_KEY, mcsDs); routing.addDataSource(DS_KEY, mcsDs);
cachedConfig.set(config);
log.info("[MCS中间库] 动态数据源 {} 已热刷新(无需重启): {}:{}/{}", DS_KEY, log.info("[MCS中间库] 动态数据源 {} 已热刷新(无需重启): {}:{}/{}", DS_KEY,
config.getServerHost(), config.getServerPort(), config.getDbName()); config.getServerHost(), config.getServerPort(), config.getDbName());
} catch (Exception e) { } catch (Exception e) {
@@ -107,6 +112,7 @@ public class McsDataSourceManager {
} }
return; return;
} }
cachedConfig.set(config);
restoreYmlDataSource(routing); restoreYmlDataSource(routing);
log.info("[MCS中间库] 连接未启用,读写开关仍按页面配置生效"); log.info("[MCS中间库] 连接未启用,读写开关仍按页面配置生效");
} }

View File

@@ -28,4 +28,9 @@ public interface IMesXslMcsDbConfigService extends IService<MesXslMcsDbConfig> {
* 删除配置并移除动态数据源 * 删除配置并移除动态数据源
*/ */
Result<String> deleteConfig(String id); Result<String> deleteConfig(String id);
/**
* 启动时加载中间库配置(不限定租户,取最近更新的一条)
*/
MesXslMcsDbConfig loadStartupConfig();
} }

View File

@@ -44,6 +44,16 @@ public class MesXslMcsDbConfigServiceImpl extends ServiceImpl<MesXslMcsDbConfigM
return config; return config;
} }
//update-begin---author:GHT ---date:20260616 for【MES上辅机】启动时加载中间库配置不限定租户-----------
@Override
public MesXslMcsDbConfig loadStartupConfig() {
LambdaQueryWrapper<MesXslMcsDbConfig> qw = new LambdaQueryWrapper<>();
qw.orderByDesc(MesXslMcsDbConfig::getUpdateTime);
qw.last("LIMIT 1");
return getOne(qw, false);
}
//update-end---author:GHT ---date:20260616 for【MES上辅机】启动时加载中间库配置不限定租户-----------
//update-begin---author:GHT ---date:20260616 for【MES上辅机】SQL Server中间库可视化配置----------- //update-begin---author:GHT ---date:20260616 for【MES上辅机】SQL Server中间库可视化配置-----------
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)