From b8c728aef8a8f94938d49c4a5ff90e8632ec1e37 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Mon, 16 Jan 2023 13:10:02 +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/codegen/CodegenServiceImpl.java | 4 -- .../service/db/DatabaseTableServiceImpl.java | 47 ++++++++++++------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java index d531d237b..3b693eb50 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/CodegenServiceImpl.java @@ -237,10 +237,6 @@ public class CodegenServiceImpl implements CodegenService { @Override public List getDatabaseTableList(Long dataSourceConfigId, String name, String comment) { List tables = databaseTableService.getTableList(dataSourceConfigId, name, comment); - // 移除置顶前缀的表名 // TODO 未来做成可配置 - tables.removeIf(table -> table.getName().toUpperCase().startsWith("QRTZ_")); - tables.removeIf(table -> table.getName().toUpperCase().startsWith("ACT_")); - tables.removeIf(table -> table.getName().toUpperCase().startsWith("FLW_")); // 移除已经生成的表 // 移除在 Codegen 中,已经存在的 Set existsTables = CollectionUtils.convertSet( 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 6b8346cf0..77ff2409f 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,9 +12,12 @@ 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; /** @@ -28,6 +31,26 @@ 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); @@ -42,24 +65,16 @@ public class DatabaseTableServiceImpl implements DatabaseTableService { } public List getTableList0(Long dataSourceConfigId, String name) { - // 获得数据源配置 - DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId); - Assert.notNull(config, "数据源({}) 不存在!", dataSourceConfigId); + ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId); + Assert.notNull(builder, "数据源({}) 不存在!", 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); - } - 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(); - tables.sort(Comparator.comparing(TableInfo::getName)); - return tables; + if (StrUtil.isBlank(name)) { + tables.sort(Comparator.comparing(TableInfo::getName)); + return tables; + } else { + return CollUtil.filter(tables, tableInfo -> tableInfo.getName().equals(name)); + } } - }