From 09acd152f5f3cc705764e4f8f75d9128970eeba1 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 18 Aug 2022 12:00:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1008224 --user=陈建星 用例导出/导入支持自定义字段 https://www.tapd.cn/55049933/s/1225482 refactor(测试跟踪): ddd --story=1008224 --user=陈建星 用例导出/导入支持自定义字段 https://www.tapd.cn/55049933/s/1225482 --- .../constants/TestCaseCommentType.java | 16 ++++- .../constants/TestPlanTestCaseStatus.java | 17 ++++- .../constants/TestReviewCaseStatus.java | 14 +++- .../TestCaseExportCommendConverter.java | 20 +++--- .../TestCaseExportExecuteResultConverter.java | 8 +-- .../TestCaseExportReviewResultConverter.java | 6 +- .../FunctionCaseTemplateWriteHandler.java | 67 +++++++++---------- .../components/track/case/TestCase.vue | 6 ++ .../track/case/components/TestCaseList.vue | 13 ++-- .../case/components/export/TestCaseExport.vue | 13 +++- .../export/TestCaseExportFieldList.vue | 5 +- .../export/TestCaseExportFieldSelect.vue | 3 +- .../export/TestCaseExportFieldSelectItem.vue | 6 +- .../track/module/TestCaseNodeTree.vue | 3 + 14 files changed, 127 insertions(+), 70 deletions(-) diff --git a/backend/src/main/java/io/metersphere/commons/constants/TestCaseCommentType.java b/backend/src/main/java/io/metersphere/commons/constants/TestCaseCommentType.java index 11a59bc3a6..1e5b837aeb 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/TestCaseCommentType.java +++ b/backend/src/main/java/io/metersphere/commons/constants/TestCaseCommentType.java @@ -1,7 +1,17 @@ package io.metersphere.commons.constants; public enum TestCaseCommentType { - CASE, - REVIEW, - PLAN + CASE("test_case_comment"), + REVIEW("test_case_plan_comment"), + PLAN("test_case_review_comment"); + + private String i18nKey; + + TestCaseCommentType(String i18nKey) { + this.i18nKey = i18nKey; + } + + public String getI18nKey() { + return i18nKey; + } } diff --git a/backend/src/main/java/io/metersphere/commons/constants/TestPlanTestCaseStatus.java b/backend/src/main/java/io/metersphere/commons/constants/TestPlanTestCaseStatus.java index f11250442b..28603ab621 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/TestPlanTestCaseStatus.java +++ b/backend/src/main/java/io/metersphere/commons/constants/TestPlanTestCaseStatus.java @@ -1,5 +1,20 @@ package io.metersphere.commons.constants; public enum TestPlanTestCaseStatus { - Prepare, Pass, Failure, Blocking, Skip, Underway + Prepare("test_case_status_prepare"), + Pass("execute_pass"), + Failure("test_case_status_error"), + Blocking("plan_case_status_blocking"), + Skip("plan_case_status_skip"), + Underway("test_case_status_prepare"); + + private String i18nKey; + + TestPlanTestCaseStatus(String i18nKey) { + this.i18nKey = i18nKey; + } + + public String getI18nKey() { + return i18nKey; + } } diff --git a/backend/src/main/java/io/metersphere/commons/constants/TestReviewCaseStatus.java b/backend/src/main/java/io/metersphere/commons/constants/TestReviewCaseStatus.java index dca7fc23ff..1f93d19791 100644 --- a/backend/src/main/java/io/metersphere/commons/constants/TestReviewCaseStatus.java +++ b/backend/src/main/java/io/metersphere/commons/constants/TestReviewCaseStatus.java @@ -1,5 +1,17 @@ package io.metersphere.commons.constants; public enum TestReviewCaseStatus { - Prepare, Pass, UnPass + Prepare("test_case_status_prepare"), + Pass("execute_pass"), + UnPass("execute_not_pass"); + + private String i18nKey; + + TestReviewCaseStatus(String i18nKey) { + this.i18nKey = i18nKey; + } + + public String getI18nKey() { + return i18nKey; + } } diff --git a/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportCommendConverter.java b/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportCommendConverter.java index 52b27db160..aafc5a2f67 100644 --- a/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportCommendConverter.java +++ b/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportCommendConverter.java @@ -21,19 +21,17 @@ public class TestCaseExportCommendConverter implements TestCaseExportConverter { private HashMap reviewCaseStatusMap = new HashMap<>(); public TestCaseExportCommendConverter() { - commendTypeMap.put(TestCaseCommentType.CASE.name(), "test_case_comment"); - commendTypeMap.put(TestCaseCommentType.PLAN.name(), "test_case_plan_comment"); - commendTypeMap.put(TestCaseCommentType.REVIEW.name(), "test_case_review_comment"); + for (TestCaseCommentType value : TestCaseCommentType.values()) { + commendTypeMap.put(value.name(), value.getI18nKey()); + } - planCaseStatusMap.put(TestPlanTestCaseStatus.Pass.name(), "execute_pass"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Underway.name(), "test_case_status_prepare"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Blocking.name(), "plan_case_status_blocking"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Failure.name(), "test_case_status_error"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Skip.name(), "plan_case_status_skip"); + for (TestPlanTestCaseStatus value : TestPlanTestCaseStatus.values()) { + planCaseStatusMap.put(value.name(), value.getI18nKey()); + } - reviewCaseStatusMap.put(TestReviewCaseStatus.Prepare.name(), "test_case_status_prepare"); - reviewCaseStatusMap.put(TestReviewCaseStatus.Pass.name(), "execute_pass"); - reviewCaseStatusMap.put(TestReviewCaseStatus.UnPass.name(), "execute_not_pass"); + for (TestReviewCaseStatus value : TestReviewCaseStatus.values()) { + reviewCaseStatusMap.put(value.name(), value.getI18nKey()); + } } @Override diff --git a/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportExecuteResultConverter.java b/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportExecuteResultConverter.java index f4728a6d17..5149ebb2ce 100644 --- a/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportExecuteResultConverter.java +++ b/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportExecuteResultConverter.java @@ -11,11 +11,9 @@ public class TestCaseExportExecuteResultConverter implements TestCaseExportConve private Map planCaseStatusMap = new HashMap<>(); public TestCaseExportExecuteResultConverter() { - planCaseStatusMap.put(TestPlanTestCaseStatus.Pass.name(), "execute_pass"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Underway.name(), "test_case_status_prepare"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Blocking.name(), "plan_case_status_blocking"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Failure.name(), "test_case_status_error"); - planCaseStatusMap.put(TestPlanTestCaseStatus.Skip.name(), "plan_case_status_skip"); + for (TestPlanTestCaseStatus value : TestPlanTestCaseStatus.values()) { + planCaseStatusMap.put(value.name(), value.getI18nKey()); + } } @Override diff --git a/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportReviewResultConverter.java b/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportReviewResultConverter.java index 6af9d6a8d3..8041a9dd4c 100644 --- a/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportReviewResultConverter.java +++ b/backend/src/main/java/io/metersphere/excel/converter/TestCaseExportReviewResultConverter.java @@ -11,9 +11,9 @@ public class TestCaseExportReviewResultConverter implements TestCaseExportConver private Map reviewCaseStatusMap = new HashMap<>(); public TestCaseExportReviewResultConverter() { - reviewCaseStatusMap.put(TestReviewCaseStatus.Prepare.name(), "test_case_status_prepare"); - reviewCaseStatusMap.put(TestReviewCaseStatus.Pass.name(), "execute_pass"); - reviewCaseStatusMap.put(TestReviewCaseStatus.UnPass.name(), "execute_not_pass"); + for (TestReviewCaseStatus value : TestReviewCaseStatus.values()) { + reviewCaseStatusMap.put(value.name(), value.getI18nKey()); + } } @Override diff --git a/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java b/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java index 38de24f059..447b8466c9 100644 --- a/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java +++ b/backend/src/main/java/io/metersphere/excel/handler/FunctionCaseTemplateWriteHandler.java @@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONArray; import io.metersphere.excel.constants.TestCaseImportFiled; import io.metersphere.i18n.Translator; import org.apache.commons.collections.CollectionUtils; + +import org.apache.commons.collections.MapUtils; import org.apache.poi.ss.usermodel.Comment; import org.apache.poi.ss.usermodel.Drawing; import org.apache.poi.ss.usermodel.Sheet; @@ -14,7 +16,6 @@ import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -26,7 +27,6 @@ import java.util.Map; public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { private boolean isNeedId; - Map rowDisposeIndexMap; Map> caseLevelAndStatusValueMap; private Integer idIndex; @@ -37,15 +37,16 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { private Integer statusIndex; private Integer stepModelIndex; + private Sheet sheet; + private Drawing drawingPatriarch; + public FunctionCaseTemplateWriteHandler(boolean isNeedId, List> headList, Map> caseLevelAndStatusValueMap) { this.isNeedId = isNeedId; - rowDisposeIndexMap = this.buildFiledMap(headList); + this.initIndex(headList); this.caseLevelAndStatusValueMap = caseLevelAndStatusValueMap; } - private Map buildFiledMap(List> headList) { - Map returnMap = new HashMap<>(); - + private void initIndex(List> headList) { int index = 0; for (List list : headList) { for (String head : list) { @@ -67,48 +68,46 @@ public class FunctionCaseTemplateWriteHandler implements RowWriteHandler { index++; } } - return returnMap; } @Override public void afterRowDispose(RowWriteHandlerContext context) { if (BooleanUtils.isTrue(context.getHead())) { - Sheet sheet = context.getWriteSheetHolder().getSheet(); - Drawing drawingPatriarch = sheet.createDrawingPatriarch(); + sheet = context.getWriteSheetHolder().getSheet(); + drawingPatriarch = sheet.createDrawingPatriarch(); - if (rowDisposeIndexMap != null) { - if (isNeedId) { - setComment(sheet, drawingPatriarch, idIndex, Translator.get("do_not_modify_header_order") + "," + Translator.get("id_required")); - } + if (isNeedId) { + setComment(idIndex, Translator.get("do_not_modify_header_order").concat(",").concat(Translator.get("id_required"))); + } - setComment(sheet, drawingPatriarch, moduleIndex, Translator.get("module_created_automatically")); - setComment(sheet, drawingPatriarch, maintainerIndex, Translator.get("please_input_project_member")); - setComment(sheet, drawingPatriarch, tagIndex, Translator.get("tag_tip_pattern")); - setComment(sheet, drawingPatriarch, stepModelIndex, Translator.get("step_model_tip")); + setComment(moduleIndex, Translator.get("module_created_automatically")); + setComment(maintainerIndex, Translator.get("please_input_project_member")); + setComment(tagIndex, Translator.get("tag_tip_pattern")); + setComment(stepModelIndex, Translator.get("step_model_tip")); - List list = new ArrayList<>(); - if (caseLevelAndStatusValueMap != null && caseLevelAndStatusValueMap.containsKey("caseLevel")) { - list = caseLevelAndStatusValueMap.get("caseLevel"); - } - if (CollectionUtils.isEmpty(list)) { - setComment(sheet, drawingPatriarch, priorityIndex, Translator.get("options") + "(P0、P1、P2、P3)"); - } else { - setComment(sheet, drawingPatriarch, priorityIndex, Translator.get("options") + JSONArray.toJSONString(list)); - } + List list = new ArrayList<>(); + if (MapUtils.isNotEmpty(caseLevelAndStatusValueMap) && caseLevelAndStatusValueMap.containsKey("caseLevel")) { + list = caseLevelAndStatusValueMap.get("caseLevel"); + } + if (CollectionUtils.isEmpty(list)) { + setComment(priorityIndex, Translator.get("options").concat("(P0、P1、P2、P3)")); + } else { + setComment(priorityIndex, Translator.get("options").concat(JSONArray.toJSONString(list))); + } - list.clear(); - if (caseLevelAndStatusValueMap != null && caseLevelAndStatusValueMap.containsKey("caseStatus")) { - list = caseLevelAndStatusValueMap.get("caseStatus"); - } - if (CollectionUtils.isNotEmpty(list)) { - setComment(sheet, drawingPatriarch, statusIndex, Translator.get("options") + JSONArray.toJSONString(list)); - } + list.clear(); + if (MapUtils.isNotEmpty(caseLevelAndStatusValueMap) && caseLevelAndStatusValueMap.containsKey("caseStatus")) { + list = caseLevelAndStatusValueMap.get("caseStatus"); + } + if (CollectionUtils.isNotEmpty(list)) { + setComment(statusIndex, Translator.get("options").concat(JSONArray.toJSONString(list))); } } + } - private void setComment(Sheet sheet, Drawing drawingPatriarch, Integer index, String text) { + private void setComment(Integer index, String text) { if (index == null) { return; } diff --git a/frontend/src/business/components/track/case/TestCase.vue b/frontend/src/business/components/track/case/TestCase.vue index f54a324f6b..1f374add7b 100644 --- a/frontend/src/business/components/track/case/TestCase.vue +++ b/frontend/src/business/components/track/case/TestCase.vue @@ -8,6 +8,7 @@ :show-operator="true" :public-total="publicTotal" :case-condition="condition" + @handleExportCheck="handleExportCheck" @refreshTable="refresh" @setTreeNodes="setTreeNodes" @exportTestCase="exportTestCase" @@ -585,6 +586,11 @@ export default { this.activeName = "default"; } }, + handleExportCheck() { + if (this.$refs.testCaseList.checkSelected()) { + this.$refs.nodeTree.openExport(); + } + }, exportTestCase(type, param) { if (this.activeDom !== 'left') { this.$warning(this.$t('test_track.case.export.export_tip')); diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index dd682283ee..1a37d9655b 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -1041,11 +1041,6 @@ export default { fileNameSuffix = ".xlsx"; } - if (config.data.ids === undefined || config.data.ids.length < 1) { - this.$warning(this.$t("test_track.case.check_select")); - return; - } - this.page.result = this.$request(config).then(response => { const filename = "Metersphere_case_" + this.projectName + fileNameSuffix; const blob = new Blob([response.data]); @@ -1198,6 +1193,14 @@ export default { } }, + checkSelected() { + let selectIds = this.$refs.table.selectIds; + if (!selectIds || selectIds.length < 1) { + this.$warning(this.$t("test_track.case.check_select")); + return false; + } + return true; + }, getMaintainerOptions() { this.$get('/user/project/member/list', response => { this.valueArr.maintainer = response.data; diff --git a/frontend/src/business/components/track/case/components/export/TestCaseExport.vue b/frontend/src/business/components/track/case/components/export/TestCaseExport.vue index 158bee6006..599f58a3fe 100644 --- a/frontend/src/business/components/track/case/components/export/TestCaseExport.vue +++ b/frontend/src/business/components/track/case/components/export/TestCaseExport.vue @@ -1,5 +1,8 @@