From 0cc2336a3cd7bff4c18043e52e54eb48c8e474ea Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 21 Dec 2023 16:21:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E6=9F=A5=E8=AF=A2=E7=8E=AF=E5=A2=83=E6=97=B6=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=BF=87=E6=BB=A4=E5=9B=9E=E6=94=B6=E7=AB=99=E9=87=8C?= =?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=1033796 --user=宋天阳 【测试跟踪】测试计划-操作执行-项目展示错误 https://www.tapd.cn/55049933/s/1446912 --- .../definition/ApiDefinitionService.java | 36 +++++++++++-------- .../service/plan/TestPlanApiCaseService.java | 4 ++- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index ae0d419c3b..8ab1af8f88 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -1064,7 +1064,10 @@ public class ApiDefinitionService { LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败!", e); } if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) { - String envId = runModeConfigDTO.getEnvMap().get(projectId); + String envId = null; + for (String envItemId : runModeConfigDTO.getEnvMap().values()) { + envId = envItemId; + } apiReportEnvConfig.setEnvName(apiTestEnvironmentService.selectNameById(envId)); } if (runModeConfigDTO != null && StringUtils.isNotBlank(runModeConfigDTO.getResourcePoolId())) { @@ -2199,10 +2202,8 @@ public class ApiDefinitionService { Map> returnMap = new HashMap<>(); if (MapUtils.isNotEmpty(projectEnvConfigMap)) { for (Map.Entry> entry : projectEnvConfigMap.entrySet()) { - String projectId = entry.getKey(); List configList = entry.getValue(); - Project project = baseProjectService.getProjectById(projectId); - List envIdList = new ArrayList<>(); + configList.forEach(envConfig -> { RunModeConfigDTO runModeConfigDTO = null; try { @@ -2210,19 +2211,24 @@ public class ApiDefinitionService { } catch (Exception e) { LogUtil.error("解析" + envConfig + "为RunModeConfigDTO时失败!", e); } - - if (StringUtils.isNotEmpty(projectId) && runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) { - String envId = runModeConfigDTO.getEnvMap().get(projectId); - if (!envIdList.contains(envId)) { - envIdList.add(envId); - } + if (runModeConfigDTO != null && MapUtils.isNotEmpty(runModeConfigDTO.getEnvMap())) { + runModeConfigDTO.getEnvMap().forEach((k, v) -> { + Project project = baseProjectService.getProjectById(k); + String envName = apiTestEnvironmentService.selectNameById(v); + String projectName = project == null ? null : project.getName(); + if (StringUtils.isNoneBlank(projectName, projectName)) { + if (returnMap.containsKey(projectName) && !returnMap.get(projectName).contains(envName)) { + returnMap.get(projectName).add(envName); + } else if (!returnMap.containsKey(projectName)) { + returnMap.put(projectName, new ArrayList<>() {{ + this.add(envName); + }}); + } + } + }); } + }); - String projectName = project == null ? null : project.getName(); - if (StringUtils.isNotEmpty(projectName) && CollectionUtils.isNotEmpty(envIdList)) { - List envNameList = apiTestEnvironmentService.selectNameByIdList(envIdList); - returnMap.put(projectName, envNameList); - } } } return returnMap; diff --git a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java index fc2e8da9c1..f2356050ef 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/plan/TestPlanApiCaseService.java @@ -910,6 +910,8 @@ public class TestPlanApiCaseService { ApiTestCaseExample example = new ApiTestCaseExample(); example.createCriteria().andIdIn(apiCaseIds); List apiTestCases = apiTestCaseMapper.selectByExample(example); - return apiTestCases.stream().map(ApiTestCase::getProjectId).distinct().collect(Collectors.toList()); + List filtedList = apiTestCases.stream().filter( + apiTestCase -> apiTestCase.getStatus() == null || !CommonConstants.TRASH_STATUS.equals(apiTestCase.getStatus())).collect(Collectors.toList()); + return filtedList.stream().map(ApiTestCase::getProjectId).distinct().collect(Collectors.toList()); } }