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; } } }