From 46cc049051fe7b81a426986da64b5bb99e41672b Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Thu, 12 Aug 2021 11:08:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E7=94=A8=E4=BE=8B=E6=89=B9=E9=87=8F=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E5=8F=AF=E9=80=89=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../track/controller/TestPlanController.java | 5 +++ .../service/TestPlanScenarioCaseService.java | 38 +++++++++++++++++++ .../track/service/TestPlanService.java | 36 ++++++++++++++++++ .../track/plan/common/PlanRunModeWithEnv.vue | 12 ++++-- .../comonents/api/TestPlanApiCaseList.vue | 2 +- .../comonents/api/TestPlanApiScenarioList.vue | 32 +++++++++++++--- 6 files changed, 116 insertions(+), 9 deletions(-) diff --git a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java index 5e9cfdf89d..31298fc577 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestPlanController.java @@ -173,6 +173,11 @@ public class TestPlanController { return testPlanService.getApiCaseEnv(caseIds); } + @PostMapping("/api/scenario/env") + public Map> getApiScenarioEnv(@RequestBody List caseIds) { + return testPlanService.getApiScenarioEnv(caseIds); + } + @GetMapping("/report/export/{planId}") public void exportHtmlReport(@PathVariable String planId, HttpServletResponse response) throws UnsupportedEncodingException { testPlanService.exportPlanReport(planId, response); 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 9cafc62a9a..fc99a2c4cf 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanScenarioCaseService.java @@ -22,6 +22,9 @@ import io.metersphere.track.dto.*; import io.metersphere.track.request.testcase.TestPlanScenarioCaseBatchRequest; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -49,6 +52,8 @@ public class TestPlanScenarioCaseService { private ProjectService projectService; @Resource private ApiTestEnvironmentMapper apiTestEnvironmentMapper; + @Resource + private SqlSessionFactory sqlSessionFactory; public List list(TestPlanScenarioRequest request) { request.setProjectId(null); @@ -154,6 +159,9 @@ public class TestPlanScenarioCaseService { if (CollectionUtils.isEmpty(planCaseIdList)) { MSException.throwException("未找到执行场景!"); } + if (testPlanScenarioRequest.getConfig() != null && !testPlanScenarioRequest.getConfig().getEnvMap().isEmpty()) { + this.setScenarioEnv(planCaseIdList, testPlanScenarioRequest.getConfig().getEnvMap()); + } planCaseIdList.forEach(item -> { idStr.append("\"").append(item).append("\"").append(","); }); @@ -179,6 +187,36 @@ public class TestPlanScenarioCaseService { return apiAutomationService.run(request); } + private void setScenarioEnv(List planScenarioIds, Map envMap) { + if (CollectionUtils.isEmpty(planScenarioIds)) { + return; + } + TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample(); + testPlanApiScenarioExample.createCriteria().andIdIn(planScenarioIds); + List testPlanApiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(testPlanApiScenarioExample); + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + TestPlanApiScenarioMapper mapper = sqlSession.getMapper(TestPlanApiScenarioMapper.class); + for (TestPlanApiScenario testPlanApiScenario : testPlanApiScenarios) { + String env = testPlanApiScenario.getEnvironment(); + if (StringUtils.isBlank(env)) { + continue; + } + Map map = JSON.parseObject(env, Map.class); + if (map.isEmpty()) { + continue; + } + Set set = map.keySet(); + for (String s : set) { + if (StringUtils.isNotBlank(envMap.get(s))) { + map.put(s, envMap.get(s)); + } + } + testPlanApiScenario.setEnvironment(JSON.toJSONString(map)); + mapper.updateByPrimaryKeyWithBLOBs(testPlanApiScenario); + } + sqlSession.flushStatements(); + } + public List getCasesByPlanId(String planId) { TestPlanApiScenarioExample example = new TestPlanApiScenarioExample(); example.createCriteria().andTestPlanIdEqualTo(planId); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 6bfac16749..67609e4691 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -1302,6 +1302,42 @@ public class TestPlanService { return envMap; } + public Map> getApiScenarioEnv(List planApiScenarioIds) { + Map> envMap = new HashMap<>(); + if (CollectionUtils.isEmpty(planApiScenarioIds)) { + return envMap; + } + + TestPlanApiScenarioExample scenarioExample = new TestPlanApiScenarioExample(); + scenarioExample.createCriteria().andIdIn(planApiScenarioIds); + List testPlanApiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(scenarioExample); + + for (TestPlanApiScenario testPlanApiScenario : testPlanApiScenarios) { + String env = testPlanApiScenario.getEnvironment(); + if (StringUtils.isBlank(env)) { + continue; + } + Map map = JSON.parseObject(env, Map.class); + if (!map.isEmpty()) { + Set set = map.keySet(); + for (String s : set) { + String e = map.get(s); + if (envMap.containsKey(s)) { + List list = envMap.get(s); + if (!list.contains(e)) { + list.add(e); + } + } else { + List envs = new ArrayList<>(); + envs.add(e); + envMap.put(s, envs); + } + } + } + } + return envMap; + } + public void exportPlanReport(String planId, HttpServletResponse response) throws UnsupportedEncodingException { TestPlan testPlan = getTestPlan(planId); if (StringUtils.isBlank(testPlan.getReportId())) { diff --git a/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue b/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue index 4a2d03991d..b7b529c469 100644 --- a/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue +++ b/frontend/src/business/components/track/plan/common/PlanRunModeWithEnv.vue @@ -98,7 +98,7 @@ export default { projectIds: new Set(), }; }, - props: ['planCaseIds'], + props: ['planCaseIds', 'type'], methods: { open(testType) { this.runModeVisible = true; @@ -141,7 +141,13 @@ export default { }, showPopover() { this.projectIds.clear(); - this.$post('/test/plan/api/case/env', this.planCaseIds, res => { + let url = ""; + if (this.type === 'apiCase') { + url = '/test/plan/api/case/env'; + } else if (this.type === 'apiScenario') { + url = '/test/plan/api/scenario/env'; + } + this.$post(url, this.planCaseIds, res => { let data = res.data; if (data) { this.projectEnvListMap = data; @@ -150,7 +156,7 @@ export default { } } this.$refs.envPopover.openEnvSelect(); - }) + }); } }, }; diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue index 3db555c4c3..dbdd73d827 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiCaseList.vue @@ -145,7 +145,7 @@ - + diff --git a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue index 4b2021326c..7a4474e2d3 100644 --- a/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/api/TestPlanApiScenarioList.vue @@ -56,8 +56,12 @@ @@ -180,7 +184,7 @@ import { import {TEST_PLAN_SCENARIO_CASE} from "@/common/js/constants"; import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate"; import BatchEdit from "@/business/components/track/case/components/BatchEdit"; -import MsPlanRunMode from "../../../common/PlanRunMode"; +import MsPlanRunMode from "@/business/components/track/plan/common/PlanRunModeWithEnv"; import PriorityTableItem from "@/business/components/track/common/tableItems/planview/PriorityTableItem"; import {API_SCENARIO_FILTERS} from "@/common/js/table-constants"; import MsTaskCenter from "../../../../../task/TaskCenter"; @@ -275,6 +279,7 @@ export default { valueArr: { projectEnv: [] }, + planCaseIds: [] } }, computed: { @@ -373,6 +378,11 @@ export default { }) }, handleBatchExecute() { + let rows = this.orderBySelectRows(this.$refs.table.selectRows); + this.planCaseIds = []; + rows.forEach(row => { + this.planCaseIds.push(row.id); + }) this.$refs.runMode.open('API'); }, orderBySelectRows(rows){ @@ -409,9 +419,12 @@ export default { this.$post("/test/plan/scenario/case/run", param, response => { this.$message(this.$t('commons.run_message')); this.$refs.taskCenter.open(); + this.search(); + }, () => { + this.search(); }); } - this.search(); + }, execute(row) { this.infoDb = false; @@ -537,4 +550,13 @@ export default { margin-left: 5px; } +.project-name { + display: inline-block; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + width: 100px; + vertical-align: middle; +} +