From 17d52a6e19661091b8536cb1bf2d02d13883961a Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Fri, 22 Oct 2021 12:01:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=9C=BA=E6=99=AF=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=96=B0=E5=A2=9E=E8=BF=90=E8=A1=8C=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1003532 --user=lyh 6.单接口用例列表和场景列表新增 运行环境 参考测试计划列表的运行环境展示 https://www.tapd.cn/55049933/s/1061128 --- .../controller/ApiAutomationController.java | 4 +- .../api/dto/automation/ApiScenarioDTO.java | 6 ++ .../dto/automation/ApiScenarioRequest.java | 4 ++ .../api/service/ApiAutomationService.java | 49 +++++++++++++++ .../base/mapper/ext/ExtApiScenarioMapper.java | 1 + .../base/mapper/ext/ExtApiScenarioMapper.xml | 4 ++ .../service/TestPlanScenarioCaseService.java | 2 +- .../automation/scenario/ApiScenarioList.vue | 63 +++++++++++++++++++ .../src/common/js/default-table-header.js | 1 + 9 files changed, 132 insertions(+), 2 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 fcddac01cc..b68ef841ed 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -47,7 +47,8 @@ public class ApiAutomationController { @RequiresPermissions("PROJECT_API_SCENARIO:READ") public Pager> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiScenarioRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); - + // 查询场景环境 + request.setSelectEnvironment(true); return PageUtils.setPageInfo(page, apiAutomationService.list(request)); } @@ -367,5 +368,6 @@ public class ApiAutomationController { public List getFollows(@PathVariable String scenarioId) { return apiAutomationService.getFollows(scenarioId); } + } 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 117302645b..447d5d0368 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 @@ -5,6 +5,7 @@ import lombok.Getter; import lombok.Setter; import java.util.List; +import java.util.Map; @Getter @Setter @@ -24,4 +25,9 @@ public class ApiScenarioDTO extends ApiScenarioWithBLOBs { private String caseId; private String environment; + /** + * 场景列表 环境 + */ + private String env; + private Map environmentMap; } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java index 19dfc681b9..41ec492b87 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java @@ -28,4 +28,8 @@ public class ApiScenarioRequest extends BaseQueryRequest { private String operator; //操作时间 private Long operationTime; + /** + * 是否需要查询环境字段 + */ + private boolean selectEnvironment = false; } 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 1a8f692f00..c4e48a447d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -174,9 +174,58 @@ public class ApiAutomationService { public List list(ApiScenarioRequest request) { request = this.initRequest(request, true, true); List list = extApiScenarioMapper.list(request); + if (BooleanUtils.isTrue(request.isSelectEnvironment())) { + this.setApiScenarioEnv(list); + } return list; } + private void setApiScenarioEnv(List list) { + List projectList = projectMapper.selectByExample(new ProjectExample()); + List apiTestEnvironments = apiTestEnvironmentMapper.selectByExampleWithBLOBs(new ApiTestEnvironmentExample()); + for (int i = 0; i < list.size(); i++) { + String env = list.get(i).getEnv(); + // 环境属性为空 跳过 + if (StringUtils.isBlank(env)) { + continue; + } + try { + Map map = JSON.parseObject(env, Map.class); + Set set = map.keySet(); + HashMap envMap = new HashMap<>(16); + // 项目为空 跳过 + if (set.isEmpty()) { + continue; + } + for (String projectId : set) { + String envId = (String) map.get(projectId); + if (StringUtils.isBlank(envId)) { + continue; + } + List projects = projectList.stream().filter(p -> StringUtils.equals(p.getId(), projectId)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(projects)) { + continue; + } + Project project = projects.get(0); + List envs = apiTestEnvironments.stream().filter(e -> StringUtils.equals(e.getId(), envId)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(envs)) { + continue; + } + ApiTestEnvironmentWithBLOBs environment = envs.get(0); + String projectName = project.getName(); + String envName = environment.getName(); + if (StringUtils.isBlank(projectName) || StringUtils.isBlank(envName)) { + continue; + } + envMap.put(projectName, envName); + } + list.get(i).setEnvironmentMap(envMap); + } catch (Exception e) { + LogUtil.error("api scenario environment map incorrect parsing. api scenario id:" + list.get(i).getId()); + } + } + } + public List listAll(ApiScenarioBatchRequest request) { ServiceUtils.getSelectAllIds(request, request.getCondition(), (query) -> extApiScenarioMapper.selectIdsByQuery(query)); diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java index 275380ea9e..6bf78568d5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java @@ -84,4 +84,5 @@ public interface ExtApiScenarioMapper { Long getLastOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder); List getTestCaseForGraph(@Param("ids") Set 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 9756080b7b..b7763bd7af 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 @@ -153,6 +153,9 @@ + 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 774c076299..5bbe6b00f6 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -341,7 +341,7 @@ public class TestPlanScenarioCaseService { return testPlanApiScenarioMapper.countByExample(example) > 0 ? true : false; } - public Map getScenarioCaseEnv(HashMap map) { + public Map getScenarioCaseEnv(Map map) { Set set = map.keySet(); HashMap envMap = new HashMap<>(16); if (set.isEmpty()) { diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index d03abeb7d3..edd5641754 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -132,6 +132,39 @@ :field="item" :fields-width="fieldsWidth" sortable="custom"/> + + + + + diff --git a/frontend/src/common/js/default-table-header.js b/frontend/src/common/js/default-table-header.js index a04c8f30cd..4390fb2521 100644 --- a/frontend/src/common/js/default-table-header.js +++ b/frontend/src/common/js/default-table-header.js @@ -73,6 +73,7 @@ export let CUSTOM_TABLE_HEADER = { {id: 'tags', key: '5', label: 'commons.tag'}, {id: 'userName', key: '6', label: 'api_test.automation.creator'}, {id: 'principalName', key: '7', label: 'api_test.definition.api_principal'}, + {id: 'environmentMap', key: 'e', label: 'commons.environment'}, {id: 'updateTime', key: '8', label: 'api_test.definition.api_last_time'}, {id: 'stepTotal', key: '9', label: 'api_test.automation.step'}, {id: 'lastResult', key: 'a', label: 'api_test.automation.last_result'},