refactor: 发送人去重复
This commit is contained in:
parent
6bdd7fdeac
commit
17d924f9e9
|
@ -2,9 +2,11 @@ package io.metersphere.notice.domain;
|
|||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@EqualsAndHashCode
|
||||
public class Receiver {
|
||||
private String userId;
|
||||
private String type;
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -127,16 +128,15 @@ public abstract class AbstractNoticeSender implements NoticeSender {
|
|||
break;
|
||||
case NoticeConstants.RelatedUser.CREATOR:
|
||||
Object creator = paramMap.get("creator");
|
||||
Object createUser = paramMap.get("createUser");
|
||||
Object userId1 = paramMap.get("userId");
|
||||
|
||||
if (creator != null) {
|
||||
toUsers.add(new Receiver(creator.toString(), NotificationConstants.Type.SYSTEM_NOTICE.name()));
|
||||
}
|
||||
Object createUser = paramMap.get("createUser");
|
||||
if (createUser != null) {
|
||||
toUsers.add(new Receiver(createUser.toString(), NotificationConstants.Type.SYSTEM_NOTICE.name()));
|
||||
}
|
||||
createUser = paramMap.get("userId");
|
||||
if (createUser != null) {
|
||||
} else if (createUser != null) {
|
||||
toUsers.add(new Receiver(createUser.toString(), NotificationConstants.Type.SYSTEM_NOTICE.name()));
|
||||
} else if (userId1 != null) {
|
||||
toUsers.add(new Receiver(userId1.toString(), NotificationConstants.Type.SYSTEM_NOTICE.name()));
|
||||
}
|
||||
break;
|
||||
case NoticeConstants.RelatedUser.MAINTAINER:
|
||||
|
@ -161,6 +161,8 @@ public abstract class AbstractNoticeSender implements NoticeSender {
|
|||
}
|
||||
// 排除自己
|
||||
toUsers.removeIf(u -> StringUtils.equals(u.getUserId(), noticeModel.getOperator()));
|
||||
return toUsers;
|
||||
// 去重复
|
||||
HashSet<Receiver> receivers = new HashSet<>(toUsers);
|
||||
return new ArrayList<>(receivers);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,10 @@ public class DingNoticeSender extends AbstractNoticeSender {
|
|||
text.setContent(context);
|
||||
request.setText(text);
|
||||
OapiRobotSendRequest.At at = new OapiRobotSendRequest.At();
|
||||
List<String> phoneList = super.getUserPhones(noticeModel, receivers.stream().map(Receiver::getUserId).collect(Collectors.toList()));
|
||||
List<String> phoneList = super.getUserPhones(noticeModel, receivers.stream()
|
||||
.map(Receiver::getUserId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList()));
|
||||
LogUtil.info("收件人地址: " + phoneList);
|
||||
at.setAtMobiles(phoneList);
|
||||
request.setAt(at);
|
||||
|
|
|
@ -37,7 +37,10 @@ public class MailNoticeSender extends AbstractNoticeSender {
|
|||
LogUtil.info("发件人地址" + javaMailSender.getUsername());
|
||||
LogUtil.info("helper" + helper);
|
||||
helper.setSubject("MeterSphere " + noticeModel.getSubject());
|
||||
List<String> userIds = noticeModel.getReceivers().stream().map(Receiver::getUserId).collect(Collectors.toList());
|
||||
List<String> userIds = noticeModel.getReceivers().stream()
|
||||
.map(Receiver::getUserId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<String> emails = super.getUserEmails(noticeModel, userIds);
|
||||
String[] users = emails.toArray(new String[0]);
|
||||
LogUtil.info("收件人地址: " + emails);
|
||||
|
|
|
@ -24,7 +24,10 @@ public class WeComNoticeSender extends AbstractNoticeSender {
|
|||
return;
|
||||
}
|
||||
TextMessage message = new TextMessage(context);
|
||||
List<String> phoneLists = super.getUserPhones(noticeModel, receivers.stream().map(Receiver::getUserId).collect(Collectors.toList()));
|
||||
List<String> phoneLists = super.getUserPhones(noticeModel, receivers.stream()
|
||||
.map(Receiver::getUserId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList()));
|
||||
message.setMentionedMobileList(phoneLists);
|
||||
try {
|
||||
WxChatbotClient.send(messageDetail.getWebhook(), message);
|
||||
|
|
Loading…
Reference in New Issue