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;
}
}
// 排除自己
if (noticeModel.isExcludeSelf()) {
toUsers.removeIf(u -> StringUtils.equals(u.getUserId(), noticeModel.getOperator()));
}
// 去重复
return toUsers.stream()
.distinct()

View File

@ -21,33 +21,32 @@ public class DingNoticeSender extends AbstractNoticeSender {
public void sendNailRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers();
if (CollectionUtils.isEmpty(receivers)) {
return;
}
DingTalkClient client = new DefaultDingTalkClient(messageDetail.getWebhook());
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent(context);
request.setText(text);
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
if (CollectionUtils.isNotEmpty(receivers)) {
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
List<String> userIds = receivers.stream()
.map(Receiver::getUserId)
.distinct()
.collect(Collectors.toList());
List<String> userIds = receivers.stream()
.map(Receiver::getUserId)
.distinct()
.collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream()
.map(UserDetail::getPhone)
.distinct()
.collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream()
.map(UserDetail::getPhone)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(phoneList)) {
return;
if (!CollectionUtils.isEmpty(phoneList)) {
LogUtil.info("钉钉收件人地址: {}", userIds);
at.setAtMobiles(phoneList);
request.setAt(at);
}
}
LogUtil.info("钉钉收件人地址: {}", userIds);
at.setAtMobiles(phoneList);
request.setAt(at);
try {
client.execute(request);
} 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.service.NotificationService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -23,6 +24,10 @@ public class InSiteNoticeSender extends AbstractNoticeSender {
public void sendAnnouncement(MessageDetail messageDetail, NoticeModel noticeModel, String context) {
List<Receiver> receivers = noticeModel.getReceivers();
// 排除自己
if (noticeModel.isExcludeSelf()) {
receivers.removeIf(u -> StringUtils.equals(u.getUserId(), noticeModel.getOperator()));
}
if (CollectionUtils.isEmpty(receivers)) {
return;
}

View File

@ -28,10 +28,6 @@ public class LarkNoticeSender extends AbstractNoticeSender {
.map(ud -> "<at email=\"" + ud.getEmail() + "\">" + ud.getName() + "</at>")
.collect(Collectors.toList());
// 没有接收人不发通知
if (CollectionUtils.isEmpty(collect)) {
return;
}
LogUtil.info("飞书收件人: {}", userIds);
context += StringUtils.join(collect, " ");
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) {
List<Receiver> receivers = noticeModel.getReceivers();
if (CollectionUtils.isEmpty(receivers)) {
return;
}
TextMessage message = new TextMessage(context);
List<String> userIds = receivers.stream()
.map(Receiver::getUserId)
.distinct()
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(receivers)) {
List<String> userIds = receivers.stream()
.map(Receiver::getUserId)
.distinct()
.collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream()
.map(UserDetail::getPhone)
.distinct()
.collect(Collectors.toList());
List<String> phoneList = super.getUserDetails(userIds).stream()
.map(UserDetail::getPhone)
.distinct()
.collect(Collectors.toList());
message.setMentionedMobileList(phoneList);
if (CollectionUtils.isEmpty(phoneList)) {
return;
if (CollectionUtils.isNotEmpty(phoneList)) {
message.setMentionedMobileList(phoneList);
LogUtil.info("企业微信收件人: {}", userIds);
}
}
LogUtil.info("企业微信收件人: {}", userIds);
try {
WxChatbotClient.send(messageDetail.getWebhook(), message);
} catch (IOException e) {