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'},