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 2e70ddade4..9f4659c9d7 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 @@ -2350,9 +2350,8 @@ public class ApiScenarioService { public Map> getProjectEnvMap(RunScenarioRequest request) { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); - List ids = request.getIds(); ApiScenarioExample example = new ApiScenarioExample(); - example.createCriteria().andIdIn(ids); + example.createCriteria().andIdIn(request.getIds()); List apiScenarios = apiScenarioMapper.selectByExampleWithBLOBs(example); Map> projectEnvMap = new HashMap<>(); apiScenarios.forEach(item -> { @@ -2360,8 +2359,7 @@ public class ApiScenarioService { JSONObject jsonObject = JSONUtil.parseObject(item.getEnvironmentJson()); Map projectIdEnvMap = jsonObject.toMap(); if (MapUtils.isNotEmpty(projectIdEnvMap)) { - Set projectIds = projectIdEnvMap.keySet(); - projectIds.forEach(t -> { + projectIdEnvMap.keySet().forEach(t -> { List envIds = projectEnvMap.get(t); if (CollectionUtils.isNotEmpty(envIds)) { if (!envIds.contains(projectIdEnvMap.get(t).toString())) { @@ -2376,6 +2374,13 @@ public class ApiScenarioService { }); } } + // 未选择环境的项目 + List scenarioProjectIds = ElementUtil.getProjectIds(item.getScenarioDefinition()); + scenarioProjectIds.forEach(id -> { + if (!projectEnvMap.containsKey(id)) { + projectEnvMap.put(id, new ArrayList<>()); + } + }); }); return projectEnvMap; }