fix(缺陷管理): 修复缺陷评论通知及关注人通知相关问题

--bug=1036462 --user=宋昌昌 【项目管理】消息管理-缺陷评论-关注人-发送消息后飞书可以收到,其他未收到 https://www.tapd.cn/55049933/s/1467978
This commit is contained in:
song-cc-rock 2024-03-01 19:11:41 +08:00 committed by Craftsman
parent c810f8b8d3
commit e9ddb78d89
5 changed files with 59 additions and 37 deletions

View File

@ -55,12 +55,12 @@ public class BugCommentNoticeService {
* 发送缺陷通知 * 发送缺陷通知
*/ */
@Async @Async
public void sendNotice(BugCommentEditRequest request, BugCommentNoticeDTO noticeDTO, String currentUser) { public void sendNotice(String event, BugCommentNoticeDTO noticeDTO, String currentUser) {
User user = userMapper.selectByPrimaryKey(currentUser); User user = userMapper.selectByPrimaryKey(currentUser);
Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); Map<String, String> defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap();
String template = defaultTemplateMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + request.getEvent()); String template = defaultTemplateMap.get(NoticeConstants.TaskType.BUG_TASK + "_" + event);
Map<String, String> defaultSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); Map<String, String> 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); BeanMap beanMap = new BeanMap(noticeDTO);
Map paramMap = new HashMap<>(beanMap); Map paramMap = new HashMap<>(beanMap);
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName()); paramMap.put(NoticeConstants.RelatedUser.OPERATOR, user.getName());
@ -69,7 +69,7 @@ public class BugCommentNoticeService {
.context(template) .context(template)
.subject(subject) .subject(subject)
.paramMap(paramMap) .paramMap(paramMap)
.event(request.getEvent()) .event(event)
.status((String) paramMap.get("status")) .status((String) paramMap.get("status"))
.excludeSelf(true) .excludeSelf(true)
.relatedUsers(getRelateUser(noticeDTO.getNotifier())) .relatedUsers(getRelateUser(noticeDTO.getNotifier()))
@ -91,7 +91,7 @@ public class BugCommentNoticeService {
/** /**
* 评论通知@用户处理与功能用例保持一致即可, 根据事件类型设置通知人 * 评论通知@用户处理与功能用例保持一致即可, 根据事件类型设置通知人
* 如果是REPLAY事件需要判断有无@的人如果有@的人且和当前被回复的人不是同一人这里只被回复的人,如果是同一人这里通知人为空走AT事件 * 如果是REPLAY事件, 需要判断有无@的人, 如果有@的人且和当前被回复的人不是同一人, 这里只通知被回复的人; 如果是同一人, 这里通知人为空, 走AT事件
* 如果不是REPLAY事件需要判断有无被回复的人如果被回复的人不在被@人里则用页面参数传递的通知人如果在则排除这个人,如果没有被回复的人用页面数据 * 如果不是REPLAY事件需要判断有无被回复的人如果被回复的人不在被@人里则用页面参数传递的通知人如果在则排除这个人,如果没有被回复的人用页面数据
* *
* @param request 页面请求参数 * @param request 页面请求参数

View File

@ -161,11 +161,11 @@ public class BugCommentService {
bugCommentMapper.insertSelective(bugComment); bugCommentMapper.insertSelective(bugComment);
// 回复通知 // 回复通知
BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request);
bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); bugCommentNoticeService.sendNotice(NoticeConstants.Event.REPLY, bugCommentNotice, currentUser);
// @通知 // @通知
request.setEvent(NoticeConstants.Event.AT); request.setEvent(NoticeConstants.Event.AT);
bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request);
bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); bugCommentNoticeService.sendNotice(NoticeConstants.Event.AT, bugCommentNotice, currentUser);
return bugComment; return bugComment;
} }
@ -184,10 +184,10 @@ public class BugCommentService {
* 如果通知@人为空, 只发送评论通知. * 如果通知@人为空, 只发送评论通知.
*/ */
BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request);
bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); bugCommentNoticeService.sendNotice(request.getEvent(), bugCommentNotice, currentUser);
if (StringUtils.equals(request.getEvent(), NoticeConstants.Event.AT)) { 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; return bugComment;
} }
@ -213,7 +213,7 @@ public class BugCommentService {
request.setEvent(NoticeConstants.Event.AT); request.setEvent(NoticeConstants.Event.AT);
} }
BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request); BugCommentNoticeDTO bugCommentNotice = bugCommentNoticeService.getBugCommentNotice(request);
bugCommentNoticeService.sendNotice(request, bugCommentNotice, currentUser); bugCommentNoticeService.sendNotice(request.getEvent(), bugCommentNotice, currentUser);
return bugComment; return bugComment;
} }

View File

@ -44,33 +44,38 @@ public class BugNoticeService {
// 获取状态选项, 处理人选项 // 获取状态选项, 处理人选项
Map<String, String> statusMap = getStatusMap(request.getProjectId()); Map<String, String> statusMap = getStatusMap(request.getProjectId());
Map<String, String> handlerMap = getHandleMap(request.getProjectId()); Map<String, String> handlerMap = getHandleMap(request.getProjectId());
// 构建通知对象 if (StringUtils.isEmpty(request.getId())) {
BugNoticeDTO notice = new BugNoticeDTO(); // 构建通知对象
notice.setTitle(request.getTitle()); BugNoticeDTO notice = new BugNoticeDTO();
// 自定义字段解析{name: value} notice.setTitle(request.getTitle());
if (CollectionUtils.isNotEmpty(request.getCustomFields())) { // 自定义字段解析{name: value}
List<OptionDTO> fields = new ArrayList<>(); if (CollectionUtils.isNotEmpty(request.getCustomFields())) {
request.getCustomFields().forEach(field -> { List<OptionDTO> fields = new ArrayList<>();
if (StringUtils.equals(field.getId(), CUSTOM_TITLE)) { request.getCustomFields().forEach(field -> {
// TITLE {标题为空时, 从自定义字段中获取标题} if (StringUtils.equals(field.getId(), CUSTOM_TITLE)) {
notice.setTitle(field.getValue()); // TITLE {标题为空时, 从自定义字段中获取标题}
} else if (StringUtils.equals(field.getId(), CUSTOM_STATUS)) { 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.setStatus(statusMap.get(field.getValue()));
// 处理人 {从自定义字段中获取状态} } else if (StringUtils.equals(field.getName(), CUSTOM_HANDLE_USER)) {
notice.setHandleUser(handlerMap.get(field.getValue())); // 处理人 {从自定义字段中获取状态}
} else { notice.setHandleUser(handlerMap.get(field.getValue()));
// 其他自定义字段 } else {
OptionDTO fieldDTO = new OptionDTO(); // 其他自定义字段
fieldDTO.setId(field.getName()); OptionDTO fieldDTO = new OptionDTO();
fieldDTO.setName(field.getValue()); fieldDTO.setId(field.getName());
fields.add(fieldDTO); fieldDTO.setName(field.getValue());
} fields.add(fieldDTO);
}); }
notice.setCustomFields(fields); });
notice.setCustomFields(fields);
}
return notice;
} else {
// 需设置业务ID(用来通知关注人), 创建人
return getNoticeById(request.getId());
} }
return notice;
} }
/** /**

View File

@ -15,6 +15,9 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class BugNoticeDTO { public class BugNoticeDTO {
@Schema(description ="message.domain.bug_num")
private String id;
@Schema(description ="message.domain.bug_title") @Schema(description ="message.domain.bug_title")
private String title; private String title;

View File

@ -7,6 +7,9 @@ import io.metersphere.api.domain.ApiScenarioFollower;
import io.metersphere.api.domain.ApiScenarioFollowerExample; import io.metersphere.api.domain.ApiScenarioFollowerExample;
import io.metersphere.api.mapper.ApiDefinitionFollowerMapper; import io.metersphere.api.mapper.ApiDefinitionFollowerMapper;
import io.metersphere.api.mapper.ApiScenarioFollowerMapper; 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.CaseReviewFollower;
import io.metersphere.functional.domain.CaseReviewFollowerExample; import io.metersphere.functional.domain.CaseReviewFollowerExample;
import io.metersphere.functional.domain.FunctionalCaseFollower; import io.metersphere.functional.domain.FunctionalCaseFollower;
@ -41,6 +44,8 @@ import java.util.stream.Collectors;
public abstract class AbstractNoticeSender implements NoticeSender { public abstract class AbstractNoticeSender implements NoticeSender {
@Resource
private BugFollowerMapper bugFollowerMapper;
@Resource @Resource
private TestPlanFollowerMapper testPlanFollowerMapper; private TestPlanFollowerMapper testPlanFollowerMapper;
@Resource @Resource
@ -212,6 +217,15 @@ public abstract class AbstractNoticeSender implements NoticeSender {
.map(t -> new Receiver(t.getUserId(), NotificationConstants.Type.SYSTEM_NOTICE.name())) .map(t -> new Receiver(t.getUserId(), NotificationConstants.Type.SYSTEM_NOTICE.name()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
case NoticeConstants.TaskType.BUG_TASK -> {
BugFollowerExample bugFollowerExample = new BugFollowerExample();
bugFollowerExample.createCriteria().andBugIdEqualTo(id);
List<BugFollower> bugFollowers = bugFollowerMapper.selectByExample(bugFollowerExample);
receivers = bugFollowers
.stream()
.map(t -> new Receiver(t.getUserId(), NotificationConstants.Type.SYSTEM_NOTICE.name()))
.collect(Collectors.toList());
}
default -> { default -> {
} }
} }