From 1b3da348c25a1a029fd308e14c9b981434bb7195 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 22 Mar 2023 18:26:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=9C=BA=E6=99=AF=E6=97=B6=E7=94=B1=E4=BA=8E=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=B7=A8=E9=A1=B5=E9=80=89=E6=8B=A9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E8=80=8C=E5=BC=95=E8=B5=B7=E7=9A=84=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E5=85=A8=E9=83=A8=E6=B7=BB=E5=8A=A0=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1024678 --user=宋天阳 [测试跟踪]github#22858测试计划中添加场景用例,全选所有场景(不止一页数据),非当前页的某个场景含多个项目运行环境时,在测试计划中选择环境时无法选择多个项目环境,导致执行测试计划时一直running https://www.tapd.cn/55049933/s/1354570 --- .../dto/automation/ScenarioProjectDTO.java | 34 +++++++++++++++++++ .../commons/utils/BatchProcessingUtil.java | 13 +++---- .../plan/TestPlanScenarioCaseController.java | 2 +- .../plan/TestPlanScenarioCaseService.java | 2 +- .../service/scenario/ApiScenarioService.java | 17 +++++----- .../comonents/api/RelevanceScenarioList.vue | 12 +++++-- 6 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 api-test/backend/src/main/java/io/metersphere/api/dto/automation/ScenarioProjectDTO.java diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ScenarioProjectDTO.java b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ScenarioProjectDTO.java new file mode 100644 index 0000000000..80ff529a89 --- /dev/null +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/automation/ScenarioProjectDTO.java @@ -0,0 +1,34 @@ +package io.metersphere.api.dto.automation; + +import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Data +public class ScenarioProjectDTO { + private List projectIdList; + private Map> scenarioProjectIdMap; + + public ScenarioProjectDTO() { + this.projectIdList = new ArrayList<>(); + this.scenarioProjectIdMap = new HashMap<>(); + } + + public void merge(ScenarioProjectDTO mergeDTO) { + if (CollectionUtils.isNotEmpty(mergeDTO.getProjectIdList())) { + for (String projectId : mergeDTO.getProjectIdList()) { + if (!this.projectIdList.contains(projectId)) { + projectIdList.add(projectId); + } + } + } + if (MapUtils.isNotEmpty(mergeDTO.getScenarioProjectIdMap())) { + this.scenarioProjectIdMap.putAll(mergeDTO.getScenarioProjectIdMap()); + } + } +} diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/BatchProcessingUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/BatchProcessingUtil.java index 2e11c49bf3..af651f8e1a 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/BatchProcessingUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/BatchProcessingUtil.java @@ -1,5 +1,6 @@ package io.metersphere.commons.utils; +import io.metersphere.api.dto.automation.ScenarioProjectDTO; import io.metersphere.api.dto.definition.BatchDataCopyRequest; import io.metersphere.base.domain.ApiScenarioReportResultWithBLOBs; import org.apache.commons.collections.CollectionUtils; @@ -16,8 +17,8 @@ public class BatchProcessingUtil { private static final int BATCH_PROCESS_QUANTITY = 1000; - public static List getProjectIdsByScenarioIdList(List scenarioIdList, Function, List> func) { - List returnList = new ArrayList<>(); + public static ScenarioProjectDTO getProjectIdsByScenarioIdList(List scenarioIdList, Function, ScenarioProjectDTO> func) { + ScenarioProjectDTO returnDTO = new ScenarioProjectDTO(); if (CollectionUtils.isNotEmpty(scenarioIdList)) { int unProcessingCount = scenarioIdList.size(); while (scenarioIdList.size() > BATCH_PROCESS_QUANTITY) { @@ -26,9 +27,9 @@ public class BatchProcessingUtil { processingList.add(scenarioIdList.get(i)); } //函数处理 - returnList.addAll(func.apply(processingList)); - scenarioIdList.removeAll(processingList); + returnDTO.merge(func.apply(processingList)); + scenarioIdList.removeAll(processingList); //如果剩余数量没有发生变化,则跳出循环。防止出现死循环的情况 if (scenarioIdList.size() == unProcessingCount) { break; @@ -38,10 +39,10 @@ public class BatchProcessingUtil { } if (CollectionUtils.isNotEmpty(scenarioIdList)) { //剩余待处理数据进行处理 - returnList.addAll(func.apply(scenarioIdList)); + returnDTO.merge(func.apply(scenarioIdList)); } } - return returnList; + return returnDTO; } public static List selectScenarioReportResultByScenarioReportId(List scenarioReportId, Function, List> func) { diff --git a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java index 3a269f7544..107e5a47b3 100644 --- a/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java +++ b/api-test/backend/src/main/java/io/metersphere/controller/plan/TestPlanScenarioCaseController.java @@ -79,7 +79,7 @@ public class TestPlanScenarioCaseController { } @PostMapping("/relevance/projectIds") - public List relevanceProjectIds(@RequestBody ApiScenarioRequest request) { + public ScenarioProjectDTO relevanceProjectIds(@RequestBody ApiScenarioRequest request) { return testPlanScenarioCaseService.relevanceProjectIds(request); } diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java index 8b61c91d66..fb2b9da5a0 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanScenarioCaseService.java @@ -178,7 +178,7 @@ public class TestPlanScenarioCaseService { return PageUtils.setPageInfo(page, apiAutomationService.list(request)); } - public List relevanceProjectIds(ApiScenarioRequest request) { + public ScenarioProjectDTO relevanceProjectIds(ApiScenarioRequest request) { request.setNotInTestPlan(true); if (request.getAllowedRepeatCase()) { request.setNotInTestPlan(false); diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index 36b91fe7e7..1f02e9b473 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -2309,19 +2309,17 @@ public class ApiScenarioService { } } - public List projectIdInlist(ApiScenarioRequest request) { + public ScenarioProjectDTO projectIdInlist(ApiScenarioRequest request) { request = this.initRequest(request, true, true); List scenarioIdList = extApiScenarioMapper.selectIdByScenarioRequest(request); if (CollectionUtils.isNotEmpty(request.getUnSelectIds())) { scenarioIdList.removeAll(request.getUnSelectIds()); } - List projectIdList = BatchProcessingUtil.getProjectIdsByScenarioIdList(scenarioIdList, this::getProjectIdsByScenarioIdList); - - return projectIdList; + return BatchProcessingUtil.getProjectIdsByScenarioIdList(scenarioIdList, this::getProjectIdsByScenarioIdList); } - public List getProjectIdsByScenarioIdList(List scenarioIdList) { - List projectIdList = new ArrayList<>(); + public ScenarioProjectDTO getProjectIdsByScenarioIdList(List scenarioIdList) { + ScenarioProjectDTO returnDTO = new ScenarioProjectDTO(); if (CollectionUtils.isNotEmpty(scenarioIdList)) { ApiScenarioExample example = new ApiScenarioExample(); example.createCriteria().andIdIn(scenarioIdList); @@ -2330,14 +2328,15 @@ public class ApiScenarioService { ScenarioEnv scenarioEnv = apiScenarioEnvService.getApiScenarioEnv(scenario.getScenarioDefinition()); if (CollectionUtils.isNotEmpty(scenarioEnv.getProjectIds())) { scenarioEnv.getProjectIds().forEach(projectId -> { - if (!projectIdList.contains(projectId)) { - projectIdList.add(projectId); + if (!returnDTO.getProjectIdList().contains(projectId)) { + returnDTO.getProjectIdList().add(projectId); } }); } + returnDTO.getScenarioProjectIdMap().put(scenario.getId(), new ArrayList<>(scenarioEnv.getProjectIds())); } } - return projectIdList; + return returnDTO; } diff --git a/test-track/frontend/src/business/plan/view/comonents/api/RelevanceScenarioList.vue b/test-track/frontend/src/business/plan/view/comonents/api/RelevanceScenarioList.vue index cd4758a54b..da72277e66 100644 --- a/test-track/frontend/src/business/plan/view/comonents/api/RelevanceScenarioList.vue +++ b/test-track/frontend/src/business/plan/view/comonents/api/RelevanceScenarioList.vue @@ -32,7 +32,6 @@ { this.result.loading = false; - let projectIds = rsp.data; - projectIds.forEach((d) => this.projectIds.add(d)); + if (rsp.data) { + let projectIds = rsp.data.projectIdList; + projectIds.forEach((d) => this.projectIds.add(d)); + let scenarioProjectIdMap = rsp.data.scenarioProjectIdMap; + let scenarioIds = Object.keys(scenarioProjectIdMap); + scenarioIds.forEach((scenarioId) => { + this.map.set(scenarioId, scenarioProjectIdMap[scenarioId]); + }); + } }) .catch(() => { this.result.loading = false;