From cd60ef9be8b01c353f2341feec5dbe36d87a3658 Mon Sep 17 00:00:00 2001 From: wenyann <64353056+wenyann@users.noreply.github.com> Date: Tue, 14 Jul 2020 10:15:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=AF=BC?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtTestCaseMapper.java | 2 + .../base/mapper/ext/ExtTestCaseMapper.xml | 11 +++ .../track/controller/TestCaseController.java | 5 ++ .../io/metersphere/track/dto/TestCaseDTO.java | 4 +- .../testcase/QueryTestCaseRequest.java | 2 + .../track/service/TestCaseService.java | 79 +++++++++++++++++-- .../track/case/components/TestCaseExport.vue | 20 +++-- .../track/case/components/TestCaseList.vue | 34 ++++++-- 8 files changed, 141 insertions(+), 16 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java index 7a1aa58b2b..1fab9ae1fc 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.java @@ -15,4 +15,6 @@ public interface ExtTestCaseMapper { List listByMethod(@Param("request") QueryTestCaseRequest request); + List listBytestCaseIds(@Param("request") QueryTestCaseRequest request); + } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml index 8f5cf65ed5..fe7b7dceb7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtTestCaseMapper.xml @@ -80,4 +80,15 @@ + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java index 63d075366d..2e24659650 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java @@ -109,6 +109,11 @@ public class TestCaseController { public void testCaseTemplateExport(HttpServletResponse response){ testCaseService.testCaseTemplateExport(response); } + @GetMapping("/export/testCase/{testCaseIds}") + @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + public void testCaseExport(HttpServletResponse response,QueryTestCaseRequest request){ + testCaseService.testCaseExport(response,request); + } @PostMapping("/batch/edit") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) diff --git a/backend/src/main/java/io/metersphere/track/dto/TestCaseDTO.java b/backend/src/main/java/io/metersphere/track/dto/TestCaseDTO.java index 3bdd50fa3c..bd63bd8863 100644 --- a/backend/src/main/java/io/metersphere/track/dto/TestCaseDTO.java +++ b/backend/src/main/java/io/metersphere/track/dto/TestCaseDTO.java @@ -6,8 +6,10 @@ import lombok.Setter; @Getter @Setter -public class TestCaseDTO extends TestCaseWithBLOBs{ +public class TestCaseDTO extends TestCaseWithBLOBs { private String maintainerName; + private String apiName; + private String performName; } diff --git a/backend/src/main/java/io/metersphere/track/request/testcase/QueryTestCaseRequest.java b/backend/src/main/java/io/metersphere/track/request/testcase/QueryTestCaseRequest.java index 3f6c41cd72..0863257cbf 100644 --- a/backend/src/main/java/io/metersphere/track/request/testcase/QueryTestCaseRequest.java +++ b/backend/src/main/java/io/metersphere/track/request/testcase/QueryTestCaseRequest.java @@ -16,6 +16,8 @@ public class QueryTestCaseRequest extends TestCase { private List nodeIds; + private List testCaseIds; + private List orders; private Map> filters; diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 628cb9bf95..d07607b377 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -2,6 +2,8 @@ package io.metersphere.track.service; import com.alibaba.excel.EasyExcelFactory; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; @@ -101,7 +103,7 @@ public class TestCaseService { return testCaseMapper.updateByPrimaryKeySelective(testCase); } - private void checkTestCaseExist (TestCaseWithBLOBs testCase) { + private void checkTestCaseExist(TestCaseWithBLOBs testCase) { if (testCase.getName() != null) { TestCaseExample example = new TestCaseExample(); example.createCriteria() @@ -154,7 +156,7 @@ public class TestCaseService { List testCaseNames = extTestCaseMapper.getTestCaseNames(request); - if ( StringUtils.isNotBlank(request.getPlanId()) ) { + if (StringUtils.isNotBlank(request.getPlanId())) { TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(request.getPlanId()); List relevanceIds = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample).stream() @@ -284,9 +286,9 @@ public class TestCaseService { data.setName(Translator.get("test_case") + i); path.append("/" + Translator.get("module") + i); data.setNodePath(path.toString()); - data.setPriority("P" + i%4); - data.setType(types.get(i%3)); - data.setMethod(methods.get(i%2)); + data.setPriority("P" + i % 4); + data.setType(types.get(i % 3)); + data.setMethod(methods.get(i % 2)); data.setPrerequisite(Translator.get("preconditions_optional")); data.setStepDesc("1. " + Translator.get("step_tip_separate") + "\n2. " + Translator.get("step_tip_order") + "\n3. " + Translator.get("step_tip_optional")); @@ -309,6 +311,73 @@ public class TestCaseService { return list; } + public void testCaseExport(HttpServletResponse response, QueryTestCaseRequest request) { + EasyExcelExporter easyExcelExporter = null; + try { + easyExcelExporter = new EasyExcelExporter(TestCaseExcelData.class); + easyExcelExporter.export(response, generateTestCaseExcel(request), + Translator.get("test_case_import_template_name"), Translator.get("test_case_import_template_sheet")); + } catch (Exception e) { + MSException.throwException(e); + } finally { + easyExcelExporter.close(); + } + } + + private List generateTestCaseExcel(QueryTestCaseRequest request) { + List TestCaseList = extTestCaseMapper.listBytestCaseIds(request); + List list = new ArrayList<>(); + SessionUser user = SessionUtils.getUser(); + StringBuilder step = new StringBuilder(""); + StringBuilder result = new StringBuilder(""); + for (int i = 0; i < TestCaseList.size(); i++) { + TestCaseExcelData data = new TestCaseExcelData(); + data.setName(TestCaseList.get(i).getName()); + data.setNodePath(TestCaseList.get(i).getNodePath()); + data.setPriority(TestCaseList.get(i).getPriority()); + data.setType(TestCaseList.get(i).getType()); + data.setMethod(TestCaseList.get(i).getMethod()); + data.setPrerequisite(TestCaseList.get(i).getPrerequisite()); + if (TestCaseList.get(i).getMethod().equals("manual")) { + String steps = TestCaseList.get(i).getSteps(); + JSONArray jsonArray = JSON.parseArray(steps); + for (int j = 0; j
- - - + + {{$t('test_track.case.import.download_case')}} + +
+