From e58dcf4d889c4f6a3c885a2da34b1a753fa9fc20 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 17 Mar 2021 14:05:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=B9=E9=87=8F=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiAutomationController.java | 2 +- .../api/dto/automation/ApiScenarioDTO.java | 2 + .../api/service/ApiAutomationService.java | 50 +++++++++---------- .../base/mapper/ext/ExtApiScenarioMapper.xml | 2 - .../TestCaseReviewScenarioCaseService.java | 37 -------------- .../service/TestPlanScenarioCaseService.java | 31 ------------ .../automation/scenario/ApiScenarioList.vue | 14 ++---- .../scenario/testplan/TestPlanList.vue | 11 ++-- .../track/case/components/BatchEdit.vue | 25 +++++++--- .../comonents/api/RelevanceScenarioList.vue | 7 ++- .../api/TestCaseScenarioRelevance.vue | 6 +-- .../comonents/api/TestPlanApiScenarioList.vue | 8 +-- 12 files changed, 66 insertions(+), 129 deletions(-) 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 @@