From d511800cc87630357bb3bd1df35fb29b5de4bc3b Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Wed, 6 May 2020 20:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E7=BC=96=E8=BE=91=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TestCaseReportController.java | 5 +- .../TestCaseReportTemplateController.java | 3 +- .../controller/TestPlanController.java | 2 +- .../testCaseReport/CreateReportRequest.java | 9 + .../testCaseReport/QueryTemplateRequest.java | 9 + .../service/TestCaseReportService.java | 26 +++ .../TestCaseReportTemplateService.java | 15 +- .../metersphere/service/TestPlanService.java | 6 +- .../workspace/TestCaseReportTemplate.vue | 6 +- .../components/TestCaseReportTemplateEdit.vue | 27 ++- .../view/comonents/TestCaseReportView.vue | 148 ++++++++++++ .../view/comonents/TestPlanTestCaseList.vue | 218 ++++++++++-------- .../view/comonents/TestReportTemplateList.vue | 65 ++++++ 13 files changed, 418 insertions(+), 121 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/controller/request/testCaseReport/CreateReportRequest.java create mode 100644 backend/src/main/java/io/metersphere/controller/request/testCaseReport/QueryTemplateRequest.java create mode 100644 frontend/src/business/components/track/plan/view/comonents/TestCaseReportView.vue create mode 100644 frontend/src/business/components/track/plan/view/comonents/TestReportTemplateList.vue diff --git a/backend/src/main/java/io/metersphere/controller/TestCaseReportController.java b/backend/src/main/java/io/metersphere/controller/TestCaseReportController.java index 5d527b750b..bae1fbe671 100644 --- a/backend/src/main/java/io/metersphere/controller/TestCaseReportController.java +++ b/backend/src/main/java/io/metersphere/controller/TestCaseReportController.java @@ -1,6 +1,7 @@ package io.metersphere.controller; import io.metersphere.base.domain.TestCaseReport; +import io.metersphere.controller.request.testCaseReport.CreateReportRequest; import io.metersphere.service.TestCaseReportService; import org.springframework.web.bind.annotation.*; @@ -25,8 +26,8 @@ public class TestCaseReportController { } @PostMapping("/add") - public void add(@RequestBody TestCaseReport TestCaseReport){ - testCaseReportService.addTestCaseReport(TestCaseReport); + public Long addByTemplateId(@RequestBody CreateReportRequest request){ + return testCaseReportService.addTestCaseReportByTemplateId(request); } @PostMapping("/edit") diff --git a/backend/src/main/java/io/metersphere/controller/TestCaseReportTemplateController.java b/backend/src/main/java/io/metersphere/controller/TestCaseReportTemplateController.java index b090d7f77f..1d554f9fa5 100644 --- a/backend/src/main/java/io/metersphere/controller/TestCaseReportTemplateController.java +++ b/backend/src/main/java/io/metersphere/controller/TestCaseReportTemplateController.java @@ -1,6 +1,7 @@ package io.metersphere.controller; import io.metersphere.base.domain.TestCaseReportTemplate; +import io.metersphere.controller.request.testCaseReport.QueryTemplateRequest; import io.metersphere.service.TestCaseReportTemplateService; import org.springframework.web.bind.annotation.*; @@ -15,7 +16,7 @@ public class TestCaseReportTemplateController { TestCaseReportTemplateService testCaseReportTemplateService; @PostMapping("/list") - public List list(@RequestBody TestCaseReportTemplate request) { + public List list(@RequestBody QueryTemplateRequest request) { return testCaseReportTemplateService.listTestCaseReportTemplate(request); } diff --git a/backend/src/main/java/io/metersphere/controller/TestPlanController.java b/backend/src/main/java/io/metersphere/controller/TestPlanController.java index dbfa8375a4..4530ebbfdb 100644 --- a/backend/src/main/java/io/metersphere/controller/TestPlanController.java +++ b/backend/src/main/java/io/metersphere/controller/TestPlanController.java @@ -49,7 +49,7 @@ public class TestPlanController { } @PostMapping("/get/{testPlanId}") - public List getTestPlan(@PathVariable String testPlanId){ + public TestPlan getTestPlan(@PathVariable String testPlanId){ return testPlanService.getTestPlan(testPlanId); } diff --git a/backend/src/main/java/io/metersphere/controller/request/testCaseReport/CreateReportRequest.java b/backend/src/main/java/io/metersphere/controller/request/testCaseReport/CreateReportRequest.java new file mode 100644 index 0000000000..507898ebce --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/testCaseReport/CreateReportRequest.java @@ -0,0 +1,9 @@ +package io.metersphere.controller.request.testCaseReport; + +import lombok.Data; + +@Data +public class CreateReportRequest { + String planId; + Long templateId; +} diff --git a/backend/src/main/java/io/metersphere/controller/request/testCaseReport/QueryTemplateRequest.java b/backend/src/main/java/io/metersphere/controller/request/testCaseReport/QueryTemplateRequest.java new file mode 100644 index 0000000000..d3bcb50929 --- /dev/null +++ b/backend/src/main/java/io/metersphere/controller/request/testCaseReport/QueryTemplateRequest.java @@ -0,0 +1,9 @@ +package io.metersphere.controller.request.testCaseReport; + +import io.metersphere.base.domain.TestCaseReportTemplate; +import lombok.Data; + +@Data +public class QueryTemplateRequest extends TestCaseReportTemplate { + Boolean queryDefault; +} diff --git a/backend/src/main/java/io/metersphere/service/TestCaseReportService.java b/backend/src/main/java/io/metersphere/service/TestCaseReportService.java index 3cd5961fc5..ac8856b099 100644 --- a/backend/src/main/java/io/metersphere/service/TestCaseReportService.java +++ b/backend/src/main/java/io/metersphere/service/TestCaseReportService.java @@ -2,7 +2,13 @@ package io.metersphere.service; import io.metersphere.base.domain.TestCaseReport; import io.metersphere.base.domain.TestCaseReportExample; +import io.metersphere.base.domain.TestCaseReportTemplate; +import io.metersphere.base.domain.TestPlan; import io.metersphere.base.mapper.TestCaseReportMapper; +import io.metersphere.base.mapper.TestCaseReportTemplateMapper; +import io.metersphere.base.mapper.TestPlanMapper; +import io.metersphere.commons.utils.BeanUtils; +import io.metersphere.controller.request.testCaseReport.CreateReportRequest; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,6 +23,12 @@ public class TestCaseReportService { @Resource TestCaseReportMapper testCaseReportMapper; + @Resource + TestPlanMapper testPlanMapper; + + @Resource + TestCaseReportTemplateMapper testCaseReportTemplateMapper; + public List listTestCaseReport(TestCaseReport request) { TestCaseReportExample example = new TestCaseReportExample(); if ( StringUtils.isNotBlank(request.getName()) ) { @@ -40,4 +52,18 @@ public class TestCaseReportService { public int deleteTestCaseReport(Long id) { return testCaseReportMapper.deleteByPrimaryKey(id); } + + public Long addTestCaseReportByTemplateId(CreateReportRequest request) { + TestCaseReportTemplate template = testCaseReportTemplateMapper.selectByPrimaryKey(request.getTemplateId()); + TestCaseReport report = new TestCaseReport(); + BeanUtils.copyBean(report, template); + TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId()); + report.setName(testPlan.getName()); + report.setId(null); + testCaseReportMapper.insert(report); + testPlan.setReportId(report.getId()); + testPlanMapper.updateByPrimaryKeySelective(testPlan); + return report.getId(); + } + } diff --git a/backend/src/main/java/io/metersphere/service/TestCaseReportTemplateService.java b/backend/src/main/java/io/metersphere/service/TestCaseReportTemplateService.java index 59ee2c6e32..bfa7a28b05 100644 --- a/backend/src/main/java/io/metersphere/service/TestCaseReportTemplateService.java +++ b/backend/src/main/java/io/metersphere/service/TestCaseReportTemplateService.java @@ -4,6 +4,7 @@ import io.metersphere.base.domain.TestCaseReportTemplate; import io.metersphere.base.domain.TestCaseReportTemplateExample; import io.metersphere.base.mapper.TestCaseReportMapper; import io.metersphere.base.mapper.TestCaseReportTemplateMapper; +import io.metersphere.controller.request.testCaseReport.QueryTemplateRequest; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,15 +19,21 @@ public class TestCaseReportTemplateService { @Resource TestCaseReportTemplateMapper testCaseReportTemplateMapper; - public List listTestCaseReportTemplate(TestCaseReportTemplate request) { + public List listTestCaseReportTemplate(QueryTemplateRequest request) { TestCaseReportTemplateExample example = new TestCaseReportTemplateExample(); + TestCaseReportTemplateExample.Criteria criteria1 = example.createCriteria(); + TestCaseReportTemplateExample.Criteria criteria2 = example.createCriteria(); if ( StringUtils.isNotBlank(request.getName()) ) { - example.createCriteria().andNameEqualTo(request.getName()); + criteria1.andNameLike("%" + request.getName() + "%"); + criteria2.andNameLike("%" + request.getName() + "%"); } if ( StringUtils.isNotBlank(request.getWorkspaceId()) ) { - example.createCriteria().andWorkspaceIdEqualTo(request.getWorkspaceId()); + criteria1.andWorkspaceIdEqualTo(request.getWorkspaceId()); + } + if (request.getQueryDefault() != null) { + criteria2.andWorkspaceIdIsNull(); + example.or(criteria2); } - example.or(example.createCriteria().andWorkspaceIdIsNull()); return testCaseReportTemplateMapper.selectByExample(example); } diff --git a/backend/src/main/java/io/metersphere/service/TestPlanService.java b/backend/src/main/java/io/metersphere/service/TestPlanService.java index d4ed46e38c..957aa11002 100644 --- a/backend/src/main/java/io/metersphere/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/service/TestPlanService.java @@ -53,10 +53,8 @@ public class TestPlanService { } - public List getTestPlan(String testPlanId) { - TestPlanExample testPlanExample = new TestPlanExample(); - testPlanExample.createCriteria().andIdEqualTo(testPlanId); - return testPlanMapper.selectByExampleWithBLOBs(testPlanExample); + public TestPlan getTestPlan(String testPlanId) { + return testPlanMapper.selectByPrimaryKey(testPlanId); } public int editTestPlan(TestPlan testPlan) { diff --git a/frontend/src/business/components/settings/workspace/TestCaseReportTemplate.vue b/frontend/src/business/components/settings/workspace/TestCaseReportTemplate.vue index d8d1b63aa5..37937b9171 100644 --- a/frontend/src/business/components/settings/workspace/TestCaseReportTemplate.vue +++ b/frontend/src/business/components/settings/workspace/TestCaseReportTemplate.vue @@ -56,9 +56,6 @@ this.result = this.$post('/case/report/template/list', this.condition, response => { this.templates = response.data; }); - }, - templateCreate() { - }, templateEdit(id) { this.$refs.templateEdit.open(id); @@ -69,5 +66,8 @@ diff --git a/frontend/src/business/components/settings/workspace/components/TestCaseReportTemplateEdit.vue b/frontend/src/business/components/settings/workspace/components/TestCaseReportTemplateEdit.vue index 6e9bb36952..7fa78a3233 100644 --- a/frontend/src/business/components/settings/workspace/components/TestCaseReportTemplateEdit.vue +++ b/frontend/src/business/components/settings/workspace/components/TestCaseReportTemplateEdit.vue @@ -89,16 +89,15 @@ ), components: [4], previews: [], - template: {} + template: {}, + isReport: false } }, - props: { - - }, - watch: { - }, methods: { - open(id) { + open(id, isReport) { + if (isReport) { + this.isReport = isReport; + } this.template = { name: '', content: { @@ -190,7 +189,11 @@ } }, getTemplateById(id) { - this.$get('/case/report/template/get/' + id, (response) =>{ + let url = '/case/report/template/get/'; + if (this.isReport) { + url = '/case/report/get/'; + } + this.$get(url + id, (response) =>{ this.template = response.data; this.template.content = JSON.parse(response.data.content); if (this.template.content.customComponent) { @@ -206,7 +209,11 @@ } let param = {}; this.buildParam(param); - this.$post('/case/report/template/' + this.type, param, () =>{ + let url = '/case/report/template/'; + if (this.isReport) { + url = '/case/report/'; + } + this.$post(url + this.type, param, () =>{ this.$success('保存成功'); this.showDialog = false; this.$emit('refresh'); @@ -229,6 +236,8 @@ param.content = JSON.stringify(content); if (this.type == 'edit') { param.id = this.template.id; + } else { + param.workspaceId = localStorage.getItem(WORKSPACE_ID); } if (this.template.workspaceId) { param.workspaceId = localStorage.getItem(WORKSPACE_ID); diff --git a/frontend/src/business/components/track/plan/view/comonents/TestCaseReportView.vue b/frontend/src/business/components/track/plan/view/comonents/TestCaseReportView.vue new file mode 100644 index 0000000000..e1163bb9c2 --- /dev/null +++ b/frontend/src/business/components/track/plan/view/comonents/TestCaseReportView.vue @@ -0,0 +1,148 @@ + + + + + diff --git a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue index 61bad9ab30..ed7ac849f8 100644 --- a/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue +++ b/frontend/src/business/components/track/plan/view/comonents/TestPlanTestCaseList.vue @@ -1,111 +1,115 @@ @@ -128,10 +132,14 @@ import MethodTableItem from "../../../common/tableItems/planview/MethodTableItem"; import MsTableOperator from "../../../../common/components/MsTableOperator"; import MsTableOperatorButton from "../../../../common/components/MsTableOperatorButton"; + import TestReportTemplateList from "./TestReportTemplateList"; + import TestCaseReportView from "./TestCaseReportView"; export default { name: "TestPlanTestCaseList", components: { + TestCaseReportView, + TestReportTemplateList, MsTableOperatorButton, MsTableOperator, MethodTableItem, @@ -150,6 +158,7 @@ pageSize: 10, total: 0, selectIds: new Set(), + testPlan: {}, priorityFilters: [ {text: 'P0', value: 'P0'}, {text: 'P1', value: 'P1'}, @@ -186,13 +195,15 @@ }, watch: { planId() { + this.getTestPlanById(); this.initTableData(); }, selectNodeIds() { this.search(); } }, - created: function () { + mounted() { + this.getTestPlanById(); this.initTableData(); }, methods: { @@ -281,7 +292,20 @@ return row[property] === value; }, openTestReport() { - + this.$refs.testReporTtemplateList.open(); + }, + getTestPlanById() { + if (this.planId) { + this.$post('/test/plan/get/' + this.planId, {}, response => { + this.testPlan = response.data; + }); + } + }, + openReport(id) { + if (!id) { + id = this.testPlan.reportId; + } + this.$refs.testCaseReportView.open(id); } } } diff --git a/frontend/src/business/components/track/plan/view/comonents/TestReportTemplateList.vue b/frontend/src/business/components/track/plan/view/comonents/TestReportTemplateList.vue new file mode 100644 index 0000000000..79c20c5ee8 --- /dev/null +++ b/frontend/src/business/components/track/plan/view/comonents/TestReportTemplateList.vue @@ -0,0 +1,65 @@ + + + + +