fix:重构完成;重构点:表的数量较大,在遍历表用于查询的时候安排给线程异步执行,减少执行时间,完成同步

master
Saisai Liu 2024-04-26 22:27:35 +08:00
parent b0f0c3afe5
commit e69291cd38
1 changed files with 30 additions and 12 deletions

View File

@ -15,6 +15,7 @@ import com.muyu.etl.service.StructureService;
import com.muyu.etl.service.TableInfoService;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -22,6 +23,10 @@ import javax.servlet.ServletException;
import java.sql.*;
import java.util.Date;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;
/**
@ -311,18 +316,30 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
List<TableInfoStructureResp> tableInfoStructureRespList = tableInfoService.selectTableInfoList(new TableInfo() {{
setParentId(tableInfo.getId());
}}).stream().map(info -> {
List<Structure> structureList = structureService.list(new LambdaQueryWrapper<Structure>().eq(Structure::getTableId,info.getId()));
return TableInfoStructureResp.builder()
.id(info.getId())
.tableName(info.getTableName())
.center(info.getCenter())
.tableRemark(info.getTableRemark())
.dataNum(info.getDataNum())
.parentId(info.getParentId())
.databaseType(basicConfigInfo.getDatabaseType())
.structureList(structureList)
.basicId(info.getBasicId())
.build();
TableInfoStructureResp callable = null;
try {
callable = new Callable<>() {
@Override
public TableInfoStructureResp call() throws Exception {
List<Structure> structureList = structureService.list(new LambdaQueryWrapper<Structure>().eq(Structure::getTableId, info.getId()));
return TableInfoStructureResp.builder()
.id(info.getId())
.tableName(info.getTableName())
.center(info.getCenter())
.tableRemark(info.getTableRemark())
.dataNum(info.getDataNum())
.parentId(info.getParentId())
.databaseType(basicConfigInfo.getDatabaseType())
.structureList(structureList)
.basicId(info.getBasicId())
.build();
};
}.call();
} catch (Exception e) {
throw new RuntimeException(e);
}
// ExecutorService threadPool = Executors.newCachedThreadPool();
return callable;
}).collect(Collectors.toList());
return TableTreeResp.builder()
.tableInfo(tableInfo)
@ -333,4 +350,5 @@ public class BasicConfigInfoServiceImpl extends ServiceImpl<BasicConfigInfoMapp
return tableTreeRespList;
}
}