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