新增自定义通知类型以及通知bug修复
This commit is contained in:
@@ -10,10 +10,11 @@ public enum NotifyType {
|
||||
|
||||
|
||||
/**
|
||||
* 邮件类型
|
||||
* 通知类型
|
||||
*/
|
||||
TYPE_LOG("日志输出"),
|
||||
TYPE_MAIL("邮件"),
|
||||
TYPE_CUSTOM("自定义"),
|
||||
TYPE_MSG("短信");
|
||||
|
||||
private final String typeName;
|
||||
|
@@ -1,7 +1,6 @@
|
||||
package com.hxuanyu.notify.service;
|
||||
|
||||
import com.hxuanyu.notify.enums.NotifyType;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 通知服务
|
||||
@@ -17,4 +16,18 @@ public interface NotifyService {
|
||||
* @param notifyType 通知类型
|
||||
*/
|
||||
void notify(Object content, NotifyType notifyType);
|
||||
|
||||
/**
|
||||
* 自定义通知
|
||||
*
|
||||
* @param customNotify 自定义通知接口,需手动实现
|
||||
*/
|
||||
void notify(CustomNotify customNotify);
|
||||
|
||||
interface CustomNotify {
|
||||
/**
|
||||
* 通知
|
||||
*/
|
||||
void onNotify();
|
||||
}
|
||||
}
|
||||
|
@@ -25,17 +25,26 @@ public class NotifyServiceImpl implements NotifyService {
|
||||
|
||||
@Override
|
||||
public void notify(Object content, NotifyType notifyType) {
|
||||
logger.debug("通知内容:{},通知类型:{}", notifyType, notifyType);
|
||||
if (NotifyType.TYPE_MAIL.equals(notifyType)) {
|
||||
sendMail(content);
|
||||
} else if (NotifyType.TYPE_MSG.equals(notifyType)) {
|
||||
sendSms(content);
|
||||
} else if (NotifyType.TYPE_LOG.equals(notifyType)) {
|
||||
logger.info("新通知:{}", content);
|
||||
} else if (NotifyType.TYPE_CUSTOM.equals(notifyType)) {
|
||||
logger.warn("您选择了自定义通知,请实现CustomNotify接口并调用 notify(CustomNotify customNotify方法)");
|
||||
} else {
|
||||
logger.info("未匹配到通知类型:[{}]", content);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notify(CustomNotify customNotify) {
|
||||
logger.debug("执行自定义通知");
|
||||
customNotify.onNotify();
|
||||
}
|
||||
|
||||
private void sendSms(Object content) {
|
||||
logger.info("即将发送短信通知,通知内容:{}", content);
|
||||
}
|
||||
|
Reference in New Issue
Block a user