fix(项目管理): 修复消息通知设置显示字段问题

--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
This commit is contained in:
guoyuqi 2024-04-11 11:08:12 +08:00 committed by 刘瑞斌
parent 933415c30d
commit d029ed513b
7 changed files with 72 additions and 38 deletions

View File

@ -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<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
String template = defaultTemplateMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + event);
Map<String, String> 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 缺陷通知参数

View File

@ -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<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
String template = defaultTemplateMap.get(NoticeConstants.TemplateText.BUG_SYNC_TASK_EXECUTE_COMPLETED);
Map<String, String> 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);
}
}

View File

@ -280,8 +280,7 @@ public class NoticeMessageTaskService {
*
* @return Map<String, String>
*/
public Map<String, String> getCustomFielddMap(String projectId) {
Map<String, String> customFielddMap = new HashMap<>();
public Map<String, List<CustomField>> getCustomFielddMap(String projectId) {
List<String> 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<CustomField> 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<String, String> eventMap = MessageTemplateUtils.getEventMap();
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
Map<String, String> defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
Map<String, String> customFielddMap = getCustomFielddMap(projectId);
Map<String, List<CustomField>> 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<String, String> customFielddMap) {
private ProjectRobotConfigDTO getProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, MessageTask messageTask, MessageTaskBlob messageTaskBlob, Map<String, List<CustomField>> 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<String, String> customFielddMap) {
private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String taskType, String defaultTemplate, String defaultSubject, ProjectRobot projectRobot, Map<String, List<CustomField>> customFielddMap) {
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
projectRobotConfigDTO.setRobotId(projectRobot.getId());
projectRobotConfigDTO.setRobotName(Translator.get(projectRobot.getName()));
@ -486,7 +482,7 @@ public class NoticeMessageTaskService {
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
Map<String, String> defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
Map<String, String> customFielddMap = getCustomFielddMap(projectId);
Map<String, List<CustomField>> customFielddMap = getCustomFielddMap(projectId);
ProjectRobot projectRobot = projectRobotMapper.selectByPrimaryKey(robotId);
MessageTask messageTask;
if (projectRobot == null) {

View File

@ -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) {

View File

@ -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<String, String> customFielddMap) {
public static String getTranslateTemplate(String taskType, String template, Map<String, List<CustomField>> 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<String, String> 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<String, List<CustomField>> customFielddMap, Map<String, Object> map) {
for (TemplateScene value : TemplateScene.values()) {
if (taskType.contains(value.toString())) {
List<CustomField> customFields = customFielddMap.get(value.toString());
if (CollectionUtils.isNotEmpty(customFields)) {
Map <String,String>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<String, Object> 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<String, String> customFielddMap) {
public static String getTranslateSubject(String taskType, String subject, Map<String, List<CustomField>> 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<String, String> defaultRelatedUserMap = getDefaultRelatedUserMap();
defaultRelatedUserMap.remove("FOLLOW_PEOPLE");
map.putAll(defaultRelatedUserMap);
map.putAll(customFielddMap);
addCustomFiled(taskType, customFielddMap, map);
return getContent(subject, map);
}
}

View File

@ -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<String, String> fieldSourceMap = MessageTemplateUtils.getFieldSourceMap();
Assertions.assertTrue(MapUtils.isNotEmpty(fieldSourceMap));
Map<String, String> customFielddMap = getCustomFielddMap("100001100001");
Map<String, List<CustomField>> 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<String, String>
*/
public Map<String, String> getCustomFielddMap(String projectId) {
Map<String, String> customFielddMap = new HashMap<>();
public Map<String, List<CustomField>> getCustomFielddMap(String projectId) {
List<String> 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<CustomField> 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));
}
}

View File

@ -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)