fix:1.修改数据同步策略配置接口,配合前端对接

This commit is contained in:
panbaolin 2026-08-10 10:28:00 +08:00
parent e3fe064509
commit 99262e667f
2 changed files with 12 additions and 20 deletions

View File

@ -49,30 +49,20 @@ public class StasTaskConfigServiceImpl extends ServiceImpl<StasTaskConfigMapper,
*/ */
@Override @Override
public MindMapVO getMindMap(String taskId) { public MindMapVO getMindMap(String taskId) {
// 1. 使用多线程并行查询数据库 StasTaskConfig stasTaskConfig = stasTaskConfigMapper.selectById(taskId);
CompletableFuture<StasTaskConfig> taskConfigFuture = CompletableFuture.supplyAsync(() -> if(Objects.isNull(stasTaskConfig)) {
stasTaskConfigMapper.selectById(taskId)); throw new RuntimeException("此任务不存在");
}
LambdaQueryWrapper<StasSyncStrategy> strategyQueryWrapper = new LambdaQueryWrapper<>();
strategyQueryWrapper.eq(StasSyncStrategy::getTaskId, taskId);
List<StasSyncStrategy> syncStrategies = stasSyncStrategyMapper.selectList(strategyQueryWrapper);
CompletableFuture<List<StasSyncStrategy>> strategiesFuture = taskConfigFuture.thenApplyAsync(config -> StasDataSource stasDataSource = stasDataSourceMapper.selectById(stasTaskConfig.getSourceId());
stasSyncStrategyMapper.selectList(
new LambdaQueryWrapper<StasSyncStrategy>()
.eq(StasSyncStrategy::getTaskId, taskId)));
CompletableFuture<StasDataSource> dataSourceFuture = taskConfigFuture.thenApplyAsync(config ->
stasDataSourceMapper.selectById(config.getSourceId()));
// 2. 等待所有查询完成
CompletableFuture.allOf(taskConfigFuture, strategiesFuture, dataSourceFuture).join();
// 3. 构建响应对象
StasDataSource sourceInfo = dataSourceFuture.join();
List<StasSyncStrategy> stasSyncStrategies = strategiesFuture.join();
MindMapVO mindMapVO = new MindMapVO(); MindMapVO mindMapVO = new MindMapVO();
mindMapVO.setDatabaseName(sourceInfo.getInstanceName()); mindMapVO.setDatabaseName(stasDataSource.getInstanceName());
// 4. 使用流式处理简化代码 List<UserInfoVO> userInfos = syncStrategies.stream()
List<UserInfoVO> userInfos = stasSyncStrategies.stream()
.collect(Collectors.groupingBy(StasSyncStrategy::getSourceOwner)) .collect(Collectors.groupingBy(StasSyncStrategy::getSourceOwner))
.entrySet().stream() .entrySet().stream()
.map(entry -> { .map(entry -> {
@ -84,6 +74,7 @@ public class StasTaskConfigServiceImpl extends ServiceImpl<StasTaskConfigMapper,
TableInfoVO tableInfoVO = new TableInfoVO(); TableInfoVO tableInfoVO = new TableInfoVO();
tableInfoVO.setTableName(strategy.getTableName()); tableInfoVO.setTableName(strategy.getTableName());
tableInfoVO.setColumnName(strategy.getColumnName()); tableInfoVO.setColumnName(strategy.getColumnName());
tableInfoVO.setSyncCount(strategy.getSyncCount());
return tableInfoVO; return tableInfoVO;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -6,4 +6,5 @@ import lombok.Data;
public class TableInfoVO { public class TableInfoVO {
private String tableName; private String tableName;
private String columnName; private String columnName;
private Integer syncCount;
} }