mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
feat: filter invalid info in alarm service
This commit is contained in:
parent
464ce2dc0c
commit
c9b0cef1ea
@ -51,10 +51,14 @@ public class DingTalkAlarmService implements Alarmable {
|
||||
}
|
||||
Set<String> userIds = Sets.newHashSet();
|
||||
targetUserList.forEach(user -> {
|
||||
String phone = user.getPhone();
|
||||
if (StringUtils.isEmpty(phone)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String userId = mobile2UserIdCache.get(user.getPhone(), () -> {
|
||||
String userId = mobile2UserIdCache.get(phone, () -> {
|
||||
try {
|
||||
return dingTalkUtils.fetchUserIdByMobile(user.getPhone());
|
||||
return dingTalkUtils.fetchUserIdByMobile(phone);
|
||||
} catch (PowerJobException ignore) {
|
||||
return EMPTY_TAG;
|
||||
} catch (Exception ignore) {
|
||||
|
@ -14,6 +14,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 邮件通知服务
|
||||
@ -43,7 +44,7 @@ public class MailAlarmService implements Alarmable {
|
||||
SimpleMailMessage sm = new SimpleMailMessage();
|
||||
try {
|
||||
sm.setFrom(from);
|
||||
sm.setTo(targetUserList.stream().map(UserInfoDO::getEmail).toArray(String[]::new));
|
||||
sm.setTo(targetUserList.stream().map(UserInfoDO::getEmail).filter(Objects::nonNull).toArray(String[]::new));
|
||||
sm.setSubject(alarm.fetchTitle());
|
||||
sm.setText(alarm.fetchContent());
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.github.kfcfans.powerjob.server.test;
|
||||
|
||||
import com.github.kfcfans.powerjob.server.OhMyApplication;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.CronExpression;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.timewheel.HashedWheelTimer;
|
||||
import com.github.kfcfans.powerjob.server.common.utils.timewheel.TimerFuture;
|
||||
@ -11,9 +10,11 @@ import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 工具类测试
|
||||
@ -92,4 +93,11 @@ public class UtilsTest {
|
||||
System.out.println(StringUtils.containsWhitespace(goodAppName));
|
||||
System.out.println(StringUtils.containsWhitespace(appName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filterTest() {
|
||||
List<String> test = Lists.newArrayList("A", "B", null, "C", null);
|
||||
List<String> list = test.stream().filter(Objects::nonNull).collect(Collectors.toList());
|
||||
System.out.println(list);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user