refactor: 检查 userIds 是否为空

This commit is contained in:
Captain.B 2020-10-22 17:59:56 +08:00
parent dd8d52a32d
commit 633bfd3e12
3 changed files with 18 additions and 4 deletions

View File

@ -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<String> userIds, String Webhook) {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
DingTalkClient client = new DefaultDingTalkClient(Webhook);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");

View File

@ -281,6 +281,9 @@ public class MailService {
}
private void sendReviewNotice(List<String> userIds, Map<String, String> 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<String> userIds, Map<String, String> 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<String> emails = new ArrayList<>();
if (CollectionUtils.isEmpty(userIds)) {
return;
}
List<UserDetail> list = userService.queryTypeByIds(userIds);
list.forEach(u -> {
emails.add(u.getEmail());
@ -323,6 +326,9 @@ public class MailService {
}
private void sendIssuesNotice(List<String> userIds, Map<String, String> context, String Template) throws MessagingException {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
JavaMailSenderImpl javaMailSender = getMailSender();
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);

View File

@ -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<String> userIds, String Webhook) {
if (CollectionUtils.isEmpty(userIds)) {
return;
}
TextMessage message = new TextMessage(context);
List<String> mentionedMobileList = new ArrayList<String>();
List<String> mentionedMobileList = new ArrayList<>();
List<UserDetail> list = userService.queryTypeByIds(userIds);
List<String> phoneList = new ArrayList<>();
list.forEach(u -> {