From dd1e5619e3299c9e4126820f0bf1c30cc7ef1da0 Mon Sep 17 00:00:00 2001 From: AgAngle <1323481023@qq.com> Date: Sun, 16 Jun 2024 15:21:11 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E4=B8=B2=E8=A1=8C=E6=89=A7=E8=A1=8C=E9=A1=BA?= =?UTF-8?q?=E5=BA=8F=E6=9C=89=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/service/TestPlanApiCaseService.java | 14 +++++++++++++- .../plan/service/TestPlanApiScenarioService.java | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index 13f678fc5b..afacbd8ee4 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -62,6 +62,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -488,7 +489,18 @@ public class TestPlanApiCaseService extends TestPlanResourceService { } else { TestPlanApiCaseExample example = new TestPlanApiCaseExample(); example.createCriteria().andIdIn(request.getSelectIds()); - return testPlanApiCaseMapper.selectByExample(example); + Map testPlanApiCaseMap = testPlanApiCaseMapper.selectByExample(example) + .stream() + .collect(Collectors.toMap(TestPlanApiCase::getId, Function.identity())); + List testPlanApiCases = new ArrayList<>(request.getSelectIds().size()); + // 按ID的顺序排序 + for (String id : request.getSelectIds()) { + TestPlanApiCase testPlanApiCase = testPlanApiCaseMap.get(id); + if (testPlanApiCase != null) { + testPlanApiCases.add(testPlanApiCase); + } + } + return testPlanApiCases; } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java index c6eb53eb5b..e724e4fe89 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java @@ -63,6 +63,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; import java.util.stream.Collectors; @Service @@ -654,7 +655,18 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { } else { TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); example.createCriteria().andIdIn(request.getSelectIds()); - return testPlanApiScenarioMapper.selectByExample(example); + Map testPlanApiScenarioMap = testPlanApiScenarioMapper.selectByExample(example) + .stream() + .collect(Collectors.toMap(TestPlanApiScenario::getId, Function.identity())); + List testPlanApiScenarios = new ArrayList<>(request.getSelectIds().size()); + // 按ID的顺序排序 + for (String id : request.getSelectIds()) { + TestPlanApiScenario testPlanApiScenario = testPlanApiScenarioMap.get(id); + if (testPlanApiScenario != null) { + testPlanApiScenarios.add(testPlanApiScenario); + } + } + return testPlanApiScenarios; } } }