From e1d18909e227327619bdc58d3a032844c35be13e Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 10 Mar 2021 14:15:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E6=B7=BB=E5=8A=A0=E5=9C=BA=E6=99=AF=E5=88=B0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92=E6=97=B6=E6=9C=AA=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/automation/SaveApiPlanRequest.java | 10 +++++ .../api/service/ApiAutomationService.java | 29 +++++++++---- .../ext/ExtTestPlanScenarioCaseMapper.xml | 4 +- .../automation/scenario/ApiScenarioList.vue | 30 +++++++++---- .../scenario/testplan/TestPlanList.vue | 42 ++++++++++++++++--- 5 files changed, 91 insertions(+), 24 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiPlanRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiPlanRequest.java index 516efd56e8..2e91f5999e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiPlanRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/SaveApiPlanRequest.java @@ -34,4 +34,14 @@ public class SaveApiPlanRequest { private String projectId; + /** + * 项目环境对应关系 + */ + private Map envMap; + + /** + * 用例的环境的对应关系 + */ + private Map> mapping; + } 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 d6a92e7d44..4846a2b422 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -611,27 +611,38 @@ public class ApiAutomationService { if (CollectionUtils.isEmpty(request.getPlanIds())) { MSException.throwException(Translator.get("plan id is null ")); } - List scenarioIds = request.getScenarioIds(); - if (request.isSelectAllDate()) { - scenarioIds = this.getAllScenarioIdsByFontedSelect( - request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds()); - } +// List scenarioIds = request.getScenarioIds(); +// if (request.isSelectAllDate()) { +// scenarioIds = this.getAllScenarioIdsByFontedSelect( +// request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds()); +// } + Map> mapping = request.getMapping(); + Map envMap = request.getEnvMap(); + Set set = mapping.keySet(); List list = extTestPlanMapper.selectByIds(request.getPlanIds()); SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ExtTestPlanScenarioCaseMapper scenarioBatchMapper = sqlSession.getMapper(ExtTestPlanScenarioCaseMapper.class); ExtTestPlanApiCaseMapper apiCaseBatchMapper = sqlSession.getMapper(ExtTestPlanApiCaseMapper.class); for (TestPlanDTO testPlan : list) { - if (scenarioIds != null) { - for (String scenarioId : scenarioIds) { + if (!set.isEmpty()) { + set.forEach(id -> { + Map newEnvMap = new HashMap<>(16); + if (envMap != null && !envMap.isEmpty()) { + List lt = mapping.get(id); + lt.forEach(l -> { + newEnvMap.put(l, envMap.get(l)); + }); + } TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); testPlanApiScenario.setId(UUID.randomUUID().toString()); - testPlanApiScenario.setApiScenarioId(scenarioId); + testPlanApiScenario.setApiScenarioId(id); testPlanApiScenario.setTestPlanId(testPlan.getId()); testPlanApiScenario.setCreateTime(System.currentTimeMillis()); testPlanApiScenario.setUpdateTime(System.currentTimeMillis()); + testPlanApiScenario.setEnvironment(JSON.toJSONString(newEnvMap)); scenarioBatchMapper.insertIfNotExists(testPlanApiScenario); - } + }); } if (request.getApiIds() != null) { for (String caseId : request.getApiIds()) { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml index ac1de53c06..95c735f953 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestPlanScenarioCaseMapper.xml @@ -5,8 +5,8 @@ -- 查询没有数据再插入 - INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time) - SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime} + INSERT INTO test_plan_api_scenario(id, test_plan_id, api_scenario_id, create_time, update_time, environment) + SELECT #{request.id}, #{request.testPlanId}, #{request.apiScenarioId}, #{request.createTime}, #{request.updateTime}, #{request.environment} FROM DUAL WHERE NOT EXISTS( SELECT id FROM diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 6bb9514153..32cd3a64a2 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -145,7 +145,7 @@ - + @@ -318,7 +318,7 @@ ], principal: [], environmentId: [], - projectEnv: [] + projectEnv: [], }, } }, @@ -496,17 +496,31 @@ cancel() { this.planVisible = false; }, - addTestPlan(plans) { - let obj = {planIds: plans, scenarioIds: this.selection}; + addTestPlan(params) { + let obj = {planIds: params[0], scenarioIds: this.selection}; - obj.projectId = getCurrentProjectID(); - obj.selectAllDate = this.isSelectAllDate; - obj.unSelectIds = this.unSelection; - obj = Object.assign(obj, this.condition); + // obj.projectId = getCurrentProjectID(); + // obj.selectAllDate = this.isSelectAllDate; + // obj.unSelectIds = this.unSelection; + // obj = Object.assign(obj, this.condition); + + // todo 选取全部数据 + if (this.isSelectAllDate) { + this.$warning("暂不支持批量添加所有场景到测试计划!"); + } this.planVisible = false; + + let map = new Map(); + this.selectRows.forEach(row => { + map.set(row.id, row.projectIds); + }) + obj.mapping = strMapToObj(map); + obj.envMap = strMapToObj(params[1]); + this.$post("/api/automation/scenario/plan", obj, response => { this.$success(this.$t("commons.save_success")); + this.search(); }); }, getReport() { diff --git a/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue b/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue index 7e631ce3a3..bcbe85bf8b 100644 --- a/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue +++ b/frontend/src/business/components/api/automation/scenario/testplan/TestPlanList.vue @@ -3,9 +3,11 @@ - + s.id); this.$emit('selection', selection); }, + setScenarioSelectRows(rows) { + this.projectIds.clear(); + rows.forEach(row => { + row.projectIds.forEach(id => this.projectIds.add(id)); + }) + }, initTableData() { if (this.planId) { this.condition.planId = this.planId; @@ -284,6 +308,14 @@ export default { this.$refs.testCaseReportView.open(planId, reportId); } }, + checkEnv() { + return this.$refs.envPopover.checkEnv(); + }, + getWsProjects() { + this.$get("/project/listAll", res => { + this.projectList = res.data; + }) + }, } }