refactor(接口测试): 根据资源池类型过滤
This commit is contained in:
parent
97d026e3d6
commit
d4673456eb
|
@ -61,6 +61,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
@ -188,6 +189,7 @@ public class BaseTaskHubService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置任务的报告ID
|
* 设置任务的报告ID
|
||||||
|
*
|
||||||
* @param tasks 任务集合
|
* @param tasks 任务集合
|
||||||
*/
|
*/
|
||||||
private void setTaskReportId(List<TaskHubDTO> tasks) {
|
private void setTaskReportId(List<TaskHubDTO> tasks) {
|
||||||
|
@ -749,27 +751,19 @@ public class BaseTaskHubService {
|
||||||
public Map<String, Integer> getTaskItemOrder(List<String> taskIdItemIds) {
|
public Map<String, Integer> getTaskItemOrder(List<String> taskIdItemIds) {
|
||||||
List<ExecTaskItem> taskItemIds = getTaskItemByIds(taskIdItemIds);
|
List<ExecTaskItem> taskItemIds = getTaskItemByIds(taskIdItemIds);
|
||||||
Map<String, List<ExecTaskItem>> nodeResourceMap = taskItemIds.stream()
|
Map<String, List<ExecTaskItem>> nodeResourceMap = taskItemIds.stream()
|
||||||
|
.filter(item -> StringUtils.equals(item.getResourceType(), ResourcePoolTypeEnum.NODE.getName())) // 根据条件过滤
|
||||||
.collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
|
.collect(Collectors.groupingBy(ExecTaskItem::getResourcePoolNode));
|
||||||
|
|
||||||
Map<String, Integer> taskItemOrderMap = new HashMap<>();
|
List<CompletableFuture<Map<String, Integer>>> futures = nodeResourceMap.keySet().stream()
|
||||||
|
.filter(StringUtils::isNotBlank)
|
||||||
|
.map(execTaskItems -> CompletableFuture.supplyAsync(() -> getTaskItemOrder(execTaskItems, taskIdItemIds)))
|
||||||
|
.toList();
|
||||||
|
|
||||||
List<Thread> threads = new ArrayList<>();
|
// 等待所有异步任务完成并合并结果
|
||||||
nodeResourceMap.forEach((node, items) -> {
|
return futures.stream()
|
||||||
if (StringUtils.isNotBlank(node)) {
|
.map(CompletableFuture::join)
|
||||||
Thread thread = Thread.startVirtualThread(() -> taskItemOrderMap.putAll(getTaskItemOrder(node, taskIdItemIds)));
|
.flatMap(map -> map.entrySet().stream())
|
||||||
threads.add(thread);
|
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
for (Thread thread : threads) {
|
|
||||||
try {
|
|
||||||
thread.join();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LogUtils.error(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return taskItemOrderMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Integer> getTaskItemOrder(String node, List<String> taskIdItemIds) {
|
public Map<String, Integer> getTaskItemOrder(String node, List<String> taskIdItemIds) {
|
||||||
|
|
Loading…
Reference in New Issue