fix(测试计划): 生成报告模块树造成的迭代问题

This commit is contained in:
song-cc-rock 2024-07-16 15:35:51 +08:00 committed by 刘瑞斌
parent 993508e2f7
commit b41eaa2d82
1 changed files with 19 additions and 5 deletions

View File

@ -19,29 +19,43 @@ public class ModuleTreeUtils {
/** /**
* 解析并返回模块的全路径 * 解析并返回模块的全路径
* @param allNodes 模块集合 * @param filterNodes 模块集合
* @param nodePathMap 树节点路径集合 * @param nodePathMap 树节点路径集合
*/ */
public static void genPathMap(List<TestPlanBaseModule> allNodes, Map<String, String> nodePathMap, List<String> scanIds) { private static void realGenPathMap(List<TestPlanBaseModule> filterNodes, Map<String, String> nodePathMap, List<String> scanIds) {
int lastLoopSize = nodePathMap.size();
if (MapUtils.isEmpty(nodePathMap)) { if (MapUtils.isEmpty(nodePathMap)) {
// 根节点遍历 // 根节点遍历
List<TestPlanBaseModule> rootNodes = allNodes.stream().filter(node -> List<TestPlanBaseModule> rootNodes = filterNodes.stream().filter(node ->
StringUtils.isBlank(node.getParentId()) || StringUtils.equals(node.getParentId(), "NONE")).toList(); StringUtils.isBlank(node.getParentId()) || StringUtils.equals(node.getParentId(), "NONE")).toList();
rootNodes.forEach(node -> nodePathMap.put(node.getId(), MODULE_PATH_PREFIX + node.getName())); rootNodes.forEach(node -> nodePathMap.put(node.getId(), MODULE_PATH_PREFIX + node.getName()));
// 下一级父节点 // 下一级父节点
scanIds = rootNodes.stream().map(TestPlanBaseModule::getId).toList(); scanIds = rootNodes.stream().map(TestPlanBaseModule::getId).toList();
filterNodes.removeAll(rootNodes);
} else { } else {
// 非根节点遍历 // 非根节点遍历
List<String> finalScanIds = scanIds; List<String> finalScanIds = scanIds;
List<TestPlanBaseModule> scanNodes = allNodes.stream().filter(node -> finalScanIds.contains(node.getParentId())).toList(); List<TestPlanBaseModule> scanNodes = filterNodes.stream().filter(node -> finalScanIds.contains(node.getParentId())).toList();
scanNodes.forEach(node -> nodePathMap.put(node.getId(), nodePathMap.getOrDefault(node.getParentId(), StringUtils.EMPTY) + MODULE_PATH_PREFIX + node.getName())); scanNodes.forEach(node -> nodePathMap.put(node.getId(), nodePathMap.getOrDefault(node.getParentId(), StringUtils.EMPTY) + MODULE_PATH_PREFIX + node.getName()));
// 下一级父节点 // 下一级父节点
scanIds = scanNodes.stream().map(TestPlanBaseModule::getId).toList(); scanIds = scanNodes.stream().map(TestPlanBaseModule::getId).toList();
// 每次过滤的数据
filterNodes.removeAll(scanNodes);
} }
if (CollectionUtils.isEmpty(scanIds)) { if (CollectionUtils.isEmpty(scanIds)) {
// 叶子节点不存在, 跳出 // 叶子节点不存在, 跳出
return; return;
} }
genPathMap(allNodes, nodePathMap, scanIds); if (lastLoopSize == nodePathMap.size()) {
// 处理前后无新数据产生, 无效的迭代, 跳出;
return;
}
realGenPathMap(filterNodes, nodePathMap, scanIds);
}
public static void genPathMap(List<TestPlanBaseModule> allNodes, Map<String, String> nodePathMap, List<String> scanIds) {
// 过滤掉一些不好的数据
allNodes.removeIf(node -> StringUtils.equals(node.getId(), "NONE") || StringUtils.equals(node.getId(), node.getParentId()));
realGenPathMap(allNodes, nodePathMap, scanIds);
} }
} }