diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index fa4e5d86ef..bc38ce887f 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -86,7 +86,7 @@ public class ApiAutomationController { } @GetMapping("/getApiScenario/{id}") - public ApiScenario getScenarioDefinition(@PathVariable String id) { + public ApiScenarioDTO getScenarioDefinition(@PathVariable String id) { return apiAutomationService.getApiScenario(id); } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java index b1f9e6e044..540ee78564 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioDTO.java @@ -18,4 +18,6 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs { * 场景跨项目ID */ private List projectIds; + + private String caseId; } 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 ebc994c1c4..9da3974953 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -94,42 +94,38 @@ public class ApiAutomationService { public List list(ApiScenarioRequest request) { request = this.initRequest(request, true, true); List list = extApiScenarioMapper.list(request); - setApiScenarioProjectIds(list); return list; } public List listReview(ApiScenarioRequest request) { request = this.initRequest(request, true, true); List list = extApiScenarioMapper.listReview(request); - setApiScenarioProjectIds(list); return list; } - private void setApiScenarioProjectIds(List list) { + private void setApiScenarioProjectIds(ApiScenarioDTO data) { // 如果场景步骤涉及多项目,则把涉及到的项目ID保存在projectIds属性 - list.forEach(data -> { - List idList = new ArrayList<>(); - String definition = data.getScenarioDefinition(); - if (StringUtils.isNotBlank(definition)) { - RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class); + List idList = new ArrayList<>(); + String definition = data.getScenarioDefinition(); + if (StringUtils.isNotBlank(definition)) { + RunDefinitionRequest d = JSON.parseObject(definition, RunDefinitionRequest.class); - if (d != null) { - Map map = d.getEnvironmentMap(); - if (map != null) { - 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); - } + if (d != null) { + Map map = d.getEnvironmentMap(); + if (map != null) { + if (map.isEmpty()) { + List ids = (List) JSONPath.read(definition, "$..projectId"); + idList.addAll(new HashSet<>(ids)); } else { - // 兼容历史数据,无EnvironmentMap直接赋值场景所属项目 - idList.add(data.getProjectId()); + Set set = d.getEnvironmentMap().keySet(); + idList = new ArrayList<>(set); } + } else { + // 兼容历史数据,无EnvironmentMap直接赋值场景所属项目 + idList.add(data.getProjectId()); } - } - data.setProjectIds(idList); - }); + + } + data.setProjectIds(idList); } /** @@ -333,8 +329,12 @@ public class ApiAutomationService { } } - public ApiScenarioWithBLOBs getApiScenario(String id) { - return apiScenarioMapper.selectByPrimaryKey(id); + public ApiScenarioDTO getApiScenario(String id) { + ApiScenarioDTO apiScenarioDTO = new ApiScenarioDTO(); + ApiScenarioWithBLOBs scenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id); + BeanUtils.copyBean(apiScenarioDTO, scenarioWithBLOBs); + setApiScenarioProjectIds(apiScenarioDTO); + return apiScenarioDTO; } public List getApiScenarios(List ids) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index 033111900a..c7db6225fe 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -134,7 +134,6 @@