refactor: 兼容context为空的问题

This commit is contained in:
Captain.B 2021-08-24 19:11:39 +08:00 committed by 刘瑞斌
parent b913e2b804
commit f3cc9bd166
1 changed files with 13 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import io.metersphere.notice.domain.MessageDetail;
import io.metersphere.notice.domain.Receiver; import io.metersphere.notice.domain.Receiver;
import io.metersphere.notice.domain.UserDetail; import io.metersphere.notice.domain.UserDetail;
import io.metersphere.service.UserService; import io.metersphere.service.UserService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RegExUtils; import org.apache.commons.lang3.RegExUtils;
@ -137,10 +138,12 @@ public abstract class AbstractNoticeSender implements NoticeSender {
case NoticeConstants.RelatedUser.EXECUTOR: case NoticeConstants.RelatedUser.EXECUTOR:
if (StringUtils.equals(NoticeConstants.Event.CREATE, event)) { if (StringUtils.equals(NoticeConstants.Event.CREATE, event)) {
List<String> relatedUsers = (List<String>) paramMap.get("userIds"); List<String> relatedUsers = (List<String>) paramMap.get("userIds");
List<Receiver> receivers = relatedUsers.stream() if (CollectionUtils.isNotEmpty(relatedUsers)) {
.map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name())) List<Receiver> receivers = relatedUsers.stream()
.collect(Collectors.toList()); .map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name()))
toUsers.addAll(receivers); .collect(Collectors.toList());
toUsers.addAll(receivers);
}
} }
break; break;
case NoticeConstants.RelatedUser.CREATOR: case NoticeConstants.RelatedUser.CREATOR:
@ -162,10 +165,12 @@ public abstract class AbstractNoticeSender implements NoticeSender {
case NoticeConstants.RelatedUser.MAINTAINER: case NoticeConstants.RelatedUser.MAINTAINER:
if (StringUtils.equals(NoticeConstants.Event.COMMENT, event)) { if (StringUtils.equals(NoticeConstants.Event.COMMENT, event)) {
List<String> relatedUsers = (List<String>) paramMap.get("userIds"); List<String> relatedUsers = (List<String>) paramMap.get("userIds");
List<Receiver> receivers = relatedUsers.stream() if (CollectionUtils.isNotEmpty(relatedUsers)) {
.map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name())) List<Receiver> receivers = relatedUsers.stream()
.collect(Collectors.toList()); .map(u -> new Receiver(u, NotificationConstants.Type.SYSTEM_NOTICE.name()))
toUsers.addAll(receivers); .collect(Collectors.toList());
toUsers.addAll(receivers);
}
} }
break; break;
case NoticeConstants.RelatedUser.FOLLOW_PEOPLE: case NoticeConstants.RelatedUser.FOLLOW_PEOPLE: