refactor(消息管理): 获取详情的默认值处理
This commit is contained in:
parent
e943387381
commit
79b4a51ca1
|
@ -287,8 +287,8 @@ message.title.load_test_task_execute_completed=性能用例执行完成通知
|
|||
message.title.load_report_task_delete=性能报告删除通知
|
||||
message.title.jenkins_task_execute_successful=Jenkins任务执行成功通知
|
||||
message.title.jenkins_task_execute_failed=Jenkins任务执行失败通知
|
||||
message.title.schedule_task_open=
|
||||
message.title.schedule_task_close=
|
||||
message.title.schedule_task_open=开启定时任务通知
|
||||
message.title.schedule_task_close=关闭定时任务通知
|
||||
|
||||
resource_pool_not_exist=资源池不存在
|
||||
|
||||
|
|
|
@ -317,6 +317,8 @@ message.title.load_test_task_execute_completed=Load case execution completion no
|
|||
message.title.load_report_task_delete=Load report deletion notification
|
||||
message.title.jenkins_task_execute_successful=Jenkins task execution success notification
|
||||
message.title.jenkins_task_execute_failed=Jenkins task execution failure notification
|
||||
message.title.schedule_task_open=Turn on scheduled task notifications
|
||||
message.title.schedule_task_close=Turn off scheduled task notifications
|
||||
|
||||
resource_pool_not_exist=Resource pool does not exist
|
||||
|
||||
|
|
|
@ -317,6 +317,9 @@ message.title.load_test_task_execute_completed=性能用例执行完成通知
|
|||
message.title.load_report_task_delete=性能报告删除通知
|
||||
message.title.jenkins_task_execute_successful=Jenkins任务执行成功通知
|
||||
message.title.jenkins_task_execute_failed=Jenkins任务执行失败通知
|
||||
message.title.schedule_task_open=开启定时任务通知
|
||||
message.title.schedule_task_close=关闭定时任务通知
|
||||
|
||||
resource_pool_not_exist=资源池不存在
|
||||
|
||||
#file management
|
||||
|
|
|
@ -319,6 +319,8 @@ message.title.load_test_task_execute_completed=性能用例執行完成通知
|
|||
message.title.load_report_task_delete=性能報告删除通知
|
||||
message.title.jenkins_task_execute_successful=Jenkins任務執行成功通知
|
||||
message.title.jenkins_task_execute_failed=Jenkins任務執行失敗通知
|
||||
message.title.schedule_task_open=開啟定時任務通知
|
||||
message.title.schedule_task_close=關閉定時任務通知
|
||||
resource_pool_not_exist=資源池不存在
|
||||
#file management
|
||||
file_module.not.exist=文件模塊不存在
|
||||
|
|
|
@ -36,10 +36,7 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
@ -456,9 +453,26 @@ public class NoticeMessageTaskService {
|
|||
MessageTaskExample messageTaskExample = new MessageTaskExample();
|
||||
messageTaskExample.createCriteria().andProjectIdEqualTo(projectId).andTaskTypeEqualTo(taskType).andEventEqualTo(event);
|
||||
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
|
||||
List<String> receiverIds = messageTasks.stream().map(MessageTask::getReceiver).distinct().toList();
|
||||
Map<String, List<MessageTask>> messageRobotMap = messageTasks.stream().collect(Collectors.groupingBy(MessageTask::getProjectRobotId));
|
||||
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
||||
Map<String, String> defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
||||
ProjectRobot projectRobot = projectRobotMapper.selectByPrimaryKey(robotId);
|
||||
MessageTask messageTask;
|
||||
if (projectRobot == null) {
|
||||
throw new MSException(Translator.get("robot_is_null"));
|
||||
}
|
||||
if (CollectionUtils.isEmpty(messageTasks)) {
|
||||
messageTask = new MessageTask();
|
||||
messageTask.setTaskType(taskType);
|
||||
messageTask.setEvent(event);
|
||||
messageTask.setEnable(false);
|
||||
messageTask.setUseDefaultTemplate(true);
|
||||
messageTask.setUseDefaultSubject(true);
|
||||
messageTask.setProjectRobotId(projectRobot.getId());
|
||||
messageTask.setProjectId(projectId);
|
||||
messageTasks.add(messageTask);
|
||||
}
|
||||
List<String> receiverIds = messageTasks.stream().map(MessageTask::getReceiver).filter(Objects::nonNull).distinct().toList();
|
||||
Map<String, List<MessageTask>> messageRobotMap = messageTasks.stream().collect(Collectors.groupingBy(MessageTask::getProjectRobotId));
|
||||
if (CollectionUtils.isNotEmpty(messageRobotMap.get(robotId))) {
|
||||
messageTask = messageRobotMap.get(robotId).get(0);
|
||||
} else {
|
||||
|
@ -468,14 +482,8 @@ public class NoticeMessageTaskService {
|
|||
messageTask.setUseDefaultSubject(true);
|
||||
}
|
||||
MessageTaskBlob messageTaskBlob = messageTaskBlobMapper.selectByPrimaryKey(messageTask.getId());
|
||||
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
||||
Map<String, String> defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
|
||||
String defaultTemplate = defaultTemplateMap.get(messageTask.getTaskType() + "_" + messageTask.getEvent());
|
||||
String defaultSubject = defaultTemplateSubjectMap.get(messageTask.getTaskType() + "_" + messageTask.getEvent());
|
||||
ProjectRobot projectRobot = projectRobotMapper.selectByPrimaryKey(robotId);
|
||||
if (projectRobot == null) {
|
||||
throw new MSException(Translator.get("robot_is_null"));
|
||||
}
|
||||
ProjectRobotConfigDTO projectRobotConfigDTO = getProjectRobotConfigDTO(defaultTemplate, defaultSubject, projectRobot, messageTask, messageTaskBlob);
|
||||
MessageTemplateConfigDTO messageTemplateConfigDTO = new MessageTemplateConfigDTO();
|
||||
BeanUtils.copyBean(messageTemplateConfigDTO, projectRobotConfigDTO);
|
||||
|
|
|
@ -573,6 +573,26 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
|||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(23)
|
||||
public void getTemplateDetailNotData() throws Exception {
|
||||
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test")
|
||||
.header(SessionConstants.HEADER_TOKEN, sessionId)
|
||||
.header(SessionConstants.CSRF_TOKEN, csrfToken)
|
||||
.param("taskType", NoticeConstants.TaskType.BUG_TASK)
|
||||
.param("event", NoticeConstants.Event.CREATE)
|
||||
.param("robotId", "test_message_robot3")
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
|
||||
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||
MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class);
|
||||
Assertions.assertTrue(StringUtils.isNotBlank(messageTemplateConfigDTO.getTemplate()));
|
||||
Assertions.assertTrue(CollectionUtils.isEmpty(messageTemplateConfigDTO.getReceiverIds()));
|
||||
|
||||
}
|
||||
|
||||
public void setMessageTask(String projectId, String defaultRobotId) {
|
||||
StringBuilder jsonStr = new StringBuilder();
|
||||
InputStream inputStream = getClass().getResourceAsStream("/message_task.json");
|
||||
|
|
Loading…
Reference in New Issue