refactor: 优化通知使用体验,站内通知接收人不包括操作人,三方通知不限制接收人是否是操作人

This commit is contained in:
Captain.B 2021-08-31 15:05:09 +08:00 committed by 刘瑞斌
parent 2a7983feb1
commit eead4da948
5 changed files with 35 additions and 41 deletions

View File

@ -179,10 +179,6 @@ public abstract class AbstractNoticeSender implements NoticeSender {
break; break;
} }
} }
// 排除自己
if (noticeModel.isExcludeSelf()) {
toUsers.removeIf(u -> StringUtils.equals(u.getUserId(), noticeModel.getOperator()));
}
// 去重复 // 去重复
return toUsers.stream() return toUsers.stream()
.distinct() .distinct()

View File

@ -21,33 +21,32 @@ public class DingNoticeSender extends AbstractNoticeSender {
public void sendNailRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) { public void sendNailRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers(); List<Receiver> receivers = noticeModel.getReceivers();
if (CollectionUtils.isEmpty(receivers)) {
return;
}
DingTalkClient client = new DefaultDingTalkClient(messageDetail.getWebhook()); DingTalkClient client = new DefaultDingTalkClient(messageDetail.getWebhook());
OapiRobotSendRequest request = new OapiRobotSendRequest(); OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text"); request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent(context); text.setContent(context);
request.setText(text); request.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); if (CollectionUtils.isNotEmpty(receivers)) {
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
List<String> userIds = receivers.stream() List<String> userIds = receivers.stream()
.map(Receiver::getUserId) .map(Receiver::getUserId)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream() List<String> phoneList = super.getUserDetails(userIds).stream()
.map(UserDetail::getPhone) .map(UserDetail::getPhone)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(phoneList)) { if (!CollectionUtils.isEmpty(phoneList)) {
return; LogUtil.info("钉钉收件人地址: {}", userIds);
at.setAtMobiles(phoneList);
request.setAt(at);
}
} }
LogUtil.info("钉钉收件人地址: {}", userIds);
at.setAtMobiles(phoneList);
request.setAt(at);
try { try {
client.execute(request); client.execute(request);
} catch (ApiException e) { } catch (ApiException e) {

View File

@ -9,6 +9,7 @@ import io.metersphere.notice.sender.AbstractNoticeSender;
import io.metersphere.notice.sender.NoticeModel; import io.metersphere.notice.sender.NoticeModel;
import io.metersphere.notice.service.NotificationService; import io.metersphere.notice.service.NotificationService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -23,6 +24,10 @@ public class InSiteNoticeSender extends AbstractNoticeSender {
public void sendAnnouncement(MessageDetail messageDetail, NoticeModel noticeModel, String context) { public void sendAnnouncement(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers(); List<Receiver> receivers = noticeModel.getReceivers();
// 排除自己
if (noticeModel.isExcludeSelf()) {
receivers.removeIf(u -> StringUtils.equals(u.getUserId(), noticeModel.getOperator()));
}
if (CollectionUtils.isEmpty(receivers)) { if (CollectionUtils.isEmpty(receivers)) {
return; return;
} }

View File

@ -28,10 +28,6 @@ public class LarkNoticeSender extends AbstractNoticeSender {
.map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>") .map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>")
.collect(Collectors.toList()); .collect(Collectors.toList());
// 没有接收人不发通知
if (CollectionUtils.isEmpty(collect)) {
return;
}
LogUtil.info("飞书收件人: {}", userIds); LogUtil.info("飞书收件人: {}", userIds);
context += StringUtils.join(collect, " "); context += StringUtils.join(collect, " ");
LarkClient.send(messageDetail.getWebhook(), context); LarkClient.send(messageDetail.getWebhook(), context);

View File

@ -21,27 +21,25 @@ public class WeComNoticeSender extends AbstractNoticeSender {
public void sendWechatRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) { public void sendWechatRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers(); List<Receiver> receivers = noticeModel.getReceivers();
if (CollectionUtils.isEmpty(receivers)) {
return;
}
TextMessage message = new TextMessage(context); TextMessage message = new TextMessage(context);
List<String> userIds = receivers.stream() if (CollectionUtils.isNotEmpty(receivers)) {
.map(Receiver::getUserId) List<String> userIds = receivers.stream()
.distinct() .map(Receiver::getUserId)
.collect(Collectors.toList()); .distinct()
.collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream() List<String> phoneList = super.getUserDetails(userIds).stream()
.map(UserDetail::getPhone) .map(UserDetail::getPhone)
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
message.setMentionedMobileList(phoneList); if (CollectionUtils.isNotEmpty(phoneList)) {
message.setMentionedMobileList(phoneList);
if (CollectionUtils.isEmpty(phoneList)) { LogUtil.info("企业微信收件人: {}", userIds);
return; }
} }
LogUtil.info("企业微信收件人: {}", userIds);
try { try {
WxChatbotClient.send(messageDetail.getWebhook(), message); WxChatbotClient.send(messageDetail.getWebhook(), message);
} catch (IOException e) { } catch (IOException e) {