feat: 待办飞书通知

This commit is contained in:
裴浩宇 2024-05-08 15:57:14 +08:00
parent 0c646549ca
commit 6720b83025
13 changed files with 106 additions and 29 deletions

View File

@ -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" +

View File

@ -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))
// 版本

View File

@ -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 = "<div\n" +
" style=\"border-radius: 10px 10px 10px 10px;font-size:13px; color: #555555;width: 666px;font-family:'Century Gothic','Trebuchet MS','Hiragino Sans GB',微软雅黑,'Microsoft Yahei',Tahoma,Helvetica,Arial,'SimSun',sans-serif;margin:50px auto;border:1px solid #eee;max-width:100%;background: #ffffff repeating-linear-gradient(-45deg,#fff,#fff 1.125rem,transparent 1.125rem,transparent 2.25rem);box-shadow: 0 1px 5px rgba(0, 0, 0, 0.15);\">\n" +
" <div\n" +
" style=\"width:100%;background:#49BDAD;color:#ffffff;border-radius: 10px 10px 0 0;background-image: -moz-linear-gradient(0deg, rgb(67, 198, 184), rgb(255, 209, 244));background-image: -webkit-linear-gradient(0deg, rgb(67, 198, 184), rgb(255, 209, 244));height: 66px;\">\n" +
" <p\n" +
" style=\"text-align: center;font-size:15px;word-break:break-all;padding: 23px 32px;margin:0;background-color: hsla(0,0%,100%,.4);border-radius: 10px 10px 0 0;\">\n" +
" <a style=\"text-decoration:none;color: #ffffff;\" href=\"https://pnkx.top\"\n" +
" rel=\"noopener\" target=\"_blank\">\n" +
" Pei你看雪博客\n" +
" </a>\n" +
" 用户注册\n" +
" </p>\n" +
" </div>\n" +
" <div style=\"margin:40px auto;width:90%\">\n" +
" <p>亲爱的template-nickName</p>\n" +
" <div\n" +
" style=\"background: #fafafa repeating-linear-gradient(-45deg,#fff,#fff 1.125rem,transparent 1.125rem,transparent 2.25rem);box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);margin:20px 0px;padding:15px;border-radius:5px;font-size:14px;color:#555555;\">\n" +
" <p>\n" +
" 感谢您注册\n" +
" <a style=\"text-decoration:none;color: #12addb;\" href=\"https://pnkx.top\"\n" +
" rel=\"noopener\" target=\"_blank\">\n" +
" Pei你看雪博客\n" +
" </a>,请点击下方按钮完成账户激活。\n" +
" </p>\n" +
" <p style=\"margin: 2rem 0;\">\n" +
" <a style=\"border-radius: 0.2rem; background-color:#12addb55;color:#ffffff;padding: 0.5rem 1rem;\" href=\"template-url\">激活账户</a>\n" +
" </p>\n" +
" <p>\n" +
" 欢迎再次光临\n" +
" <a style=\"text-decoration:none; color:#12addb\" href=\"https://pnkx.top/\"\n" +
" rel=\"noopener\" target=\"_blank\">\n" +
" Pei你看雪博客\n" +
" </a>\n" +
"\n" +
" </p>\n" +
" <p style='color:#5A8DEE;'>\n" +
" 欢迎关注公众号\n" +
" </p>\n" +
" <p>\n" +
" <img style='width:340px;height:120px; border-radius: 0.5rem'\n" +
" src=\"https://pnkx.cloud:8866/ftp/pnkx/images/wechat.jpg\"/>\n" +
" </p>\n" +
" <p style='color:#bbb;'>\n" +
" 回复邮件TD退订\n" +
" </p>\n" +
" </div>\n" +
" </div>\n" +
"</div>";
content = StringUtils.removeHtmlTags(content);
content = StringUtils.cleanText(content);
FeishuISysNotify.sendNotification("\uD83D\uDC49 叮咚「Pei你看雪博客」您的待办提醒~", content, "");
}
}

View File

@ -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");
}
/**
* 获取参数不为空值
*

View File

@ -19,7 +19,7 @@
感谢您注册
<a style="text-decoration:none;color: #12addb;" href="https://pnkx.top"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>,请点击下方按钮完成账户激活。
</p>
<p style="margin: 2rem 0;">
@ -29,7 +29,7 @@
欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -45,4 +45,4 @@
</p>
</div>
</div>
</div>
</div>

View File

@ -31,7 +31,7 @@
,欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -46,4 +46,4 @@
回复邮件TD退订
</p>
</div>
</div>
</div>

View File

@ -29,7 +29,7 @@
,欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -44,4 +44,4 @@
回复邮件TD退订
</p>
</div>
</div>
</div>

View File

@ -38,7 +38,7 @@
,欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -53,4 +53,4 @@
回复邮件TD退订
</p>
</div>
</div>
</div>

View File

@ -26,7 +26,7 @@
欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -42,4 +42,4 @@
</p>
</div>
</div>
</div>
</div>

View File

@ -22,7 +22,7 @@
欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -37,4 +37,4 @@
回复邮件TD退订
</p>
</div>
</div>
</div>

View File

@ -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());
}

View File

@ -28,7 +28,7 @@
,欢迎再次光临
<a style="text-decoration:none; color:#12addb" href="https://pnkx.top/"
rel="noopener" target="_blank">
pei你看雪博客
Pei你看雪博客
</a>
</p>
@ -43,4 +43,4 @@
回复邮件TD退订
</p>
</div>
</div>
</div>

View File

@ -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) {