diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index cc63e40754..f42cbf6860 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -2,6 +2,7 @@ package io.metersphere.api.service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.JSONPath; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; @@ -102,8 +103,13 @@ public class ApiAutomationService { Map map = d.getEnvironmentMap(); List idList = new ArrayList<>(); if (map != null) { - Set set = d.getEnvironmentMap().keySet(); - idList = new ArrayList<>(set); + if (map.isEmpty()) { + List ids = (List) JSONPath.read(definition, "$..projectId"); + idList.addAll(new HashSet<>(ids)); + } else { + Set set = d.getEnvironmentMap().keySet(); + idList = new ArrayList<>(set); + } } else { // 兼容历史数据,无EnvironmentMap直接赋值场景所属项目 idList.add(data.getProjectId()); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java index ae2cca7a78..2faa3f357e 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -1,6 +1,7 @@ package io.metersphere.track.service; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONPath; import io.metersphere.api.dto.automation.ApiScenarioDTO; import io.metersphere.api.dto.automation.ApiScenarioRequest; import io.metersphere.api.dto.automation.RunScenarioRequest; @@ -56,8 +57,13 @@ public class TestPlanScenarioCaseService { Map map = d.getEnvironmentMap(); List idList = new ArrayList<>(); if (map != null) { - Set set = d.getEnvironmentMap().keySet(); - idList = new ArrayList<>(set); + if (map.isEmpty()) { + List ids = (List) JSONPath.read(definition, "$..projectId"); + idList.addAll(new HashSet<>(ids)); + } else { + Set set = d.getEnvironmentMap().keySet(); + idList = new ArrayList<>(set); + } } else { // 兼容历史数据,无EnvironmentMap直接赋值场景所属项目 idList.add(data.getProjectId());