From b7b779fedbe5e702e725933aee19705ee22bea3c Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Thu, 24 Nov 2022 12:16:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F=E6=9F=A5=E8=AF=A2=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84=E5=9C=B0=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1020204 --user=宋天阳 [测试跟踪] github#20073升级到2.3.1测试跟踪--测试计划-报告打开报错误 https://www.tapd.cn/55049933/s/1304179 --- .../definition/ApiDefinitionService.java | 35 +++++++++++++++++++ .../service/plan/TestPlanApiCaseService.java | 11 ++++-- .../ext/BaseApiTestEnvironmentMapper.java | 1 + .../ext/BaseApiTestEnvironmentMapper.xml | 10 ++++++ .../service/BaseEnvironmentService.java | 8 +++++ 5 files changed, 63 insertions(+), 2 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 ebf8a4fd1a..e6606375ae 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 @@ -2969,6 +2969,41 @@ public class ApiDefinitionService { return returnMap; } + public Map> getProjectEnvNameByEnvConfig(Map> projectEnvConfigMap) { + 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 { + runModeConfigDTO = JSON.parseObject(envConfig, RunModeConfigDTO.class); + } 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); + } + } + }); + 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; + } + public List selectApiDefinitionBydIds(List ids) { if (CollectionUtils.isEmpty(ids)) { return new ArrayList<>(); 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 ab2e422b57..ed8a3b1a8c 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 @@ -508,12 +508,19 @@ public class TestPlanApiCaseService { Map> result = new LinkedHashMap<>(); if (!CollectionUtils.isEmpty(resourceIds)) { List execResults = apiDefinitionExecResultService.selectByResourceIdsAndMaxCreateTime(resourceIds); + Map> projectConfigMap = new HashMap<>(); execResults.forEach(item -> { String envConf = item.getEnvConfig(); String projectId = item.getProjectId(); - Map> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectId, envConf); - this.setProjectEnvMap(result, projectEnvMap); + if (projectConfigMap.containsKey(projectId)) { + projectConfigMap.get(projectId).add(envConf); + } else { + projectConfigMap.put(projectId, new ArrayList<>() {{ + this.add(envConf); + }}); + } }); + Map> projectEnvMap = apiDefinitionService.getProjectEnvNameByEnvConfig(projectConfigMap); } return result; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.java index 6fb82eb3d5..4ef7307da8 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.java @@ -13,4 +13,5 @@ public interface BaseApiTestEnvironmentMapper { List getNodeTreeByProjectId(@Param("projectId") String projectId, @Param("protocol") String protocol); + List selectNameByIdList(@Param("ids") List envIdList); } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.xml b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.xml index 2b49d0fc8c..c3d49ac516 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.xml +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseApiTestEnvironmentMapper.xml @@ -18,6 +18,16 @@ FROM api_test_environment WHERE id = #{0} + + +