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