feat: 优化代码生成列表加载速度
This commit is contained in:
parent
161205d32a
commit
b8c728aef8
@ -237,10 +237,6 @@ public class CodegenServiceImpl implements CodegenService {
|
|||||||
@Override
|
@Override
|
||||||
public List<DatabaseTableRespVO> getDatabaseTableList(Long dataSourceConfigId, String name, String comment) {
|
public List<DatabaseTableRespVO> getDatabaseTableList(Long dataSourceConfigId, String name, String comment) {
|
||||||
List<TableInfo> tables = databaseTableService.getTableList(dataSourceConfigId, name, comment);
|
List<TableInfo> 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 中,已经存在的
|
// 移除在 Codegen 中,已经存在的
|
||||||
Set<String> existsTables = CollectionUtils.convertSet(
|
Set<String> existsTables = CollectionUtils.convertSet(
|
||||||
|
@ -12,9 +12,12 @@ import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
|||||||
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
import com.baomidou.mybatisplus.generator.config.rules.DateType;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,6 +31,26 @@ public class DatabaseTableServiceImpl implements DatabaseTableService {
|
|||||||
@Resource
|
@Resource
|
||||||
private DataSourceConfigService dataSourceConfigService;
|
private DataSourceConfigService dataSourceConfigService;
|
||||||
|
|
||||||
|
private final Map<Long, ConfigBuilder> 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
|
@Override
|
||||||
public List<TableInfo> getTableList(Long dataSourceConfigId, String nameLike, String commentLike) {
|
public List<TableInfo> getTableList(Long dataSourceConfigId, String nameLike, String commentLike) {
|
||||||
List<TableInfo> tables = getTableList0(dataSourceConfigId, null);
|
List<TableInfo> tables = getTableList0(dataSourceConfigId, null);
|
||||||
@ -42,24 +65,16 @@ public class DatabaseTableServiceImpl implements DatabaseTableService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<TableInfo> getTableList0(Long dataSourceConfigId, String name) {
|
public List<TableInfo> getTableList0(Long dataSourceConfigId, String name) {
|
||||||
// 获得数据源配置
|
ConfigBuilder builder = ConfigBuilderMap.get(dataSourceConfigId);
|
||||||
DataSourceConfigDO config = dataSourceConfigService.getDataSourceConfig(dataSourceConfigId);
|
Assert.notNull(builder, "数据源({}) 不存在!", 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);
|
|
||||||
}
|
|
||||||
GlobalConfig globalConfig = new GlobalConfig.Builder().dateType(DateType.TIME_PACK).build(); // 只使用 Date 类型,不使用 LocalDate
|
|
||||||
ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, strategyConfig.build(),
|
|
||||||
null, globalConfig, null);
|
|
||||||
// 按照名字排序
|
// 按照名字排序
|
||||||
List<TableInfo> tables = builder.getTableInfoList();
|
List<TableInfo> tables = builder.getTableInfoList();
|
||||||
tables.sort(Comparator.comparing(TableInfo::getName));
|
if (StrUtil.isBlank(name)) {
|
||||||
return tables;
|
tables.sort(Comparator.comparing(TableInfo::getName));
|
||||||
|
return tables;
|
||||||
|
} else {
|
||||||
|
return CollUtil.filter(tables, tableInfo -> tableInfo.getName().equals(name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user