refactor(消息管理): 修改返回的机器人配置结构
This commit is contained in:
parent
5bec1e64a0
commit
d715d1f569
|
@ -8,6 +8,7 @@ import lombok.EqualsAndHashCode;
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@ -26,5 +27,6 @@ public class MessageTaskDetailDTO implements Serializable {
|
||||||
private List<OptionDTO> receivers;
|
private List<OptionDTO> receivers;
|
||||||
|
|
||||||
@Schema(description = "消息配置机器人设置")
|
@Schema(description = "消息配置机器人设置")
|
||||||
private List<ProjectRobotConfigDTO> projectRobotConfigList;
|
private Map<String,ProjectRobotConfigDTO> projectRobotConfigMap;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ public class ProjectRobotConfigDTO implements Serializable {
|
||||||
@Schema(description = "消息配置机器人id")
|
@Schema(description = "消息配置机器人id")
|
||||||
public String robotId;
|
public String robotId;
|
||||||
|
|
||||||
|
@Schema(description = "消息配置机器人名称")
|
||||||
|
public String robotName;
|
||||||
|
|
||||||
@Schema(description = "所属平台(飞书:LARK,钉钉:DING_TALK,企业微信:WE_COM,自定义:CUSTOM, 站内信:IN_SITE, 邮件:MAIL)")
|
@Schema(description = "所属平台(飞书:LARK,钉钉:DING_TALK,企业微信:WE_COM,自定义:CUSTOM, 站内信:IN_SITE, 邮件:MAIL)")
|
||||||
private String platform;
|
private String platform;
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,8 @@ public class NoticeMessageTaskService {
|
||||||
Map<String, List<String>> stringListMap = checkUserExistProject(messageTaskRequest.getReceiverIds(), projectId);
|
Map<String, List<String>> stringListMap = checkUserExistProject(messageTaskRequest.getReceiverIds(), projectId);
|
||||||
List<String> existUserIds = stringListMap.get(USER_IDS);
|
List<String> existUserIds = stringListMap.get(USER_IDS);
|
||||||
//如果只选了用户,没有选机器人,默认机器人为站内信
|
//如果只选了用户,没有选机器人,默认机器人为站内信
|
||||||
String robotId = setDefaultRobot(messageTaskRequest.getProjectId(), messageTaskRequest.getRobotId());
|
ProjectRobot projectRobot = setDefaultRobot(messageTaskRequest.getProjectId(), messageTaskRequest.getRobotId());
|
||||||
|
String robotId = projectRobot.getId();
|
||||||
messageTaskRequest.setRobotId(robotId);
|
messageTaskRequest.setRobotId(robotId);
|
||||||
//检查设置的通知是否存在,如果存在则更新
|
//检查设置的通知是否存在,如果存在则更新
|
||||||
List<MessageTask> messageTasks = updateMessageTasks(messageTaskRequest, userId, mapper, blobMapper, existUserIds);
|
List<MessageTask> messageTasks = updateMessageTasks(messageTaskRequest, userId, mapper, blobMapper, existUserIds);
|
||||||
|
@ -140,14 +141,15 @@ public class NoticeMessageTaskService {
|
||||||
* @param robotId 机器人id
|
* @param robotId 机器人id
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
private String setDefaultRobot(String projectId, String robotId) {
|
private ProjectRobot setDefaultRobot(String projectId, String robotId) {
|
||||||
if (StringUtils.isBlank(robotId)) {
|
if (StringUtils.isBlank(robotId)) {
|
||||||
ProjectRobotExample projectRobotExample = new ProjectRobotExample();
|
ProjectRobotExample projectRobotExample = new ProjectRobotExample();
|
||||||
projectRobotExample.createCriteria().andProjectIdEqualTo(projectId).andPlatformEqualTo(ProjectRobotPlatform.IN_SITE.toString());
|
projectRobotExample.createCriteria().andProjectIdEqualTo(projectId).andPlatformEqualTo(ProjectRobotPlatform.IN_SITE.toString());
|
||||||
List<ProjectRobot> projectRobots = projectRobotMapper.selectByExample(projectRobotExample);
|
List<ProjectRobot> projectRobots = projectRobotMapper.selectByExample(projectRobotExample);
|
||||||
robotId = projectRobots.get(0).getId();
|
return projectRobots.get(0);
|
||||||
|
} else {
|
||||||
|
return projectRobotMapper.selectByPrimaryKey(robotId);
|
||||||
}
|
}
|
||||||
return robotId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -323,8 +325,7 @@ public class NoticeMessageTaskService {
|
||||||
Map<String, String> eventMap = MessageTemplateUtils.getEventMap();
|
Map<String, String> eventMap = MessageTemplateUtils.getEventMap();
|
||||||
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
|
||||||
Map<String, String> defaultTemplateTitleMap = MessageTemplateUtils.getDefaultTemplateTitleMap();
|
Map<String, String> defaultTemplateTitleMap = MessageTemplateUtils.getDefaultTemplateTitleMap();
|
||||||
String robotId = setDefaultRobot(projectId, null);
|
ProjectRobot projectRobot = setDefaultRobot(projectId, null);
|
||||||
|
|
||||||
for (MessageTaskDTO messageTaskDTO : messageTaskDTOList) {
|
for (MessageTaskDTO messageTaskDTO : messageTaskDTOList) {
|
||||||
messageTaskDTO.setProjectId(projectId);
|
messageTaskDTO.setProjectId(projectId);
|
||||||
messageTaskDTO.setName(moduleMap.get(messageTaskDTO.getType()));
|
messageTaskDTO.setName(moduleMap.get(messageTaskDTO.getType()));
|
||||||
|
@ -339,13 +340,12 @@ public class NoticeMessageTaskService {
|
||||||
messageTaskDetailDTO.setEventName(eventMap.get(messageTaskDetailDTO.getEvent()));
|
messageTaskDetailDTO.setEventName(eventMap.get(messageTaskDetailDTO.getEvent()));
|
||||||
List<MessageTask> messageTaskList = messageEventMap.get(messageTaskDetailDTO.getEvent());
|
List<MessageTask> messageTaskList = messageEventMap.get(messageTaskDetailDTO.getEvent());
|
||||||
List<OptionDTO> receivers = new ArrayList<>();
|
List<OptionDTO> receivers = new ArrayList<>();
|
||||||
|
Map<String,ProjectRobotConfigDTO> projectRobotConfigMap = new HashMap<>();
|
||||||
List<ProjectRobotConfigDTO> projectRobotConfigList = new ArrayList<>();
|
|
||||||
String defaultTemplate = defaultTemplateMap.get(messageTaskTypeDTO.taskType + "_" + messageTaskDetailDTO.getEvent());
|
String defaultTemplate = defaultTemplateMap.get(messageTaskTypeDTO.taskType + "_" + messageTaskDetailDTO.getEvent());
|
||||||
if (CollectionUtils.isEmpty(messageTaskList)) {
|
if (CollectionUtils.isEmpty(messageTaskList)) {
|
||||||
String defaultSubject = defaultTemplateTitleMap.get(messageTaskTypeDTO.taskType + "_" + messageTaskDetailDTO.getEvent());
|
String defaultSubject = defaultTemplateTitleMap.get(messageTaskTypeDTO.taskType + "_" + messageTaskDetailDTO.getEvent());
|
||||||
ProjectRobotConfigDTO projectRobotConfigDTO = getDefaultProjectRobotConfigDTO(defaultTemplate, defaultSubject, robotId);
|
ProjectRobotConfigDTO projectRobotConfigDTO = getDefaultProjectRobotConfigDTO(defaultTemplate, defaultSubject, projectRobot);
|
||||||
projectRobotConfigList.add(projectRobotConfigDTO);
|
projectRobotConfigMap.put(projectRobot.getId(),projectRobotConfigDTO);
|
||||||
} else {
|
} else {
|
||||||
for (MessageTask messageTask : messageTaskList) {
|
for (MessageTask messageTask : messageTaskList) {
|
||||||
MessageTaskBlob messageTaskBlob = messageTaskBlobMap.get(messageTask.getId());
|
MessageTaskBlob messageTaskBlob = messageTaskBlobMap.get(messageTask.getId());
|
||||||
|
@ -361,20 +361,22 @@ public class NoticeMessageTaskService {
|
||||||
defaultSubject = defaultTemplateTitleMap.get(messageTaskTypeDTO.taskType + "_" + messageTaskDetailDTO.getEvent());
|
defaultSubject = defaultTemplateTitleMap.get(messageTaskTypeDTO.taskType + "_" + messageTaskDetailDTO.getEvent());
|
||||||
}
|
}
|
||||||
ProjectRobotConfigDTO projectRobotConfigDTO = getProjectRobotConfigDTO(defaultTemplate, defaultSubject, platform, messageTask, messageTaskBlob);
|
ProjectRobotConfigDTO projectRobotConfigDTO = getProjectRobotConfigDTO(defaultTemplate, defaultSubject, platform, messageTask, messageTaskBlob);
|
||||||
projectRobotConfigList.add(projectRobotConfigDTO);
|
projectRobotConfigMap.put(messageTask.getProjectRobotId(),projectRobotConfigDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<OptionDTO> distinctReceivers = receivers.stream().distinct().toList();
|
List<OptionDTO> distinctReceivers = receivers.stream().distinct().toList();
|
||||||
messageTaskDetailDTO.setReceivers(distinctReceivers);
|
messageTaskDetailDTO.setReceivers(distinctReceivers);
|
||||||
messageTaskDetailDTO.setProjectRobotConfigList(projectRobotConfigList);
|
messageTaskDetailDTO.setProjectRobotConfigMap(projectRobotConfigMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return messageTaskDTOList;
|
return messageTaskDTOList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProjectRobotConfigDTO getProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, String robotPlatForm, MessageTask messageTask, MessageTaskBlob messageTaskBlob) {
|
private ProjectRobotConfigDTO getProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, String robotPlatForm, MessageTask messageTask, MessageTaskBlob messageTaskBlob) {
|
||||||
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
|
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
|
||||||
|
ProjectRobot projectRobot = projectRobotMapper.selectByPrimaryKey(messageTask.getProjectRobotId());
|
||||||
|
projectRobotConfigDTO.setRobotName(projectRobot.getName());
|
||||||
projectRobotConfigDTO.setRobotId(messageTask.getProjectRobotId());
|
projectRobotConfigDTO.setRobotId(messageTask.getProjectRobotId());
|
||||||
projectRobotConfigDTO.setPlatform(robotPlatForm);
|
projectRobotConfigDTO.setPlatform(robotPlatForm);
|
||||||
projectRobotConfigDTO.setEnable(messageTask.getEnable());
|
projectRobotConfigDTO.setEnable(messageTask.getEnable());
|
||||||
|
@ -387,9 +389,10 @@ public class NoticeMessageTaskService {
|
||||||
return projectRobotConfigDTO;
|
return projectRobotConfigDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, String robotId) {
|
private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, ProjectRobot projectRobot) {
|
||||||
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
|
ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO();
|
||||||
projectRobotConfigDTO.setRobotId(robotId);
|
projectRobotConfigDTO.setRobotId(projectRobot.getId());
|
||||||
|
projectRobotConfigDTO.setRobotName(projectRobot.getName());
|
||||||
projectRobotConfigDTO.setPlatform(ProjectRobotPlatform.IN_SITE.toString());
|
projectRobotConfigDTO.setPlatform(ProjectRobotPlatform.IN_SITE.toString());
|
||||||
projectRobotConfigDTO.setEnable(false);
|
projectRobotConfigDTO.setEnable(false);
|
||||||
projectRobotConfigDTO.setTemplate("");
|
projectRobotConfigDTO.setTemplate("");
|
||||||
|
|
|
@ -6,6 +6,8 @@ import io.metersphere.project.domain.MessageTaskBlob;
|
||||||
import io.metersphere.project.domain.MessageTaskExample;
|
import io.metersphere.project.domain.MessageTaskExample;
|
||||||
import io.metersphere.project.dto.MessageTaskDTO;
|
import io.metersphere.project.dto.MessageTaskDTO;
|
||||||
|
|
||||||
|
import io.metersphere.project.dto.MessageTaskDetailDTO;
|
||||||
|
import io.metersphere.project.dto.ProjectRobotConfigDTO;
|
||||||
import io.metersphere.project.mapper.MessageTaskBlobMapper;
|
import io.metersphere.project.mapper.MessageTaskBlobMapper;
|
||||||
import io.metersphere.project.mapper.MessageTaskMapper;
|
import io.metersphere.project.mapper.MessageTaskMapper;
|
||||||
import io.metersphere.sdk.constants.SessionConstants;
|
import io.metersphere.sdk.constants.SessionConstants;
|
||||||
|
@ -16,8 +18,8 @@ import io.metersphere.system.base.BaseTest;
|
||||||
import io.metersphere.system.controller.handler.ResultHolder;
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.platform.commons.util.StringUtils;
|
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
@ -265,9 +267,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
|
List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
|
||||||
// String robotId = messageTaskDetailDTOList.get(0).getMessageTaskTypeDTOList().get(0).getMessageTaskDetailDTOList().get(0).getProjectRobotConfigList().get(0).getRobotId();
|
|
||||||
// Assertions.assertTrue(StringUtils.isNotBlank(robotId));
|
|
||||||
System.out.println(messageTaskDetailDTOList);
|
System.out.println(messageTaskDetailDTOList);
|
||||||
|
Assertions.assertTrue(CollectionUtils.isNotEmpty(messageTaskDetailDTOList));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -291,8 +292,10 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
|
||||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
|
List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
|
||||||
String robotId = messageTaskDetailDTOList.get(0).getMessageTaskTypeDTOList().get(0).getMessageTaskDetailDTOList().get(0).getProjectRobotConfigList().get(0).getRobotId();
|
MessageTaskDetailDTO messageTaskDetailDTO = messageTaskDetailDTOList.get(0).getMessageTaskTypeDTOList().get(0).getMessageTaskDetailDTOList().get(0);
|
||||||
Assertions.assertTrue(StringUtils.isBlank(robotId));
|
Map<String, ProjectRobotConfigDTO> projectRobotConfigMap = messageTaskDetailDTO.getProjectRobotConfigMap();
|
||||||
|
System.out.println(projectRobotConfigMap);
|
||||||
|
// Assertions.assertTrue(StringUtils.isBlank(robotId));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -479,6 +482,5 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
|
||||||
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
|
||||||
List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
|
List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
|
||||||
Assertions.assertEquals(0, userDtoList.size());
|
Assertions.assertEquals(0, userDtoList.size());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue