diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java index 80f02a3f3d..534394087d 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseFileService.java @@ -210,7 +210,7 @@ public class FunctionalCaseFileService { return list; } - private Map> getCustomFieldOptionsMap(List customFields) { + public Map> getCustomFieldOptionsMap(List customFields) { Map> returnMap = new HashMap<>(); customFields.forEach(item -> { List values = getOptionValues(Optional.ofNullable(item.getOptions()).orElse(new ArrayList<>())); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java index ca963fb38e..3e1ec58f79 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/FunctionalCaseXmindService.java @@ -15,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional; import java.io.InputStream; import java.util.List; +import java.util.Map; /** * @author wx @@ -31,11 +32,13 @@ public class FunctionalCaseXmindService { public void downloadXmindTemplate(String projectId, HttpServletResponse response) { List customFields = functionalCaseFileService.getCustomFields(projectId); + //默认字段+自定义字段的 options集合 + Map> customFieldOptionsMap = functionalCaseFileService.getCustomFieldOptionsMap(customFields); try (InputStream stream = FunctionalCaseXmindService.class.getResourceAsStream(template)) { FunctionalCaseXmindData functionalCaseXmindData = JSON.parseObject(stream, FunctionalCaseXmindData.class); setTemplateCustomFields(functionalCaseXmindData.getChildren(), customFields); - XmindExportUtil.downloadTemplate(response, functionalCaseXmindData, true); + XmindExportUtil.downloadTemplate(response, functionalCaseXmindData, true, customFieldOptionsMap); } catch (Exception e) { LogUtils.error(e.getMessage()); diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/utils/XmindExportUtil.java b/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/utils/XmindExportUtil.java index 4e9711d6bd..354dbe14a9 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/utils/XmindExportUtil.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/xmind/utils/XmindExportUtil.java @@ -3,10 +3,12 @@ package io.metersphere.functional.xmind.utils; import io.metersphere.functional.constants.FunctionalCaseTypeConstants; import io.metersphere.functional.xmind.domain.FunctionalCaseXmindDTO; import io.metersphere.functional.xmind.domain.FunctionalCaseXmindData; +import io.metersphere.sdk.constants.CustomFieldType; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -34,8 +36,8 @@ public class XmindExportUtil { * @param caseData * @param template */ - public static void downloadTemplate(HttpServletResponse response, FunctionalCaseXmindData caseData, boolean template) { - IWorkbook workBook = createXmindByCaseData(caseData, template); + public static void downloadTemplate(HttpServletResponse response, FunctionalCaseXmindData caseData, boolean template, Map> customFieldOptionsMap) { + IWorkbook workBook = createXmindByCaseData(caseData, template, customFieldOptionsMap); response.setContentType("application/octet-stream"); response.setCharacterEncoding(StandardCharsets.UTF_8.name()); @@ -51,7 +53,7 @@ public class XmindExportUtil { } } - private static IWorkbook createXmindByCaseData(FunctionalCaseXmindData caseData, boolean template) { + private static IWorkbook createXmindByCaseData(FunctionalCaseXmindData caseData, boolean template, Map> customFieldOptionsMap) { // 创建思维导图的工作空间 IWorkbookBuilder workbookBuilder = Core.getWorkbookBuilder(); IWorkbook workbook = workbookBuilder.createWorkbook(); @@ -73,13 +75,14 @@ public class XmindExportUtil { if (CollectionUtils.isNotEmpty(caseData.getChildren())) { for (FunctionalCaseXmindData data : caseData.getChildren()) { - addItemTopic(rootTopic, workbook, styleMap, data, true, template); + addItemTopic(rootTopic, workbook, styleMap, data, true, template, customFieldOptionsMap); } } return workbook; } - private static void addItemTopic(ITopic parentTpoic, IWorkbook workbook, Map styleMap, FunctionalCaseXmindData xmindData, boolean isFirstLevel, boolean template) { + private static void addItemTopic(ITopic parentTpoic, IWorkbook workbook, Map styleMap, FunctionalCaseXmindData xmindData, + boolean isFirstLevel, boolean template, Map> customFieldOptionsMap) { ITopic topic = workbook.createTopic(); topic.setTitleText(xmindData.getModuleName()); if (isFirstLevel) { @@ -106,27 +109,30 @@ public class XmindExportUtil { } if (template) { // 模板 - buildTemplateTopic(topic, style, dto, itemTopic, workbook); + buildTemplateTopic(topic, style, dto, itemTopic, workbook, customFieldOptionsMap); } } } if (CollectionUtils.isNotEmpty(xmindData.getChildren())) { for (FunctionalCaseXmindData data : xmindData.getChildren()) { - addItemTopic(topic, workbook, styleMap, data, false, template); + addItemTopic(topic, workbook, styleMap, data, false, template, customFieldOptionsMap); } } } - private static void buildTemplateTopic(ITopic topic, IStyle style, FunctionalCaseXmindDTO dto, ITopic itemTopic, IWorkbook workbook) { + private static void buildTemplateTopic(ITopic topic, IStyle style, FunctionalCaseXmindDTO dto, ITopic itemTopic, IWorkbook workbook,Map> customFieldOptionsMap) { //用例名称 - itemTopic.setTitleText("case-P0: " + dto.getName()); + TemplateCustomFieldDTO priorityDto = dto.getTemplateCustomFieldDTOList().stream().filter(item -> StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))).findFirst().get(); + String priority = Translator.get("custom_field.functional_priority").concat(":").concat(Translator.get("required")).concat(", ").concat(Translator.get("options")).concat(JSON.toJSONString(customFieldOptionsMap.get(priorityDto.getFieldName()))); + String name = Translator.get("case.export.system.columns.name").concat(", ").concat(Translator.get("required")); + itemTopic.setTitleText("case-P0: ".concat(dto.getName()).concat(" ").concat(priority).concat(name)); //前置条件 if (StringUtils.isNotBlank(dto.getPrerequisite())) { ITopic preTopic = workbook.createTopic(); - preTopic.setTitleText(Translator.get("xmind_prerequisite") + ": " + dto.getPrerequisite()); + preTopic.setTitleText(Translator.get("xmind_prerequisite").concat(": ").concat(dto.getPrerequisite())); if (style != null) { preTopic.setStyleId(style.getId()); } @@ -136,7 +142,7 @@ public class XmindExportUtil { //备注 if (StringUtils.isNotBlank(dto.getDescription())) { ITopic deTopic = workbook.createTopic(); - deTopic.setTitleText(Translator.get("xmind_description") + ": " + dto.getDescription()); + deTopic.setTitleText(Translator.get("xmind_description").concat(": ").concat(dto.getDescription())); if (style != null) { deTopic.setStyleId(style.getId()); } @@ -146,16 +152,8 @@ public class XmindExportUtil { //标签 if (StringUtils.isNotBlank(dto.getTags())) { try { - List arr = JSON.parseArray(dto.getTags()); - String tagStr = StringUtils.EMPTY; - for (int i = 0; i < arr.size(); i++) { - tagStr = tagStr + arr.get(i) + "|"; - } - if (tagStr.endsWith("|")) { - tagStr = tagStr.substring(0, tagStr.length() - 1); - } ITopic tagTopic = workbook.createTopic(); - tagTopic.setTitleText(Translator.get("xmind_tags") + ":" + tagStr); + tagTopic.setTitleText(Translator.get("xmind_tags").concat(": ").concat(dto.getTags())); if (style != null) { tagTopic.setStyleId(style.getId()); } @@ -168,14 +166,14 @@ public class XmindExportUtil { //文本描述 ITopic textDesTopic = workbook.createTopic(); String desc = dto.getTextDescription(); - textDesTopic.setTitleText(desc == null ? Translator.get("xmind_textDescription") + ": " : Translator.get("xmind_textDescription") + ": " + desc); + textDesTopic.setTitleText(desc == null ? Translator.get("xmind_textDescription").concat(": ") : Translator.get("xmind_textDescription").concat(": ").concat(Translator.get("xmind_textDescription")).concat(": ").concat(desc)); if (style != null) { textDesTopic.setStyleId(style.getId()); } String result = dto.getExpectedResult(); ITopic resultTopic = workbook.createTopic(); - resultTopic.setTitleText(result == null ? Translator.get("xmind_expectedResult") + ": " : Translator.get("xmind_expectedResult") + ": " + result); + resultTopic.setTitleText(result == null ? Translator.get("xmind_expectedResult").concat(": ") : Translator.get("xmind_expectedResult").concat(": ").concat(result)); if (style != null) { resultTopic.setStyleId(style.getId()); } @@ -198,7 +196,7 @@ public class XmindExportUtil { if (obj.containsKey("desc")) { ITopic stepTopic = workbook.createTopic(); String desc = obj.get("desc"); - stepTopic.setTitleText(Translator.get("xmind_step") + ": " + desc); + stepTopic.setTitleText(Translator.get("xmind_step").concat(": ").concat(desc)); if (style != null) { stepTopic.setStyleId(style.getId()); } @@ -209,7 +207,7 @@ public class XmindExportUtil { if (StringUtils.isNotEmpty(result)) { hasResult = true; ITopic resultTopic = workbook.createTopic(); - resultTopic.setTitleText(Translator.get("xmind_expectedResult") + ": " + result); + resultTopic.setTitleText(Translator.get("xmind_expectedResult").concat(": ").concat(result)); if (style != null) { resultTopic.setStyleId(style.getId()); } @@ -230,9 +228,10 @@ public class XmindExportUtil { //自定义字段 dto.getTemplateCustomFieldDTOList().forEach(item -> { - if (!StringUtils.equalsIgnoreCase(item.getFieldName(), "functional_priority")) { + if (!StringUtils.equalsIgnoreCase(item.getFieldName(), Translator.get("custom_field.functional_priority"))) { ITopic customTopic = workbook.createTopic(); - customTopic.setTitleText(item.getFieldName() + ":"); + String fieldComment = getComment(item,customFieldOptionsMap); + customTopic.setTitleText(item.getFieldName().concat(": ").concat(fieldComment)); if (style != null) { customTopic.setStyleId(style.getId()); } @@ -243,6 +242,32 @@ public class XmindExportUtil { topic.add(itemTopic); } + private static String getComment(TemplateCustomFieldDTO templateCustomFieldDTO,Map> customFieldOptionsMap) { + String comment = ""; + if (StringUtils.equalsAnyIgnoreCase(templateCustomFieldDTO.getType(), CustomFieldType.MULTIPLE_MEMBER.name(), CustomFieldType.MEMBER.name())) { + if (templateCustomFieldDTO.getRequired()) { + comment = Translator.get("required").concat(",").concat(Translator.get("excel.template.member")); + } else { + comment = Translator.get("excel.template.not_required").concat(",").concat(Translator.get("excel.template.member")); + } + } else { + if (templateCustomFieldDTO.getRequired()) { + if (CollectionUtils.isNotEmpty(templateCustomFieldDTO.getOptions())) { + comment = Translator.get("required").concat(":").concat(Translator.get("options")).concat(JSON.toJSONString(customFieldOptionsMap.get(templateCustomFieldDTO.getFieldName()))); + } else { + comment = Translator.get("required"); + } + } else { + if (CollectionUtils.isNotEmpty(templateCustomFieldDTO.getOptions())) { + comment = Translator.get("excel.template.not_required").concat(":").concat(Translator.get("options")).concat(JSON.toJSONString(customFieldOptionsMap.get(templateCustomFieldDTO.getFieldName()))); + } else { + comment = Translator.get("excel.template.not_required"); + } + } + } + return comment; + } + private static Map initTheme(IWorkbook workbook) { Map styleMap = new HashMap<>(); diff --git a/backend/services/case-management/src/main/resources/template/template.json b/backend/services/case-management/src/main/resources/template/template.json index c14b9e0113..809af9e9c1 100644 --- a/backend/services/case-management/src/main/resources/template/template.json +++ b/backend/services/case-management/src/main/resources/template/template.json @@ -9,32 +9,32 @@ "id": "1", "num": 1, "projectId": "12314", - "name": "导出模板用例A", - "tags": "[\"标签789\"]", + "name": "", + "tags": "多个|分隔,非必填", "caseEditType": "STEP", - "steps": "[{\"num\":1,\"desc\":\"123\",\"result\":\"123\"},{\"num\":2,\"desc\":\"SDFS\",\"result\":\"SDFS\"}]", + "steps": "[{\"num\":1,\"desc\":\"非必填\",\"result\":\"非必填\"},{\"num\":2,\"desc\":\"非必填\",\"result\":\"非必填\"}]", "textDescription": "", "expectedResult": "", - "prerequisite": "这是前置", - "description": "这是备注", + "prerequisite": "非必填", + "description": "非必填", "customFieldDTOList": [] }, { "id": "2", "num": 2, "projectId": "12314", - "name": "导出模板用例B", - "tags": "[\"标签789\"]", + "name": "", + "tags": "标签,多个|分隔,非必填", "caseEditType": "TEXT", "steps": "", - "textDescription": "

akhfksajhfaskfha

", - "expectedResult": "

asdfsdfasfs

", - "prerequisite": "前置", - "description": "这是备注", + "textDescription": "非必填", + "expectedResult": "非必填", + "prerequisite": "非必填", + "description": "非必填", "customFieldDTOList": [] } ], - "moduleName": "模块1", + "moduleName": "模块1:若无该模块将自动创建", "moduleId": "module1", "children": [ { @@ -43,18 +43,18 @@ "id": "3", "num": 3, "projectId": "12314", - "name": "导出模板用例C", - "tags": "[\"标签789\"]", + "name": "", + "tags": "多个|分隔,非必填", "caseEditType": "STEP", - "steps": "[{\"num\":1,\"desc\":\"123\",\"result\":\"123\"},{\"num\":2,\"desc\":\"SDFS\",\"result\":\"SDFS\"}]", + "steps": "[{\"num\":1,\"desc\":\"非必填\",\"result\":\"非必填\"},{\"num\":2,\"desc\":\"非必填\",\"result\":\"非必填\"}]", "textDescription": "", "expectedResult": "", - "prerequisite": "前置", - "description": "这是备注", + "prerequisite": "非必填", + "description": "非必填", "customFieldDTOList": [] } ], - "moduleName": "模块2", + "moduleName": "模块2:若无该模块将自动创建", "moduleId": "module2", "children": [] }