From e9ddb78d896992b09d2894cad90f8094fcb82d5d Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Fri, 1 Mar 2024 19:11:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=BC=BA=E9=99=B7=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E9=99=B7=E8=AF=84=E8=AE=BA=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=8F=8A=E5=85=B3=E6=B3=A8=E4=BA=BA=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036462 --user=宋昌昌 【项目管理】消息管理-缺陷评论-关注人-发送消息后飞书可以收到,其他未收到 https://www.tapd.cn/55049933/s/1467978 --- .../bug/service/BugCommentNoticeService.java | 10 ++-- .../bug/service/BugCommentService.java | 12 ++-- .../bug/service/BugNoticeService.java | 57 ++++++++++--------- .../metersphere/system/dto/BugNoticeDTO.java | 3 + .../notice/sender/AbstractNoticeSender.java | 14 +++++ 5 files changed, 59 insertions(+), 37 deletions(-) diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java index d8ffd41d59..b2fcb8271e 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentNoticeService.java @@ -55,12 +55,12 @@ public class BugCommentNoticeService { * 发送缺陷通知 */ @Async - public void sendNotice(BugCommentEditRequest request, BugCommentNoticeDTO noticeDTO, String currentUser) { + public void sendNotice(String event, BugCommentNoticeDTO noticeDTO, String currentUser) { User user = userMapper.selectByPrimaryKey(currentUser); Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); - String template = defaultTemplateMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + request.getEvent()); + String template = defaultTemplateMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + event); Map defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); - String subject = defaultSubjectMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + request.getEvent()); + String subject = defaultSubjectMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + event); BeanMap beanMap = new BeanMap(noticeDTO); Map paramMap = new HashMap<>(beanMap); paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName()); @@ -69,7 +69,7 @@ public class BugCommentNoticeService { .context(template) .subject(subject) .paramMap(paramMap) - .event(request.getEvent()) + .event(event) .status((String) paramMap.get("status")) .excludeSelf(true) .relatedUsers(getRelateUser(noticeDTO.getNotifier())) @@ -91,7 +91,7 @@ public class BugCommentNoticeService { /** * 评论通知@用户处理与功能用例保持一致即可, 根据事件类型设置通知人 - * 如果是REPLAY事件,需要判断有无@的人,如果有@的人且和当前被回复的人不是同一人,这里只被回复的人,如果是同一人,这里通知人为空,走AT事件 + * 如果是REPLAY事件, 需要判断有无@的人, 如果有@的人且和当前被回复的人不是同一人, 这里只通知被回复的人; 如果是同一人, 这里通知人为空, 走AT事件 * 如果不是REPLAY事件,需要判断有无被回复的人,如果被回复的人不在被@人里,则用页面参数传递的通知人,如果在,则排除这个人,如果没有被回复的人,用页面数据 * * @param request 页面请求参数 diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java index 4cb1e80178..afdd100444 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugCommentService.java @@ -161,11 +161,11 @@ public class BugCommentService { bugCommentMapper.insertSelective(bugComment); // 回复通知 BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); - bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); + bugCommentNoticeService.sendNotice(NoticeConstants.Event.REPLY, bugCommentNotice, currentUser); // @通知 request.setEvent(NoticeConstants.Event.AT); bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); - bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); + bugCommentNoticeService.sendNotice(NoticeConstants.Event.AT, bugCommentNotice, currentUser); return bugComment; } @@ -184,10 +184,10 @@ public class BugCommentService { * 如果通知@人为空, 只发送评论通知. */ BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); - bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); + bugCommentNoticeService.sendNotice(request.getEvent(), bugCommentNotice, currentUser); if (StringUtils.equals(request.getEvent(), NoticeConstants.Event.AT)) { - request.setEvent(NoticeConstants.Event.COMMENT); - bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); + // 评论通知 + bugCommentNoticeService.sendNotice(NoticeConstants.Event.COMMENT, bugCommentNotice, currentUser); } return bugComment; } @@ -213,7 +213,7 @@ public class BugCommentService { request.setEvent(NoticeConstants.Event.AT); } BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); - bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); + bugCommentNoticeService.sendNotice(request.getEvent(), bugCommentNotice, currentUser); return bugComment; } diff --git a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java index 1123c977e6..1349a5eb0f 100644 --- a/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java +++ b/backend/services/bug-management/src/main/java/io/metersphere/bug/service/BugNoticeService.java @@ -44,33 +44,38 @@ public class BugNoticeService { // 获取状态选项, 处理人选项 Map statusMap = getStatusMap(request.getProjectId()); Map handlerMap = getHandleMap(request.getProjectId()); - // 构建通知对象 - BugNoticeDTO notice = new BugNoticeDTO(); - notice.setTitle(request.getTitle()); - // 自定义字段解析{name: value} - if (CollectionUtils.isNotEmpty(request.getCustomFields())) { - List fields = new ArrayList<>(); - request.getCustomFields().forEach(field -> { - if (StringUtils.equals(field.getId(), CUSTOM_TITLE)) { - // TITLE {标题为空时, 从自定义字段中获取标题} - notice.setTitle(field.getValue()); - } else if (StringUtils.equals(field.getId(), CUSTOM_STATUS)) { - // 状态 {从自定义字段中获取状态} - notice.setStatus(statusMap.get(field.getValue())); - } else if (StringUtils.equals(field.getName(), CUSTOM_HANDLE_USER)) { - // 处理人 {从自定义字段中获取状态} - notice.setHandleUser(handlerMap.get(field.getValue())); - } else { - // 其他自定义字段 - OptionDTO fieldDTO = new OptionDTO(); - fieldDTO.setId(field.getName()); - fieldDTO.setName(field.getValue()); - fields.add(fieldDTO); - } - }); - notice.setCustomFields(fields); + if (StringUtils.isEmpty(request.getId())) { + // 构建通知对象 + BugNoticeDTO notice = new BugNoticeDTO(); + notice.setTitle(request.getTitle()); + // 自定义字段解析{name: value} + if (CollectionUtils.isNotEmpty(request.getCustomFields())) { + List fields = new ArrayList<>(); + request.getCustomFields().forEach(field -> { + if (StringUtils.equals(field.getId(), CUSTOM_TITLE)) { + // TITLE {标题为空时, 从自定义字段中获取标题} + notice.setTitle(field.getValue()); + } else if (StringUtils.equals(field.getId(), CUSTOM_STATUS)) { + // 状态 {从自定义字段中获取状态} + notice.setStatus(statusMap.get(field.getValue())); + } else if (StringUtils.equals(field.getName(), CUSTOM_HANDLE_USER)) { + // 处理人 {从自定义字段中获取状态} + notice.setHandleUser(handlerMap.get(field.getValue())); + } else { + // 其他自定义字段 + OptionDTO fieldDTO = new OptionDTO(); + fieldDTO.setId(field.getName()); + fieldDTO.setName(field.getValue()); + fields.add(fieldDTO); + } + }); + notice.setCustomFields(fields); + } + return notice; + } else { + // 需设置业务ID(用来通知关注人), 创建人 + return getNoticeById(request.getId()); } - return notice; } /** diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/BugNoticeDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/BugNoticeDTO.java index 6fba9608ed..bc7312b894 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/BugNoticeDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/BugNoticeDTO.java @@ -15,6 +15,9 @@ import java.util.List; @AllArgsConstructor public class BugNoticeDTO { + @Schema(description ="message.domain.bug_num") + private String id; + @Schema(description ="message.domain.bug_title") private String title; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java index ee6729b430..88a9f5897f 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java @@ -7,6 +7,9 @@ import io.metersphere.api.domain.ApiScenarioFollower; import io.metersphere.api.domain.ApiScenarioFollowerExample; import io.metersphere.api.mapper.ApiDefinitionFollowerMapper; import io.metersphere.api.mapper.ApiScenarioFollowerMapper; +import io.metersphere.bug.domain.BugFollower; +import io.metersphere.bug.domain.BugFollowerExample; +import io.metersphere.bug.mapper.BugFollowerMapper; import io.metersphere.functional.domain.CaseReviewFollower; import io.metersphere.functional.domain.CaseReviewFollowerExample; import io.metersphere.functional.domain.FunctionalCaseFollower; @@ -41,6 +44,8 @@ import java.util.stream.Collectors; public abstract class AbstractNoticeSender implements NoticeSender { + @Resource + private BugFollowerMapper bugFollowerMapper; @Resource private TestPlanFollowerMapper testPlanFollowerMapper; @Resource @@ -212,6 +217,15 @@ public abstract class AbstractNoticeSender implements NoticeSender { .map(t -> new Receiver(t.getUserId(), NotificationConstants.Type.SYSTEM_NOTICE.name())) .collect(Collectors.toList()); } + case NoticeConstants.TaskType.BUG_TASK -> { + BugFollowerExample bugFollowerExample = new BugFollowerExample(); + bugFollowerExample.createCriteria().andBugIdEqualTo(id); + List bugFollowers = bugFollowerMapper.selectByExample(bugFollowerExample); + receivers = bugFollowers + .stream() + .map(t -> new Receiver(t.getUserId(), NotificationConstants.Type.SYSTEM_NOTICE.name())) + .collect(Collectors.toList()); + } default -> { } }