diff --git a/pnkx-admin/src/main/resources/application.yml b/pnkx-admin/src/main/resources/application.yml index c8c742f..d070cd3 100644 --- a/pnkx-admin/src/main/resources/application.yml +++ b/pnkx-admin/src/main/resources/application.yml @@ -57,7 +57,7 @@ spring: # 邮箱配置 mail: host: smtp.qq.com - userName: 617594538@qq.com + username: 617594538@qq.com #邮箱授权码 password: gormkqlrtleobecb properties: @@ -106,8 +106,3 @@ xss: excludes: /system/notice/* # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* - -feishu: - # 飞书机器人的webhook地址 - webhook: - url: https://open.feishu.cn/open-apis/bot/v2/hook/ae03114d-aa0d-4348-b12e-9bd7e2911399 diff --git a/pnkx-admin/src/test/java/NotifyTest.java b/pnkx-admin/src/test/java/NotifyTest.java index 0dc9107..7d6348a 100644 --- a/pnkx-admin/src/test/java/NotifyTest.java +++ b/pnkx-admin/src/test/java/NotifyTest.java @@ -1,10 +1,5 @@ -import com.pnkx.framework.notify.NotifyContext; -import com.pnkx.framework.notify.impl.EmailNotifyStrategy; +import com.pnkx.common.notify.FeishuISysNotify; import org.junit.Test; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.mail.javamail.JavaMailSender; - -import javax.annotation.Resource; /** * NotifyTest @@ -17,8 +12,7 @@ import javax.annotation.Resource; public class NotifyTest { @Test - public void notifyTest() throws Exception { - NotifyContext notifyContext = new NotifyContext(new EmailNotifyStrategy()); - notifyContext.send("617594538@qq.com", "测试通知"); + public void notifyTest() { + FeishuISysNotify.sendNotification("测试通知"); } } diff --git a/pnkx-framework/src/main/java/com/pnkx/framework/notify/impl/FeishuNotifyStrategy.java b/pnkx-common/src/main/java/com/pnkx/common/notify/FeishuISysNotify.java similarity index 74% rename from pnkx-framework/src/main/java/com/pnkx/framework/notify/impl/FeishuNotifyStrategy.java rename to pnkx-common/src/main/java/com/pnkx/common/notify/FeishuISysNotify.java index 210fcb5..29e1384 100644 --- a/pnkx-framework/src/main/java/com/pnkx/framework/notify/impl/FeishuNotifyStrategy.java +++ b/pnkx-common/src/main/java/com/pnkx/common/notify/FeishuISysNotify.java @@ -1,11 +1,7 @@ -package com.pnkx.framework.notify.impl; +package com.pnkx.common.notify; -import com.pnkx.common.core.controller.BaseController; -import com.pnkx.framework.notify.NotifyStrategy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; import java.io.IOException; import java.io.OutputStream; @@ -14,23 +10,21 @@ import java.net.URL; import java.nio.charset.StandardCharsets; /** - * FeishuNotifyStrategy + * FeishuISysNotify * * @author 裴浩宇 * @version 1.0 * @date 2024/4/30 17:04 * @description 飞书通知 */ -@Component -public class FeishuNotifyStrategy implements NotifyStrategy { +public class FeishuISysNotify { - protected final Logger logger = LoggerFactory.getLogger(FeishuNotifyStrategy.class); + protected static final Logger logger = LoggerFactory.getLogger(FeishuISysNotify.class); - @Value("${feishu.webhook.url}") - private String webhookUrl; + // 飞书机器人的webhook地址 + private static final String webhookUrl = "https://open.feishu.cn/open-apis/bot/v2/hook/ae03114d-aa0d-4348-b12e-9bd7e2911399"; - @Override - public void sendNotification(String recipient, String message) { + public static void sendNotification(String message) { try { URL url = new URL(webhookUrl); HttpURLConnection connection = getHttpURLConnection(message, url); diff --git a/pnkx-framework/src/main/java/com/pnkx/framework/aspectj/LogAspect.java b/pnkx-framework/src/main/java/com/pnkx/framework/aspectj/LogAspect.java index 0baf983..080bedb 100644 --- a/pnkx-framework/src/main/java/com/pnkx/framework/aspectj/LogAspect.java +++ b/pnkx-framework/src/main/java/com/pnkx/framework/aspectj/LogAspect.java @@ -141,9 +141,8 @@ public class LogAspect { * 获取请求的参数,放到log中 * * @param operLog 操作日志 - * @throws Exception 异常 */ - private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) throws Exception { + private void setRequestValue(JoinPoint joinPoint, SysOperLog operLog) { String requestMethod = operLog.getRequestMethod(); if (HttpMethod.PUT.name().equals(requestMethod) || HttpMethod.POST.name().equals(requestMethod)) { String params = argsArrayToString(joinPoint.getArgs()); diff --git a/pnkx-framework/src/main/java/com/pnkx/framework/notify/NotifyContext.java b/pnkx-framework/src/main/java/com/pnkx/framework/notify/NotifyContext.java deleted file mode 100644 index 6751112..0000000 --- a/pnkx-framework/src/main/java/com/pnkx/framework/notify/NotifyContext.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.pnkx.framework.notify; - -/** - * NotifyContext - * - * @author 裴浩宇 - * @version 1.0 - * @date 2024/4/30 17:09 - * @description 通知策略上下文 - */ -public class NotifyContext { - private final NotifyStrategy strategy; - - public NotifyContext(NotifyStrategy strategy) { - this.strategy = strategy; - } - - public void send(String recipient, String message) throws Exception { - strategy.sendNotification(recipient, message); - } -} diff --git a/pnkx-framework/src/main/java/com/pnkx/framework/notify/NotifyStrategy.java b/pnkx-framework/src/main/java/com/pnkx/framework/notify/NotifyStrategy.java deleted file mode 100644 index 52e3b14..0000000 --- a/pnkx-framework/src/main/java/com/pnkx/framework/notify/NotifyStrategy.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.pnkx.framework.notify; - -/** - * NotifyStrategy - * - * @author 裴浩宇 - * @version 1.0 - * @date 2024/4/30 16:50 - * @description 通知接口 - */ -public interface NotifyStrategy { - /** - * 发送通知 - * @param recipient 接收者 - * @param message 消息内容 - */ - void sendNotification(String recipient, String message) throws Exception; -} diff --git a/pnkx-framework/src/main/java/com/pnkx/framework/notify/impl/EmailNotifyStrategy.java b/pnkx-framework/src/main/java/com/pnkx/framework/notify/impl/EmailNotifyStrategy.java deleted file mode 100644 index b14e71a..0000000 --- a/pnkx-framework/src/main/java/com/pnkx/framework/notify/impl/EmailNotifyStrategy.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.pnkx.framework.notify.impl; - -import com.pnkx.common.exception.ServiceException; -import com.pnkx.common.utils.StringUtils; -import com.pnkx.common.utils.email.EmailUtils; -import com.pnkx.framework.notify.NotifyStrategy; -import com.pnkx.system.domain.SysEmail; -import com.pnkx.system.service.ISysEmailService; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.stereotype.Component; - -import javax.annotation.PostConstruct; -import javax.annotation.Resource; -import javax.mail.internet.MimeMessage; -import java.util.Arrays; -import java.util.Objects; -import java.util.regex.Pattern; - -/** - * EmailNotifyStrategy - * - * @author 裴浩宇 - * @version 1.0 - * @date 2024/4/30 16:56 - * @description 邮箱方式 - */ -@Component -public class EmailNotifyStrategy implements NotifyStrategy { - - @Override - public void sendNotification(String recipient, String message) throws Exception { - - } -}