From 633bfd3e12870e9b27ccdff06f7504320ed2f558 Mon Sep 17 00:00:00 2001 From: "Captain.B" Date: Thu, 22 Oct 2020 17:59:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=A3=80=E6=9F=A5=20userIds=20?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/notice/service/DingTaskService.java | 4 ++++ .../io/metersphere/notice/service/MailService.java | 12 +++++++++--- .../notice/service/WxChatTaskService.java | 6 +++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java b/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java index 809806c10d..ac1112bad7 100644 --- a/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java +++ b/backend/src/main/java/io/metersphere/notice/service/DingTaskService.java @@ -9,6 +9,7 @@ import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.notice.domain.MessageDetail; import io.metersphere.notice.domain.UserDetail; import io.metersphere.service.UserService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -53,6 +54,9 @@ public class DingTaskService { } public void sendDingTask(String context, List userIds, String Webhook) { + if (CollectionUtils.isEmpty(userIds)) { + return; + } DingTalkClient client = new DefaultDingTalkClient(Webhook); OapiRobotSendRequest request = new OapiRobotSendRequest(); request.setMsgtype("text"); diff --git a/backend/src/main/java/io/metersphere/notice/service/MailService.java b/backend/src/main/java/io/metersphere/notice/service/MailService.java index c0ec7f458f..516be9d7bf 100644 --- a/backend/src/main/java/io/metersphere/notice/service/MailService.java +++ b/backend/src/main/java/io/metersphere/notice/service/MailService.java @@ -281,6 +281,9 @@ public class MailService { } private void sendReviewNotice(List userIds, Map context, String Template) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } JavaMailSenderImpl javaMailSender = getMailSender(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); @@ -301,6 +304,9 @@ public class MailService { } private void sendTestPlanNotice(List userIds, Map context, String Template) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } JavaMailSenderImpl javaMailSender = getMailSender(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); @@ -308,9 +314,6 @@ public class MailService { helper.setSubject("MeterSphere平台" + Translator.get("test_plan_notification")); String[] users; List emails = new ArrayList<>(); - if (CollectionUtils.isEmpty(userIds)) { - return; - } List list = userService.queryTypeByIds(userIds); list.forEach(u -> { emails.add(u.getEmail()); @@ -323,6 +326,9 @@ public class MailService { } private void sendIssuesNotice(List userIds, Map context, String Template) throws MessagingException { + if (CollectionUtils.isEmpty(userIds)) { + return; + } JavaMailSenderImpl javaMailSender = getMailSender(); MimeMessage mimeMessage = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); diff --git a/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java b/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java index b2127f0f32..c7b71ae205 100644 --- a/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java +++ b/backend/src/main/java/io/metersphere/notice/service/WxChatTaskService.java @@ -7,6 +7,7 @@ import io.metersphere.notice.message.TextMessage; import io.metersphere.notice.util.SendResult; import io.metersphere.notice.util.WxChatbotClient; import io.metersphere.service.UserService; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -52,8 +53,11 @@ public class WxChatTaskService { } public void enterpriseWechatTask(String context, List userIds, String Webhook) { + if (CollectionUtils.isEmpty(userIds)) { + return; + } TextMessage message = new TextMessage(context); - List mentionedMobileList = new ArrayList(); + List mentionedMobileList = new ArrayList<>(); List list = userService.queryTypeByIds(userIds); List phoneList = new ArrayList<>(); list.forEach(u -> {