diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTaskDetailDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTaskDetailDTO.java index f2e1a979bc..56b9daa826 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTaskDetailDTO.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTaskDetailDTO.java @@ -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 receivers; @Schema(description = "消息配置机器人设置") - private List projectRobotConfigList; + private Map projectRobotConfigMap; + } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java index 0bd164d1d8..043a4a3cbd 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java @@ -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; 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 9cc6004c9d..2c7ef1c70f 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 @@ -80,7 +80,8 @@ public class NoticeMessageTaskService { Map> stringListMap = checkUserExistProject(messageTaskRequest.getReceiverIds(), projectId); List 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 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 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 eventMap = MessageTemplateUtils.getEventMap(); Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); Map 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 messageTaskList = messageEventMap.get(messageTaskDetailDTO.getEvent()); List receivers = new ArrayList<>(); - - List projectRobotConfigList = new ArrayList<>(); + Map 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 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(""); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java index 8d20f16feb..fb60e646a4 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java @@ -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 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 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 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 userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); Assertions.assertEquals(0, userDtoList.size()); - } }