From eead4da948c78ec05e5c65ff98916fbaa54c6a0a Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Tue, 31 Aug 2021 15:05:09 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E4=BD=BF=E7=94=A8=E4=BD=93=E9=AA=8C=EF=BC=8C=E7=AB=99?= =?UTF-8?q?=E5=86=85=E9=80=9A=E7=9F=A5=E6=8E=A5=E6=94=B6=E4=BA=BA=E4=B8=8D?= =?UTF-8?q?=E5=8C=85=E6=8B=AC=E6=93=8D=E4=BD=9C=E4=BA=BA=EF=BC=8C=E4=B8=89?= =?UTF-8?q?=E6=96=B9=E9=80=9A=E7=9F=A5=E4=B8=8D=E9=99=90=E5=88=B6=E6=8E=A5?= =?UTF-8?q?=E6=94=B6=E4=BA=BA=E6=98=AF=E5=90=A6=E6=98=AF=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/sender/AbstractNoticeSender.java | 4 --- .../notice/sender/impl/DingNoticeSender.java | 33 +++++++++---------- .../sender/impl/InSiteNoticeSender.java | 5 +++ .../notice/sender/impl/LarkNoticeSender.java | 4 --- .../notice/sender/impl/WeComNoticeSender.java | 30 ++++++++--------- 5 files changed, 35 insertions(+), 41 deletions(-) diff --git a/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java index 28bdf5ebdb..6757ee6bc3 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/AbstractNoticeSender.java @@ -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() diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/DingNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/DingNoticeSender.java index 74a3466bc6..e3217a824e 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/impl/DingNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/DingNoticeSender.java @@ -21,33 +21,32 @@ public class DingNoticeSender extends AbstractNoticeSender { public void sendNailRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) { List 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 userIds = receivers.stream() - .map(Receiver::getUserId) - .distinct() - .collect(Collectors.toList()); + List userIds = receivers.stream() + .map(Receiver::getUserId) + .distinct() + .collect(Collectors.toList()); - List phoneList = super.getUserDetails(userIds).stream() - .map(UserDetail::getPhone) - .distinct() - .collect(Collectors.toList()); + List 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) { diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/InSiteNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/InSiteNoticeSender.java index fd085bb5a9..91028b6fba 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/impl/InSiteNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/InSiteNoticeSender.java @@ -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 receivers = noticeModel.getReceivers(); + // 排除自己 + if (noticeModel.isExcludeSelf()) { + receivers.removeIf(u -> StringUtils.equals(u.getUserId(), noticeModel.getOperator())); + } if (CollectionUtils.isEmpty(receivers)) { return; } diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java index c90e391378..651c0d4dcb 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/LarkNoticeSender.java @@ -28,10 +28,6 @@ public class LarkNoticeSender extends AbstractNoticeSender { .map(ud -> "" + ud.getName() + "") .collect(Collectors.toList()); - // 没有接收人不发通知 - if (CollectionUtils.isEmpty(collect)) { - return; - } LogUtil.info("飞书收件人: {}", userIds); context += StringUtils.join(collect, " "); LarkClient.send(messageDetail.getWebhook(), context); diff --git a/backend/src/main/java/io/metersphere/notice/sender/impl/WeComNoticeSender.java b/backend/src/main/java/io/metersphere/notice/sender/impl/WeComNoticeSender.java index b15a8a4cf9..e0ad2011ed 100644 --- a/backend/src/main/java/io/metersphere/notice/sender/impl/WeComNoticeSender.java +++ b/backend/src/main/java/io/metersphere/notice/sender/impl/WeComNoticeSender.java @@ -21,27 +21,25 @@ public class WeComNoticeSender extends AbstractNoticeSender { public void sendWechatRobot(MessageDetail messageDetail, NoticeModel noticeModel, String context) { List receivers = noticeModel.getReceivers(); - if (CollectionUtils.isEmpty(receivers)) { - return; - } + TextMessage message = new TextMessage(context); - List userIds = receivers.stream() - .map(Receiver::getUserId) - .distinct() - .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(receivers)) { + List userIds = receivers.stream() + .map(Receiver::getUserId) + .distinct() + .collect(Collectors.toList()); - List phoneList = super.getUserDetails(userIds).stream() - .map(UserDetail::getPhone) - .distinct() - .collect(Collectors.toList()); + List 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) {