From 4f5dbb2288912f74500cdc902382a5d28d040d78 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 16 Jan 2023 16:35:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=88=97=E8=A1=A8=E5=8A=A0=E8=BD=BD=E9=80=9F?= =?UTF-8?q?=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/db/DatabaseTableServiceImpl.java | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java index 77ff2409f..55f56a5dc 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/db/DatabaseTableServiceImpl.java @@ -12,12 +12,9 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo; import com.baomidou.mybatisplus.generator.config.rules.DateType; import org.springframework.stereotype.Service; -import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; /** @@ -31,26 +28,6 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { @Resource private DataSourceConfigService dataSourceConfigService; - private final Map ConfigBuilderMap = new HashMap<>(); - - @PostConstruct - public void initConfigBuilderMap() { - for (DataSourceConfigDO config : dataSourceConfigService.getDataSourceConfigList()) { - // 使用 MyBatis Plus Generator 解析表结构 - DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), - config.getPassword()).build(); - StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); - // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 - strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); - - GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate - ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), - null, globalConfig, null); - - ConfigBuilderMap.put(config.getId(), builder); - } - } - @Override public List getTableList(Long dataSourceConfigId, String nameLike, String commentLike) { List tables = getTableList0(dataSourceConfigId, null); @@ -65,16 +42,28 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { } public List getTableList0(Long dataSourceConfigId, String name) { - ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId); - Assert.notNull(builder, "数据源({}) 不存在!", dataSourceConfigId); + // 获得数据源配置 + DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId); + Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId); + // 使用 MyBatis Plus Generator 解析表结构 + DataSourceConfig dataSourceConfig = new DataSourceConfig.Builder(config.getUrl(), config.getUsername(), + config.getPassword()).build(); + StrategyConfig.Builder strategyConfig = new StrategyConfig.Builder(); + if (StrUtil.isNotEmpty(name)) { + strategyConfig.addInclude(name); + }else{ + // 移除工作流和定时任务前缀的表名 // TODO 未来做成可配置 + strategyConfig.addExclude("ACT_[\\S\\s]+|QRTZ_[\\S\\s]+|FLW_[\\S\\s]+"); + } + + GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate + ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(), + null, globalConfig, null); // 按照名字排序 List tables = builder.getTableInfoList(); - if (StrUtil.isBlank(name)) { - tables.sort(Comparator.comparing(TableInfo::getName)); - return tables; - } else { - return CollUtil.filter(tables, tableInfo -> tableInfo.getName().equals(name)); - } + tables.sort(Comparator.comparing(TableInfo::getName)); + return tables; } + }