From 785e8d75ce9ce691826dfa8b191641a675beeb2e Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Fri, 21 Jul 2023 15:03:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BF=AE=E6=94=B9=E5=BC=95=E7=94=A8=E7=9A=84?= =?UTF-8?q?case=E7=9A=84=E5=89=8D=E5=90=8E=E7=BD=AE=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=EF=BC=8C=E5=9C=BA=E6=99=AF=E6=9C=AA=E5=90=8C=E6=AD=A5=E7=9A=84?= =?UTF-8?q?=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1028019 --user=王孝刚 【测试跟踪】github#25703,测试计划关联场景,场景中引用了case, case 修改,测试计划执行未同步更新 https://www.tapd.cn/55049933/s/1396141 --- .../dto/definition/request/ElementUtil.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java index 4dd30e9c55..309e456a6e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ElementUtil.java @@ -74,6 +74,7 @@ import java.io.File; import java.net.URL; import java.nio.charset.StandardCharsets; import java.util.*; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -455,10 +456,22 @@ public class ElementUtil { } }); - sourceList = sourceList.stream().collect(Collectors - .collectingAndThen( - Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(MsTestElement::getId))), - ArrayList::new)); + + //对sourceList根据id去重并且保持原有顺序 + sourceList = sourceList.stream() + .collect(Collectors.toMap(MsTestElement::getId, Function.identity(), (oldValue, newValue) -> oldValue, LinkedHashMap::new)) + .values() + .stream() + .collect(Collectors.toList()); + + //删除不需要的元素 + for (int i = 0; i < sourceList.size(); i++) { + MsTestElement item = sourceList.get(i); + if (!StringUtils.equals(item.getLabel(), SCENARIO_REF) + && targetHashTree.stream().noneMatch(target -> StringUtils.equals(target.getId(), item.getId()))) { + sourceList.remove(i); + } + } element.getHashTree().clear(); element.getHashTree().addAll(sourceList); @@ -508,13 +521,6 @@ public class ElementUtil { } } - // 添加少的步骤 - if (MapUtils.isNotEmpty(updateMap)) { - updateMap.forEach((k, v) -> { - sources.add(v); - }); - } - // 删除多余的步骤 for (int i = 0; i < sources.size(); i++) { JSONObject source = sources.get(i);