From 8e705e8463f56b4ec375cdcba3e11bfacae41e3f Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 27 Mar 2023 11:28:19 +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=E4=B8=8D=E5=90=8C=E5=B7=A5=E4=BD=9C=E7=A9=BA?= =?UTF-8?q?=E9=97=B4=E4=B8=8B=E7=9B=B8=E5=90=8C=E9=A1=B9=E7=9B=AE=E5=90=8D?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=E6=B5=8B=E8=AF=95=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=B1=95=E7=A4=BA=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=87=BA=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复不同工作空间下相同项目名的情况下测试报告展示运行环境出错的问题 --- .../exec/scenario/ApiScenarioEnvService.java | 28 +++++++++++++++---- .../plan/service/TestPlanReportService.java | 13 ++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java index 599760e510..72d4b3a97f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java @@ -32,13 +32,13 @@ import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.i18n.Translator; import io.metersphere.plugin.core.MsTestElement; import io.metersphere.service.definition.ApiDefinitionService; +import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; import org.springframework.stereotype.Service; -import jakarta.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -485,9 +485,18 @@ public class ApiScenarioEnvService { String projectName = this.selectNameById(projectId); List envNameList = apiTestEnvironmentService.selectNameByIds(envIdList); if (CollectionUtils.isNotEmpty(envNameList) && StringUtils.isNotEmpty(projectName)) { - returnMap.put(projectName, new ArrayList<>() {{ - this.addAll(envNameList); - }}); + //考虑到存在不同工作空间下有相同名称的项目,这里还是要检查一下项目名称是否已被记录 + if (returnMap.containsKey(projectName)) { + envNameList.forEach(envName -> { + if (!returnMap.get(projectName).contains(envName)) { + returnMap.get(projectName).add(envName); + } + }); + } else { + returnMap.put(projectName, new ArrayList<>() {{ + this.addAll(envNameList); + }}); + } } } } @@ -569,7 +578,7 @@ public class ApiScenarioEnvService { String envId = entry.getValue(); String projectName = this.selectNameById(projectId); String envName = apiTestEnvironmentService.selectNameById(envId); - if (StringUtils.isNoneEmpty(projectName, envName)) { + if (StringUtils.isNoneEmpty(projectName, envName) && this.isProjectEnvMapNotContainsEnv(returnMap, projectName, envName)) { returnMap.put(projectName, new ArrayList<>() {{ this.add(envName); }}); @@ -581,6 +590,15 @@ public class ApiScenarioEnvService { return returnMap; } + private boolean isProjectEnvMapNotContainsEnv(LinkedHashMap> returnMap, String projectName, String envName) { + if (MapUtils.isNotEmpty(returnMap)) { + if (returnMap.containsKey(projectName) && CollectionUtils.isNotEmpty(returnMap.get(projectName)) && returnMap.get(projectName).contains(envName)) { + return false; + } + } + return true; + } + public String selectNameById(String projectId) { Project project = projectMapper.selectByPrimaryKey(projectId); if (project == null) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java index 1b2085cd3c..30232a9c2b 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanReportService.java @@ -1208,7 +1208,18 @@ public class TestPlanReportService { String envName = apiTestEnvironmentService.selectNameById(envId); envNameList.add(envName); } - projectEnvMap.put(projectName, envNameList); + //考虑到存在不同工作空间下有相同名称的项目,这里还是要检查一下项目名称是否已被记录 + if (projectEnvMap.containsKey(projectName)) { + envNameList.forEach(envName -> { + if (!projectEnvMap.get(projectName).contains(envName)) { + projectEnvMap.get(projectName).add(envName); + } + }); + } else { + projectEnvMap.put(projectName, new ArrayList<>() {{ + this.addAll(envNameList); + }}); + } } } if (MapUtils.isNotEmpty(projectEnvMap)) {