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