|
@@ -2,16 +2,13 @@ package cn.reghao.tnb.message.app.service;
|
|
|
|
|
|
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
import cn.reghao.jutil.jdk.thread.ThreadPoolWrapper;
|
|
|
import cn.reghao.tnb.common.util.ConstantId;
|
|
import cn.reghao.tnb.common.util.ConstantId;
|
|
|
-import cn.reghao.tnb.message.app.model.po.Webhook;
|
|
|
|
|
|
|
+import cn.reghao.tnb.message.api.dto.UserMessageDto;
|
|
|
import cn.reghao.tnb.message.app.service.notifier.Notify;
|
|
import cn.reghao.tnb.message.app.service.notifier.Notify;
|
|
|
import cn.reghao.tnb.message.app.service.notifier.ding.DingMsg;
|
|
import cn.reghao.tnb.message.app.service.notifier.ding.DingMsg;
|
|
|
import cn.reghao.tnb.message.app.service.notifier.ding.DingNotify;
|
|
import cn.reghao.tnb.message.app.service.notifier.ding.DingNotify;
|
|
|
import cn.reghao.tnb.message.app.service.notifier.email.EmailMsg;
|
|
import cn.reghao.tnb.message.app.service.notifier.email.EmailMsg;
|
|
|
import cn.reghao.tnb.message.app.service.notifier.email.EmailNotify;
|
|
import cn.reghao.tnb.message.app.service.notifier.email.EmailNotify;
|
|
|
-import cn.reghao.tnb.user.api.dto.UserMessageDto;
|
|
|
|
|
-import cn.reghao.tnb.user.api.iface.UserService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.ExecutorService;
|
|
@@ -25,28 +22,27 @@ import java.util.concurrent.ExecutorService;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Service
|
|
@Service
|
|
|
public class NotifyService {
|
|
public class NotifyService {
|
|
|
- @DubboReference(check = false, retries = 0)
|
|
|
|
|
- private UserService userService;
|
|
|
|
|
-
|
|
|
|
|
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 UserMessageService userMessageService;
|
|
|
|
|
|
|
|
- public NotifyService(DingNotify dingNotify, EmailNotify emailNotify) {
|
|
|
|
|
|
|
+ public NotifyService(DingNotify dingNotify, EmailNotify emailNotify,
|
|
|
|
|
+ UserMessageService userMessageService) {
|
|
|
this.dingNotify = dingNotify;
|
|
this.dingNotify = dingNotify;
|
|
|
this.emailNotify = emailNotify;
|
|
this.emailNotify = emailNotify;
|
|
|
|
|
+ this.userMessageService = userMessageService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public <T> void notify(String receiver, T msg) {
|
|
public <T> void notify(String receiver, T msg) {
|
|
|
if (msg instanceof DingMsg) {
|
|
if (msg instanceof DingMsg) {
|
|
|
DingMsg dingMsg = (DingMsg) msg;
|
|
DingMsg dingMsg = (DingMsg) msg;
|
|
|
- threadPool.execute(new NotifyTask<>(dingNotify, receiver, dingMsg, userService));
|
|
|
|
|
|
|
+ threadPool.execute(new NotifyTask<>(dingNotify, receiver, dingMsg, userMessageService));
|
|
|
} else if (msg instanceof EmailMsg) {
|
|
} else if (msg instanceof EmailMsg) {
|
|
|
EmailMsg emailMsg = (EmailMsg) msg;
|
|
EmailMsg emailMsg = (EmailMsg) msg;
|
|
|
- threadPool.execute(new NotifyTask<>(emailNotify, receiver, emailMsg, userService));
|
|
|
|
|
|
|
+ threadPool.execute(new NotifyTask<>(emailNotify, receiver, emailMsg, userMessageService));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param
|
|
* @param
|
|
|
* @return
|
|
* @return
|
|
@@ -56,13 +52,13 @@ public class NotifyService {
|
|
|
private final Notify<T> notify;
|
|
private final Notify<T> notify;
|
|
|
private final String receiver;
|
|
private final String receiver;
|
|
|
private final T msg;
|
|
private final T msg;
|
|
|
- private final UserService userService;
|
|
|
|
|
|
|
+ private final UserMessageService userMessageService;
|
|
|
|
|
|
|
|
- public NotifyTask(Notify<T> notify, String receiver, T msg, UserService userService) {
|
|
|
|
|
|
|
+ public NotifyTask(Notify<T> notify, String receiver, T msg, UserMessageService userMessageService) {
|
|
|
this.notify = notify;
|
|
this.notify = notify;
|
|
|
this.receiver = receiver;
|
|
this.receiver = receiver;
|
|
|
this.msg = msg;
|
|
this.msg = msg;
|
|
|
- this.userService = userService;
|
|
|
|
|
|
|
+ this.userMessageService = userMessageService;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -73,7 +69,7 @@ public class NotifyService {
|
|
|
String title = "发送通知失败";
|
|
String title = "发送通知失败";
|
|
|
String content = String.format("发送给 %s 的通知失败 -> %s", receiver, e.getMessage());
|
|
String content = String.format("发送给 %s 的通知失败 -> %s", receiver, e.getMessage());
|
|
|
UserMessageDto userMessageDto = new UserMessageDto(title, content, ConstantId.ANONYMOUS_USER_ID);
|
|
UserMessageDto userMessageDto = new UserMessageDto(title, content, ConstantId.ANONYMOUS_USER_ID);
|
|
|
- userService.sendUserMessage(userMessageDto);
|
|
|
|
|
|
|
+ userMessageService.addMessage(userMessageDto);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|