|
@@ -1,5 +1,8 @@
|
|
|
package cn.reghao.devops.manager.notification.service;
|
|
package cn.reghao.devops.manager.notification.service;
|
|
|
|
|
|
|
|
|
|
+import cn.reghao.devops.manager.notification.db.repository.NotifyReceiverRepository;
|
|
|
|
|
+import cn.reghao.devops.manager.notification.model.NotifyType;
|
|
|
|
|
+import cn.reghao.devops.manager.notification.model.po.NotifyReceiver;
|
|
|
import cn.reghao.devops.manager.notification.service.notifier.Notify;
|
|
import cn.reghao.devops.manager.notification.service.notifier.Notify;
|
|
|
import cn.reghao.devops.manager.notification.service.notifier.ding.DingMsg;
|
|
import cn.reghao.devops.manager.notification.service.notifier.ding.DingMsg;
|
|
|
import cn.reghao.devops.manager.notification.service.notifier.ding.DingNotify;
|
|
import cn.reghao.devops.manager.notification.service.notifier.ding.DingNotify;
|
|
@@ -23,15 +26,31 @@ public class NotifyService {
|
|
|
private final ExecutorService threadPool = ThreadPoolWrapper.threadPool("notify-service");
|
|
private final ExecutorService threadPool = ThreadPoolWrapper.threadPool("notify-service");
|
|
|
private final DingNotify dingNotify;
|
|
private final DingNotify dingNotify;
|
|
|
private final EmailNotify emailNotify;
|
|
private final EmailNotify emailNotify;
|
|
|
|
|
+ private final NotifyReceiverRepository notifyReceiverRepository;
|
|
|
|
|
|
|
|
- public NotifyService(DingNotify dingNotify, EmailNotify emailNotify) {
|
|
|
|
|
|
|
+ public NotifyService(DingNotify dingNotify, EmailNotify emailNotify, NotifyReceiverRepository notifyReceiverRepository) {
|
|
|
this.dingNotify = dingNotify;
|
|
this.dingNotify = dingNotify;
|
|
|
this.emailNotify = emailNotify;
|
|
this.emailNotify = emailNotify;
|
|
|
|
|
+ this.notifyReceiverRepository = notifyReceiverRepository;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public <T> void notify(T msg) {
|
|
public <T> void notify(T msg) {
|
|
|
- String receiver = "";
|
|
|
|
|
- notify(receiver, msg);
|
|
|
|
|
|
|
+ String receiver;
|
|
|
|
|
+ if (msg instanceof DingMsg) {
|
|
|
|
|
+ NotifyReceiver notifyReceiver = notifyReceiverRepository.findByType(NotifyType.webhook.getName());
|
|
|
|
|
+ if (notifyReceiver != null) {
|
|
|
|
|
+ receiver = notifyReceiver.getUrl();
|
|
|
|
|
+ DingMsg dingMsg = (DingMsg) msg;
|
|
|
|
|
+ threadPool.execute(new NotifyTask<>(dingNotify, receiver, dingMsg));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (msg instanceof EmailMsg) {
|
|
|
|
|
+ NotifyReceiver notifyReceiver = notifyReceiverRepository.findByType(NotifyType.email.getName());
|
|
|
|
|
+ if (notifyReceiver != null) {
|
|
|
|
|
+ receiver = notifyReceiver.getUrl();
|
|
|
|
|
+ EmailMsg emailMsg = (EmailMsg) msg;
|
|
|
|
|
+ threadPool.execute(new NotifyTask<>(emailNotify, receiver, emailMsg));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public <T> void notify(String receiver, T msg) {
|
|
public <T> void notify(String receiver, T msg) {
|