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,15 +21,14 @@ 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);
if (CollectionUtils.isNotEmpty(receivers)) {
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
List<String> userIds = receivers.stream() List<String> userIds = receivers.stream()
@ -42,12 +41,12 @@ public class DingNoticeSender extends AbstractNoticeSender {
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isEmpty(phoneList)) { if (!CollectionUtils.isEmpty(phoneList)) {
return;
}
LogUtil.info("钉钉收件人地址: {}", userIds); LogUtil.info("钉钉收件人地址: {}", userIds);
at.setAtMobiles(phoneList); at.setAtMobiles(phoneList);
request.setAt(at); 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,10 +21,9 @@ 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);
if (CollectionUtils.isNotEmpty(receivers)) {
List<String> userIds = receivers.stream() List<String> userIds = receivers.stream()
.map(Receiver::getUserId) .map(Receiver::getUserId)
.distinct() .distinct()
@ -35,13 +34,12 @@ public class WeComNoticeSender extends AbstractNoticeSender {
.distinct() .distinct()
.collect(Collectors.toList()); .collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(phoneList)) {
message.setMentionedMobileList(phoneList); message.setMentionedMobileList(phoneList);
LogUtil.info("企业微信收件人: {}", userIds);
if (CollectionUtils.isEmpty(phoneList)) { }
return;
} }
LogUtil.info("企业微信收件人: {}", userIds);
try { try {
WxChatbotClient.send(messageDetail.getWebhook(), message); WxChatbotClient.send(messageDetail.getWebhook(), message);
} catch (IOException e) { } catch (IOException e) {