From e86d09e7eb72e6d29b55f86903879c976eda6415 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 29 Aug 2022 15:49:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E5=85=AC=E5=85=B1=E7=94=A8=E4=BE=8B=E5=BA=93=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E4=B8=8D=E5=B1=95=E7=A4=BA=E8=87=AA=E5=AE=9A=E4=B9=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1016140 --user=陈建星 【测试跟踪】新建用例并保存到公共用例库,用例中有自定义字段,公共用例库列表不显示自定义字段的内容 https://www.tapd.cn/55049933/s/1233942 --- .../base/mapper/ext/ExtCustomFieldMapper.java | 2 + .../base/mapper/ext/ExtCustomFieldMapper.xml | 9 +- .../commons/constants/CustomFieldScene.java | 5 + .../service/CustomFieldService.java | 5 +- .../track/controller/TestCaseController.java | 2 +- .../track/service/TestCaseService.java | 45 +- .../project/template/CustomFiledComponent.vue | 3 + .../components/track/case/TestCase.vue | 14 +- .../track/case/components/TestCaseList.vue | 285 +--------- .../components/public/PublicTestCaseList.vue | 533 ++++++++++++++++++ .../src/common/js/default-table-header.js | 2 + frontend/src/common/js/table-constants.js | 7 + frontend/src/i18n/track/en-US.js | 1 + frontend/src/i18n/track/zh-CN.js | 1 + frontend/src/i18n/track/zh-TW.js | 1 + 15 files changed, 641 insertions(+), 274 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/commons/constants/CustomFieldScene.java create mode 100644 frontend/src/business/components/track/case/components/public/PublicTestCaseList.vue diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.java index 1bf88aea93..7e101aeba5 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.java @@ -15,4 +15,6 @@ public interface ExtCustomFieldMapper { List listIds(@Param("request") QueryCustomFieldRequest request); void batchInsert(@Param("customFields") List customFields); + + List getWorkspaceIdSystemFields(@Param("workspaceId") String workspaceId, @Param("scene") String scene); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.xml index ad4fd05c88..ef4bb9a9e0 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtCustomFieldMapper.xml @@ -40,8 +40,15 @@ + - + diff --git a/backend/src/main/java/io/metersphere/commons/constants/CustomFieldScene.java b/backend/src/main/java/io/metersphere/commons/constants/CustomFieldScene.java new file mode 100644 index 0000000000..99594acfa3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/constants/CustomFieldScene.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.constants; + +public enum CustomFieldScene { + TEST_CASE, ISSUE +} diff --git a/backend/src/main/java/io/metersphere/service/CustomFieldService.java b/backend/src/main/java/io/metersphere/service/CustomFieldService.java index 44fef654f2..bc7e080564 100644 --- a/backend/src/main/java/io/metersphere/service/CustomFieldService.java +++ b/backend/src/main/java/io/metersphere/service/CustomFieldService.java @@ -9,7 +9,6 @@ import io.metersphere.base.domain.*; import io.metersphere.base.domain.ext.CustomFieldResource; import io.metersphere.base.mapper.CustomFieldIssuesMapper; import io.metersphere.base.mapper.CustomFieldMapper; -import io.metersphere.base.mapper.CustomFieldTemplateMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.ExtCustomFieldMapper; import io.metersphere.commons.constants.CustomFieldType; @@ -235,6 +234,10 @@ public class CustomFieldService { return new ArrayList<>(); } + public List getWorkspaceIdSystemFields(String workspaceId, String scene) { + return extCustomFieldMapper.getWorkspaceIdSystemFields(workspaceId, scene); + } + public List getCustomFieldResource(String customFieldsStr) { List list = new ArrayList<>(); if (StringUtils.isNotBlank(customFieldsStr)) { 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 8a134fba7a..94897aeaa7 100644 --- a/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java +++ b/backend/src/main/java/io/metersphere/track/controller/TestCaseController.java @@ -66,7 +66,7 @@ public class TestCaseController { return PageUtils.setPageInfo(page, testCaseService.listTestCase(request)); } - @PostMapping("/publicList/{goPage}/{pageSize}") + @PostMapping("/public/list/{goPage}/{pageSize}") @RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ) public Pager> publicList(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestCaseRequest request) { Page page = PageHelper.startPage(goPage, pageSize, true); 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 386826dbc0..aac32eadbc 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -195,6 +195,8 @@ public class TestCaseService { @Resource @Lazy private TestCaseTemplateService testCaseTemplateService; + @Resource + private CustomFieldService customFieldService; private ThreadLocal importCreateNum = new ThreadLocal<>(); @@ -788,10 +790,51 @@ public class TestCaseService { ServiceUtils.buildVersionInfo(returnList); ServiceUtils.buildProjectInfo(returnList); buildUserInfo(returnList); - buildCustomField(returnList); + buildPublicCustomField(request, returnList); return returnList; } + private void buildPublicCustomField(QueryTestCaseRequest request, List returnList) { + Map> projectFieldMap = customFieldService.getWorkspaceIdSystemFields(request.getWorkspaceId(), CustomFieldScene.TEST_CASE.name()) + .stream().collect(Collectors.groupingBy(CustomField::getProjectId)); + + Map> projectStatusOptionMap = new HashMap<>(); + Map> projectPriorityOptionMap = new HashMap<>(); + projectFieldMap.forEach((projectId, fields) -> { + Map statusOptionMap = Optional.ofNullable(projectStatusOptionMap.get(projectId)).orElse(new HashMap<>()); + Map priorityOptionMap = Optional.ofNullable(projectPriorityOptionMap.get(projectId)).orElse(new HashMap<>()); + for (CustomField field : fields) { + if (field.getName().equals(TestCaseImportFiled.STATUS.getFiledLangMap().get(Locale.SIMPLIFIED_CHINESE))) { + if (StringUtils.isNotBlank(field.getOptions())) { + statusOptionMap = JSONArray.parseArray(field.getOptions(), CustomFieldOption.class) + .stream() + .collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText)); + } + } + if (field.getName().equals(TestCaseImportFiled.PRIORITY.getFiledLangMap().get(Locale.SIMPLIFIED_CHINESE))) { + if (StringUtils.isNotBlank(field.getOptions())) { + priorityOptionMap = JSONArray.parseArray(field.getOptions(), CustomFieldOption.class) + .stream() + .collect(Collectors.toMap(CustomFieldOption::getValue, CustomFieldOption::getText)); + } + } + } + projectStatusOptionMap.put(projectId, statusOptionMap); + projectPriorityOptionMap.put(projectId, priorityOptionMap); + }); + + returnList.forEach(testCase -> { + String status = projectStatusOptionMap.get(testCase.getProjectId()).get(testCase.getStatus()); + String priority = projectPriorityOptionMap.get(testCase.getProjectId()).get(testCase.getStatus()); + if (StringUtils.isNotBlank(status)) { + testCase.setStatus(status); + } + if (StringUtils.isNotBlank(priority)) { + testCase.setPriority(priority); + } + }); + } + public void setDefaultOrder(QueryTestCaseRequest request) { List orders = ServiceUtils.getDefaultSortOrder(request.getOrders()); diff --git a/frontend/src/business/components/project/template/CustomFiledComponent.vue b/frontend/src/business/components/project/template/CustomFiledComponent.vue index efab602ad6..013bcd8fb2 100644 --- a/frontend/src/business/components/project/template/CustomFiledComponent.vue +++ b/frontend/src/business/components/project/template/CustomFiledComponent.vue @@ -155,6 +155,9 @@ export default { } } } + if (this.data.type.indexOf("member") < 0) { + return; + } getProjectMemberOption((data) => { this.memberOptions = data; if (this.data.name === '责任人' && this.data.system && this.isTemplateEdit) { diff --git a/frontend/src/business/components/track/case/TestCase.vue b/frontend/src/business/components/track/case/TestCase.vue index cb189aa648..89d4768853 100644 --- a/frontend/src/business/components/track/case/TestCase.vue +++ b/frontend/src/business/components/track/case/TestCase.vue @@ -55,8 +55,6 @@ :version-enable="versionEnable" @testCaseEdit="editTestCase" @testCaseCopy="copyTestCase" - @getTrashList="getTrashList" - @getPublicList="getPublicList" @refresh="refreshTrashNode" @refreshAll="refreshAll" @setCondition="setCondition" @@ -67,26 +65,20 @@
- - +
0 ? requireComponent("./version/VersionSelect.vue") : {}; @@ -240,6 +233,7 @@ const VersionSelect = requireComponent.keys().length > 0 ? requireComponent("./v export default { name: "TestCase", components: { + PublicTestCaseList, TestCaseTrashNodeTree, TestCasePublicNodeTree, IsChangeConfirm, diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index 0c49061640..e822c9a7e0 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -50,14 +50,6 @@ - - -