From d029ed513b724d5b0e4606cf395225c6166d1f56 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 11 Apr 2024 11:08:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=A1=B9=E7=9B=AE=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=98=BE=E7=A4=BA=E5=AD=97=E6=AE=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1039018 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001039018 --bug=1038673 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001038673 --bug=1039053 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001039053 --- .../bug/service/BugCommentNoticeService.java | 12 ++++++ .../bug/service/BugSyncNoticeService.java | 14 +++++++ .../service/NoticeMessageTaskService.java | 16 +++----- .../service/NoticeTemplateService.java | 11 +---- .../notice/utils/MessageTemplateUtils.java | 41 ++++++++++++++----- .../controller/MessageTemplateUtilsTests.java | 13 +++--- .../caseManagementFeature/components/utils.ts | 3 ++ 7 files changed, 72 insertions(+), 38 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java index b2fcb8271e..702a83deb9 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java @@ -18,6 +18,7 @@ import jakarta.annotation.Resource; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -57,6 +58,7 @@ public class BugCommentNoticeService { @Async public void sendNotice(String event, BugCommentNoticeDTO noticeDTO, String currentUser) { User user = userMapper.selectByPrimaryKey(currentUser); + setLanguage(user.getLanguage()); Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); String template = defaultTemplateMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + event); Map defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); @@ -77,6 +79,16 @@ public class BugCommentNoticeService { noticeSendService.send(NoticeConstants.TaskType.BUG_TASK, noticeModel); } + private static void setLanguage(String language) { + Locale locale = Locale.SIMPLIFIED_CHINESE; + if (StringUtils.containsIgnoreCase("US",language)) { + locale = Locale.US; + } else if (StringUtils.containsIgnoreCase("TW",language)){ + locale = Locale.TAIWAN; + } + LocaleContextHolder.setLocale(locale); + } + /** * 设置缺陷通知的自定义字段值 * @param bugCommentNoticeDTO 缺陷通知参数 diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java index 505f0a00ef..a8c3c67279 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugSyncNoticeService.java @@ -8,10 +8,13 @@ import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.utils.MessageTemplateUtils; import io.metersphere.system.service.NoticeSendService; import jakarta.annotation.Resource; +import org.apache.commons.lang3.StringUtils; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.HashMap; +import java.util.Locale; import java.util.Map; @Service @@ -30,6 +33,7 @@ public class BugSyncNoticeService { public void sendNotice(int total, String currentUser, String language, String projectId) { String platformName = projectApplicationService.getPlatformName(projectId); User user = userMapper.selectByPrimaryKey(currentUser); + setLanguage(user.getLanguage()); Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); String template = defaultTemplateMap.get(NoticeConstants.TemplateText.BUG_SYNC_TASK_EXECUTE_COMPLETED); Map defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); @@ -45,4 +49,14 @@ public class BugSyncNoticeService { .context(template).subject(subject).paramMap(paramMap).event(NoticeConstants.Event.EXECUTE_COMPLETED).build(); noticeSendService.send(NoticeConstants.TaskType.BUG_SYNC_TASK, noticeModel); } + + private static void setLanguage(String language) { + Locale locale = Locale.SIMPLIFIED_CHINESE; + if (StringUtils.containsIgnoreCase("US",language)) { + locale = Locale.US; + } else if (StringUtils.containsIgnoreCase("TW",language)){ + locale = Locale.TAIWAN; + } + LocaleContextHolder.setLocale(locale); + } } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java index c4d19b754e..735103c21a 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java @@ -280,8 +280,7 @@ public class NoticeMessageTaskService { * * @return Map */ - public Map getCustomFielddMap(String projectId) { - Map customFielddMap = new HashMap<>(); + public Map> getCustomFielddMap(String projectId) { List sceneList = new ArrayList<>(); sceneList.add(TemplateScene.API.toString()); sceneList.add(TemplateScene.TEST_PLAN.toString()); @@ -291,10 +290,7 @@ public class NoticeMessageTaskService { CustomFieldExample example = new CustomFieldExample(); example.createCriteria().andScopeIdEqualTo(projectId).andSceneIn(sceneList); List customFields = customFieldMapper.selectByExample(example); - for (CustomField customField : customFields) { - customFielddMap.put(customField.getName(), StringUtils.isBlank(customField.getRemark()) ? "-" : customField.getRemark()); - } - return customFielddMap; + return customFields.stream().collect(Collectors.groupingBy(CustomField::getScene)); } /** @@ -355,7 +351,7 @@ public class NoticeMessageTaskService { Map eventMap = MessageTemplateUtils.getEventMap(); Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); Map defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); - Map customFielddMap = getCustomFielddMap(projectId); + Map> customFielddMap = getCustomFielddMap(projectId); ProjectRobot projectRobot = getDefaultRobot(projectId, null); for (MessageTaskDTO messageTaskDTO : messageTaskDTOList) { messageTaskDTO.setProjectId(projectId); @@ -414,7 +410,7 @@ public class NoticeMessageTaskService { return messageTaskDTOList; } - private ProjectRobotConfigDTO getProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, MessageTask messageTask, MessageTaskBlob messageTaskBlob, Map customFielddMap) { + private ProjectRobotConfigDTO getProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, MessageTask messageTask, MessageTaskBlob messageTaskBlob, Map> customFielddMap) { ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO(); if (StringUtils.equalsIgnoreCase(projectRobot.getName(), "robot_in_site") || StringUtils.equalsIgnoreCase(projectRobot.getName(), "robot_mail")) { projectRobotConfigDTO.setRobotName(Translator.get(projectRobot.getName())); @@ -446,7 +442,7 @@ public class NoticeMessageTaskService { return projectRobotConfigDTO; } - private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String taskType, String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, Map customFielddMap) { + private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String taskType, String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, Map> customFielddMap) { ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO(); projectRobotConfigDTO.setRobotId(projectRobot.getId()); projectRobotConfigDTO.setRobotName(Translator.get(projectRobot.getName())); @@ -486,7 +482,7 @@ public class NoticeMessageTaskService { List messageTasks = messageTaskMapper.selectByExample(messageTaskExample); Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); Map defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); - Map customFielddMap = getCustomFielddMap(projectId); + Map> customFielddMap = getCustomFielddMap(projectId); ProjectRobot projectRobot = projectRobotMapper.selectByPrimaryKey(robotId); MessageTask messageTask; if (projectRobot == null) { diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java index 4b5f5e4d47..02f1191dc3 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java @@ -176,16 +176,7 @@ public class NoticeTemplateService { messageTemplateFieldOperator.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD); messageTemplateFieldOperator.setName(Translator.get("message.operator")); messageTemplateFieldDTOS.add(messageTemplateFieldOperator); - MessageTemplateFieldDTO messageTemplateFieldFollow = new MessageTemplateFieldDTO(); - messageTemplateFieldFollow.setId(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); - messageTemplateFieldFollow.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD); - messageTemplateFieldFollow.setName(Translator.get("message.follow_people")); - messageTemplateFieldDTOS.add(messageTemplateFieldFollow); - MessageTemplateFieldDTO messageTemplateFieldTriggerMode = new MessageTemplateFieldDTO(); - messageTemplateFieldTriggerMode.setId("triggerMode"); - messageTemplateFieldTriggerMode.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD); - messageTemplateFieldTriggerMode.setName(Translator.get("message.trigger_mode")); - messageTemplateFieldDTOS.add(messageTemplateFieldTriggerMode); + } public MessageTemplateResultDTO getTemplateFields(String projectId, String taskType) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java index 6a2d6622d7..4304b6c771 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java @@ -4,7 +4,9 @@ import io.metersphere.api.domain.ApiScenario; import io.metersphere.functional.domain.CaseReview; import io.metersphere.load.domain.LoadTest; import io.metersphere.plan.domain.TestPlan; +import io.metersphere.sdk.constants.TemplateScene; import io.metersphere.sdk.util.Translator; +import io.metersphere.system.domain.CustomField; import io.metersphere.system.domain.Schedule; import io.metersphere.system.dto.BugMessageDTO; import io.metersphere.system.dto.sdk.ApiDefinitionCaseDTO; @@ -12,6 +14,7 @@ import io.metersphere.system.dto.sdk.FunctionalCaseMessageDTO; import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.ui.domain.UiScenario; import io.swagger.v3.oas.annotations.media.Schema; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -197,7 +200,7 @@ public class MessageTemplateUtils { }); } - public static String getTranslateTemplate(String taskType, String template, Map customFielddMap) { + public static String getTranslateTemplate(String taskType, String template, Map> customFielddMap) { if (StringUtils.equalsIgnoreCase(taskType, NoticeConstants.TaskType.JENKINS_TASK)) { if (StringUtils.isNotBlank(template) && template.contains("${name}")) { template = template.replace("${name}", "{{" + Translator.get("message.jenkins_name") + "}}"); @@ -214,12 +217,28 @@ public class MessageTemplateUtils { } setMap(taskType, domainTemplateFields, map); Map defaultRelatedUserMap = getDefaultRelatedUserMap(); + defaultRelatedUserMap.remove("FOLLOW_PEOPLE"); map.putAll(defaultRelatedUserMap); - map.putAll(customFielddMap); + addCustomFiled(taskType, customFielddMap, map); return getContent(template, map); } } + private static void addCustomFiled(String taskType, Map> customFielddMap, Map map) { + for (TemplateScene value : TemplateScene.values()) { + if (taskType.contains(value.toString())) { + List customFields = customFielddMap.get(value.toString()); + if (CollectionUtils.isNotEmpty(customFields)) { + Map customFielddNameMap = new HashMap<>(); + for (CustomField customField : customFields) { + customFielddNameMap.put(customField.getName(), StringUtils.isBlank(customField.getName()) ? "-" : customField.getName()); + } + map.putAll(customFielddNameMap); + } + } + } + } + private static void setMap(String taskType, Field[] domainTemplateFields, Map map) { switch (taskType) { case NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> { @@ -253,7 +272,8 @@ public class MessageTemplateUtils { String tableName = "schedule_"; putDomainName(domainTemplateFields, map, tableName); } - default ->{} + default -> { + } } } @@ -261,11 +281,11 @@ public class MessageTemplateUtils { for (Field allField : domainTemplateFields) { Schema annotation = allField.getAnnotation(Schema.class); if (annotation != null) { - String description; + String description; if (StringUtils.equals(allField.getName(), "name") || StringUtils.equals(allField.getName(), "title")) { - description = "{{" + Translator.get("message.domain."+ tableName +allField.getName()) + "}}"; + description = "{{" + Translator.get("message.domain." + tableName + allField.getName()) + "}}"; } else { - description = "<" + Translator.get("message.domain."+ tableName +allField.getName()) + ">"; + description = "<" + Translator.get("message.domain." + tableName + allField.getName()) + ">"; } map.put(allField.getName(), description); } @@ -278,16 +298,16 @@ public class MessageTemplateUtils { if (annotation != null) { String description; if (StringUtils.equals(allField.getName(), "name") || StringUtils.equals(allField.getName(), "title")) { - description = "{{" + Translator.get("message.domain."+ allField.getName()) + "}}"; + description = "{{" + Translator.get("message.domain." + allField.getName()) + "}}"; } else { - description = "<" + Translator.get("message.domain."+ allField.getName()) + ">"; + description = "<" + Translator.get("message.domain." + allField.getName()) + ">"; } map.put(allField.getName(), description); } } } - public static String getTranslateSubject(String taskType, String subject, Map customFielddMap) { + public static String getTranslateSubject(String taskType, String subject, Map> customFielddMap) { if (StringUtils.equalsIgnoreCase(taskType, NoticeConstants.TaskType.JENKINS_TASK)) { if (StringUtils.isNotBlank(subject) && subject.contains("${name}")) { subject = subject.replace("${name}", "{{" + Translator.get("message.jenkins_name") + "}}"); @@ -304,8 +324,9 @@ public class MessageTemplateUtils { } setMap(taskType, domainTemplateFields, map); Map defaultRelatedUserMap = getDefaultRelatedUserMap(); + defaultRelatedUserMap.remove("FOLLOW_PEOPLE"); map.putAll(defaultRelatedUserMap); - map.putAll(customFielddMap); + addCustomFiled(taskType, customFielddMap, map); return getContent(subject, map); } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java index ac14d5e62e..3caa5b6413 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest; import java.lang.reflect.Field; import java.util.*; +import java.util.stream.Collectors; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @@ -39,7 +40,7 @@ public class MessageTemplateUtilsTests { Assertions.assertTrue(MapUtils.isNotEmpty(defaultRelatedUserMap)); Map fieldSourceMap = MessageTemplateUtils.getFieldSourceMap(); Assertions.assertTrue(MapUtils.isNotEmpty(fieldSourceMap)); - Map customFielddMap = getCustomFielddMap("100001100001"); + Map> customFielddMap = getCustomFielddMap("100001100001"); for (String type : typeList) { Field[] domainTemplateFields = MessageTemplateUtils.getDomainTemplateFields(type); Assertions.assertNotNull(domainTemplateFields); @@ -49,7 +50,7 @@ public class MessageTemplateUtilsTests { if (StringUtils.isNotBlank(template)) { String translateTemplate = MessageTemplateUtils.getTranslateTemplate(type, template, customFielddMap); Assertions.assertTrue(StringUtils.isNotBlank(translateTemplate)); - String translateSubject= MessageTemplateUtils.getTranslateSubject(type, template, customFielddMap); + String translateSubject = MessageTemplateUtils.getTranslateSubject(type, template, customFielddMap); Assertions.assertTrue(StringUtils.isNotBlank(translateSubject)); } }); @@ -63,8 +64,7 @@ public class MessageTemplateUtilsTests { * * @return Map */ - public Map getCustomFielddMap(String projectId) { - Map customFielddMap = new HashMap<>(); + public Map> getCustomFielddMap(String projectId) { List sceneList = new ArrayList<>(); sceneList.add(TemplateScene.API.toString()); sceneList.add(TemplateScene.TEST_PLAN.toString()); @@ -74,9 +74,6 @@ public class MessageTemplateUtilsTests { CustomFieldExample example = new CustomFieldExample(); example.createCriteria().andScopeIdEqualTo(projectId).andSceneIn(sceneList); List customFields = customFieldMapper.selectByExample(example); - for (CustomField customField : customFields) { - customFielddMap.put(customField.getName(), org.apache.commons.lang3.StringUtils.isBlank(customField.getRemark()) ? "-" : customField.getRemark()); - } - return customFielddMap; + return customFields.stream().collect(Collectors.groupingBy(CustomField::getScene)); } } diff --git a/frontend/src/views/case-management/caseManagementFeature/components/utils.ts b/frontend/src/views/case-management/caseManagementFeature/components/utils.ts index abbdb82a9a..a9e1ab2931 100644 --- a/frontend/src/views/case-management/caseManagementFeature/components/utils.ts +++ b/frontend/src/views/case-management/caseManagementFeature/components/utils.ts @@ -166,6 +166,9 @@ export function getTableFields(customFields: CustomAttributes[], itemDataIndex: return JSON.parse(currentColumnData.defaultValue).join(',') || '-'; } if (selectExcludes.includes(currentColumnData.type)) { + if (currentColumnData.defaultValue === 'CREATE_USER') { + currentColumnData.defaultValue = userId; + } return ( (currentColumnData.options || []) .filter((item: any) => currentColumnData.defaultValue === item.value)