From 6720b83025d3b2fa8c103f822dd0949fd286f9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A3=B4=E6=B5=A9=E5=AE=87?= <617594538@qq.com> Date: Wed, 8 May 2024 15:57:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BE=85=E5=8A=9E=E9=A3=9E=E4=B9=A6?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/pnkx/PnkxApplication.java | 2 +- .../com/pnkx/web/config/SwaggerConfig.java | 4 +- pnkx-admin/src/test/java/NotifyTest.java | 53 ++++++++++++++++++- .../com/pnkx/common/utils/StringUtils.java | 32 +++++++++++ .../main/resources/template/activation.html | 6 +-- .../src/main/resources/template/link.html | 4 +- .../src/main/resources/template/message.html | 4 +- .../src/main/resources/template/reply.html | 4 +- .../src/main/resources/template/rest.html | 4 +- .../src/main/resources/template/todo.html | 4 +- .../java/com/pnkx/quartz/task/PxTask.java | 3 +- .../src/main/resources/template/message.html | 4 +- .../service/impl/SysEmailServiceImpl.java | 11 ++-- 13 files changed, 106 insertions(+), 29 deletions(-) diff --git a/pnkx-admin/src/main/java/com/pnkx/PnkxApplication.java b/pnkx-admin/src/main/java/com/pnkx/PnkxApplication.java index 5cca3c5..e9c8d36 100644 --- a/pnkx-admin/src/main/java/com/pnkx/PnkxApplication.java +++ b/pnkx-admin/src/main/java/com/pnkx/PnkxApplication.java @@ -13,7 +13,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; public class PnkxApplication { public static void main(String[] args) { SpringApplication.run(PnkxApplication.class, args); - System.out.println("(♥◠‿◠)ノ゙ pei你看雪博客管理系统启动成功 ლ(´ڡ`ლ)゙ \n" + + System.out.println("(♥◠‿◠)ノ゙ Pei你看雪博客管理系统启动成功 ლ(´ڡ`ლ)゙ \n" + " _ \n" + " | |\n" + " _ __ _ __ | | ____ __ \n" + diff --git a/pnkx-admin/src/main/java/com/pnkx/web/config/SwaggerConfig.java b/pnkx-admin/src/main/java/com/pnkx/web/config/SwaggerConfig.java index 51998c4..b7499b1 100644 --- a/pnkx-admin/src/main/java/com/pnkx/web/config/SwaggerConfig.java +++ b/pnkx-admin/src/main/java/com/pnkx/web/config/SwaggerConfig.java @@ -114,9 +114,9 @@ public class SwaggerConfig { // 用ApiInfoBuilder进行定制 return new ApiInfoBuilder() // 设置标题 - .title("标题:pei你看雪博客管理_接口文档") + .title("标题:Pei你看雪博客管理_接口文档") // 描述 - .description("描述:用于管理pei你看雪博客") + .description("描述:用于管理Pei你看雪博客") // 作者信息 .contact(new Contact(pnkxConfig.getName(), null, null)) // 版本 diff --git a/pnkx-admin/src/test/java/NotifyTest.java b/pnkx-admin/src/test/java/NotifyTest.java index 4d568d5..b0e92c3 100644 --- a/pnkx-admin/src/test/java/NotifyTest.java +++ b/pnkx-admin/src/test/java/NotifyTest.java @@ -1,4 +1,5 @@ import com.pnkx.common.notify.FeishuISysNotify; +import com.pnkx.common.utils.StringUtils; import org.junit.Test; import java.io.IOException; @@ -15,6 +16,56 @@ public class NotifyTest { @Test public void notifyTest() { - FeishuISysNotify.sendNotification("您有待办", "/todo"); + String content = "\n" + + " \n" + + " \n" + + " \n" + + " Pei你看雪博客\n" + + " \n" + + " 用户注册\n" + + "

\n" + + " \n" + + "
\n" + + "

亲爱的template-nickName:

\n" + + " \n" + + "

\n" + + " 感谢您注册\n" + + " \n" + + " Pei你看雪博客\n" + + " ,请点击下方按钮完成账户激活。\n" + + "

\n" + + "

\n" + + " 激活账户\n" + + "

\n" + + "

\n" + + " 欢迎再次光临\n" + + " \n" + + " Pei你看雪博客\n" + + " \n" + + " 。\n" + + "

\n" + + "

\n" + + " 欢迎关注公众号\n" + + "

\n" + + "

\n" + + " \n" + + "

\n" + + "

\n" + + " 回复邮件TD退订\n" + + "

\n" + + "
\n" + + " \n" + + ""; + content = StringUtils.removeHtmlTags(content); + content = StringUtils.cleanText(content); + FeishuISysNotify.sendNotification("\uD83D\uDC49 叮咚!「Pei你看雪博客」您的待办提醒~", content, ""); } } diff --git a/pnkx-common/src/main/java/com/pnkx/common/utils/StringUtils.java b/pnkx-common/src/main/java/com/pnkx/common/utils/StringUtils.java index 97442e0..f01a69b 100644 --- a/pnkx-common/src/main/java/com/pnkx/common/utils/StringUtils.java +++ b/pnkx-common/src/main/java/com/pnkx/common/utils/StringUtils.java @@ -6,6 +6,8 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.pnkx.common.core.text.StrFormatter; @@ -25,6 +27,36 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils { */ private static final char SEPARATOR = '_'; + /** + * 移除html标签 + * @param htmlString html内容 + * @return 去除后内容 + */ + public static String removeHtmlTags(String htmlString) { + // 定义 HTML 标签的正则表达式 + String htmlPattern = "<[^>]*>"; + + // 使用正则表达式匹配 HTML 标签并替换为空字符串 + Pattern pattern = Pattern.compile(htmlPattern); + Matcher matcher = pattern.matcher(htmlString); + + return matcher.replaceAll(""); + } + + /** + * 清理文本,去除空格 + * @param text 文本 + * @return 清理后文本 + */ + public static String cleanText(String text) { + // 去掉字符串两端的空白字符 + String trimmedText = text.trim(); + // 去掉空行 + String noEmptyLines = trimmedText.replaceAll("(?m)^\\s*$", ""); + // 将多个连续的换行符替换为单个换行符 + return noEmptyLines.replaceAll("\\n+", "\\\\n"); + } + /** * 获取参数不为空值 * diff --git a/pnkx-common/src/main/resources/template/activation.html b/pnkx-common/src/main/resources/template/activation.html index aa6bbef..28987df 100644 --- a/pnkx-common/src/main/resources/template/activation.html +++ b/pnkx-common/src/main/resources/template/activation.html @@ -19,7 +19,7 @@ 感谢您注册 - pei你看雪博客 + Pei你看雪博客 ,请点击下方按钮完成账户激活。

@@ -29,7 +29,7 @@ 欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -45,4 +45,4 @@

- \ No newline at end of file + diff --git a/pnkx-common/src/main/resources/template/link.html b/pnkx-common/src/main/resources/template/link.html index 3338291..66c37ee 100644 --- a/pnkx-common/src/main/resources/template/link.html +++ b/pnkx-common/src/main/resources/template/link.html @@ -31,7 +31,7 @@ ,欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -46,4 +46,4 @@ 回复邮件TD退订

- \ No newline at end of file + diff --git a/pnkx-common/src/main/resources/template/message.html b/pnkx-common/src/main/resources/template/message.html index 6ddd874..103ce2f 100644 --- a/pnkx-common/src/main/resources/template/message.html +++ b/pnkx-common/src/main/resources/template/message.html @@ -29,7 +29,7 @@ ,欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -44,4 +44,4 @@ 回复邮件TD退订

- \ No newline at end of file + diff --git a/pnkx-common/src/main/resources/template/reply.html b/pnkx-common/src/main/resources/template/reply.html index 3227911..aad1e22 100644 --- a/pnkx-common/src/main/resources/template/reply.html +++ b/pnkx-common/src/main/resources/template/reply.html @@ -38,7 +38,7 @@ ,欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -53,4 +53,4 @@ 回复邮件TD退订

- \ No newline at end of file + diff --git a/pnkx-common/src/main/resources/template/rest.html b/pnkx-common/src/main/resources/template/rest.html index 924a8b8..9078690 100644 --- a/pnkx-common/src/main/resources/template/rest.html +++ b/pnkx-common/src/main/resources/template/rest.html @@ -26,7 +26,7 @@ 欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -42,4 +42,4 @@

- \ No newline at end of file + diff --git a/pnkx-common/src/main/resources/template/todo.html b/pnkx-common/src/main/resources/template/todo.html index 7a8d8bb..5a8b91a 100644 --- a/pnkx-common/src/main/resources/template/todo.html +++ b/pnkx-common/src/main/resources/template/todo.html @@ -22,7 +22,7 @@ 欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -37,4 +37,4 @@ 回复邮件TD退订

- \ No newline at end of file + diff --git a/pnkx-quartz/src/main/java/com/pnkx/quartz/task/PxTask.java b/pnkx-quartz/src/main/java/com/pnkx/quartz/task/PxTask.java index ab8faa7..689882a 100644 --- a/pnkx-quartz/src/main/java/com/pnkx/quartz/task/PxTask.java +++ b/pnkx-quartz/src/main/java/com/pnkx/quartz/task/PxTask.java @@ -48,7 +48,7 @@ public class PxTask { @Resource private RedisTemplate redisTemplate; - private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class); + private static Logger logger = LoggerFactory.getLogger(PxTask.class); /** * 定时清理在线聊天室缓存 @@ -109,7 +109,6 @@ public class PxTask { sysEmail.setContent(activationTemplate); try { sysEmailService.sendMail(sysEmail); - FeishuISysNotify.sendNotification(todoRemind.toString(), "/mytool/todo"); } catch (Exception e) { logger.error("发送待办提醒邮件异常,异常信息为:{}", e.getMessage()); } diff --git a/pnkx-quartz/src/main/resources/template/message.html b/pnkx-quartz/src/main/resources/template/message.html index 5bdd0f7..2d848b5 100644 --- a/pnkx-quartz/src/main/resources/template/message.html +++ b/pnkx-quartz/src/main/resources/template/message.html @@ -28,7 +28,7 @@ ,欢迎再次光临 - pei你看雪博客 + Pei你看雪博客

@@ -43,4 +43,4 @@ 回复邮件TD退订

- \ No newline at end of file + diff --git a/pnkx-system/src/main/java/com/pnkx/system/service/impl/SysEmailServiceImpl.java b/pnkx-system/src/main/java/com/pnkx/system/service/impl/SysEmailServiceImpl.java index 76b601b..04ee325 100644 --- a/pnkx-system/src/main/java/com/pnkx/system/service/impl/SysEmailServiceImpl.java +++ b/pnkx-system/src/main/java/com/pnkx/system/service/impl/SysEmailServiceImpl.java @@ -1,5 +1,6 @@ package com.pnkx.system.service.impl; +import com.pnkx.common.notify.FeishuISysNotify; import com.pnkx.common.utils.DateUtils; import com.pnkx.common.utils.StringUtils; import com.pnkx.common.utils.email.EmailUtils; @@ -7,24 +8,16 @@ import com.pnkx.system.domain.SysEmail; import com.pnkx.system.mapper.SysEmailMapper; import com.pnkx.system.service.ISysEmailService; import org.springframework.beans.factory.annotation.Value; -import org.springframework.mail.MailSendException; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; -import javax.mail.Address; import javax.mail.MessagingException; -import javax.mail.SendFailedException; -import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; -import java.util.regex.Pattern; -import java.util.stream.Collectors; /** * @author by PHY @@ -100,6 +93,8 @@ public class SysEmailServiceImpl implements ISysEmailService { @Override @Transactional public void sendMail(SysEmail email) throws MessagingException { + // 飞书通知 + FeishuISysNotify.sendNotification(email.getSubject(), ""); sysEmailMapper.insertSysEmail(email); String[] to = EmailUtils.validEmail(email.getReceiverEmail()); if (to != null && to.length > 0) {