Merge pull request #39 from linhaojun857/dev

merge dev
master
花未眠 3 years ago committed by GitHub
commit 4613708c49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -40,4 +40,6 @@ public interface CommonConstant {
String COMMENT_REMIND = "评论提醒";
String MENTION_REMIND = "@提醒";
}

@ -9,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import static com.aurora.constant.CommonConstant.*;
import static com.aurora.constant.RabbitMQConstant.EMAIL_QUEUE;
@Component
@ -21,12 +20,8 @@ public class CommentNoticeConsumer {
@RabbitHandler
public void process(byte[] data) {
EmailDTO mailDTO = JSON.parseObject(new String(data), EmailDTO.class);
if (CAPTCHA.equals(mailDTO.getSubject()) || CHECK_REMIND.equals(mailDTO.getSubject())) {
emailUtil.sendSimpleMail(mailDTO);
}
if (COMMENT_REMIND.equals(mailDTO.getSubject())) {
emailUtil.sendHtmlMail(mailDTO);
}
EmailDTO emailDTO = JSON.parseObject(new String(data), EmailDTO.class);
emailUtil.sendHtmlMail(emailDTO);
}
}

@ -15,7 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.aurora.constant.CommonConstant.TRUE;
@ -45,14 +47,20 @@ public class SubscribeConsumer {
List<String> emails = users.stream().map(UserInfo::getEmail).collect(Collectors.toList());
for (String email : emails) {
EmailDTO emailDTO = new EmailDTO();
Map<String, Object> map = new HashMap<>();
emailDTO.setEmail(email);
emailDTO.setSubject("文章订阅");
emailDTO.setTemplate("common.html");
String url = websiteUrl + "/articles/" + articleId;
if (article.getUpdateTime() == null) {
emailDTO.setContent("花未眠的个人博客发布了新的文章,地址:" + websiteUrl + "/articles/" + articleId);
map.put("content", "花未眠的个人博客发布了新的文章,"
+ "<a style=\"text-decoration:none;color:#12addb\" href=\"" + url + "\">点击查看</a>");
} else {
emailDTO.setContent("花未眠的个人博客对《" + article.getArticleTitle() + "》进行了更新,地址:" + websiteUrl + "/articles/" + articleId);
map.put("content", "花未眠的个人博客对《" + article.getArticleTitle() + "》进行了更新,"
+ "<a style=\"text-decoration:none;color:#12addb\" href=\"" + url + "\">点击查看</a>");
}
emailUtil.sendSimpleMail(emailDTO);
emailDTO.setCommentMap(map);
emailUtil.sendHtmlMail(emailDTO);
}
}

@ -25,7 +25,7 @@ public class CommentController {
@Autowired
private CommentService commentService;
@AccessLimit(seconds = 60,maxCount = 3)
@AccessLimit(seconds = 60, maxCount = 3)
@OptLog(optType = SAVE)
@ApiOperation("添加评论")
@PostMapping("/comments/save")

@ -36,7 +36,7 @@ public class AccessLimitInterceptor implements HandlerInterceptor {
if (accessLimit != null) {
long seconds = accessLimit.seconds();
int maxCount = accessLimit.maxCount();
String key = IpUtil.getIpAddress(httpServletRequest) + hm.getMethod().getName();
String key = IpUtil.getIpAddress(httpServletRequest) + "-" + hm.getMethod().getName();
try {
long q = redisService.incrExpire(key, seconds);
if (q > maxCount) {

@ -17,8 +17,6 @@ public class EmailDTO {
private String subject;
private String content;
private Map<String, Object> commentMap;
private String template;

@ -203,9 +203,7 @@ public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> impl
}
}
List<ArchiveDTO> archiveDTOs = new ArrayList<>();
map.forEach((key, value) -> {
archiveDTOs.add(ArchiveDTO.builder().Time(key).articles(value).build());
});
map.forEach((key, value) -> archiveDTOs.add(ArchiveDTO.builder().Time(key).articles(value).build()));
archiveDTOs.sort((o1, o2) -> {
String[] o1s = o1.getTime().split("-");
String[] o2s = o2.getTime().split("-");

@ -119,9 +119,7 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
List<ReplyDTO> replyDTOS = commentMapper.listReplies(commentIds);
Map<Integer, List<ReplyDTO>> replyMap = replyDTOS.stream()
.collect(Collectors.groupingBy(ReplyDTO::getParentId));
commentDTOs.forEach(item -> {
item.setReplyDTOs(replyMap.get(item.getId()));
});
commentDTOs.forEach(item -> item.setReplyDTOs(replyMap.get(item.getId())));
return new PageResultDTO<>(commentDTOs, commentCount);
}
@ -211,11 +209,40 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
private void notice(Comment comment, String fromNickname) {
if (comment.getUserId().equals(comment.getReplyUserId())) {
return;
if (Objects.nonNull(comment.getParentId())) {
Comment parentComment = commentMapper.selectById(comment.getParentId());
if (parentComment.getUserId().equals(comment.getUserId())) {
return;
}
}
}
if (comment.getUserId().equals(BLOGGER_ID) && Objects.isNull(comment.getParentId())) {
return;
}
if (Objects.nonNull(comment.getParentId())) {
Comment parentComment = commentMapper.selectById(comment.getParentId());
if (!comment.getReplyUserId().equals(parentComment.getUserId())
&& !comment.getReplyUserId().equals(comment.getUserId())) {
UserInfo userInfo = userInfoMapper.selectById(comment.getUserId());
UserInfo replyUserinfo = userInfoMapper.selectById(comment.getReplyUserId());
Map<String, Object> map = new HashMap<>();
String topicId = Objects.nonNull(comment.getTopicId()) ? comment.getTopicId().toString() : "";
String url = websiteUrl + getCommentPath(comment.getType()) + topicId;
map.put("content", userInfo.getNickname() + "在" + Objects.requireNonNull(getCommentEnum(comment.getType())).getDesc()
+ "的评论区@了你,"
+ "<a style=\"text-decoration:none;color:#12addb\" href=\"" + url + "\">点击查看</a>");
EmailDTO emailDTO = EmailDTO.builder()
.email(replyUserinfo.getEmail())
.subject(MENTION_REMIND)
.template("common.html")
.commentMap(map)
.build();
rabbitTemplate.convertAndSend(EMAIL_EXCHANGE, "*", new Message(JSON.toJSONBytes(emailDTO), new MessageProperties()));
}
if (comment.getUserId().equals(parentComment.getUserId())) {
return;
}
}
String title;
Integer userId = BLOGGER_ID;
String topicId = Objects.nonNull(comment.getTopicId()) ? comment.getTopicId().toString() : "";
@ -237,21 +264,21 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
} else {
title = Objects.requireNonNull(getCommentEnum(comment.getType())).getDesc();
}
UserInfo user = userInfoMapper.selectById(userId);
if (StringUtils.isNotBlank(user.getEmail())) {
EmailDTO emailDTO = getEmailDTO(comment, user, fromNickname, topicId, title, userId);
UserInfo userInfo = userInfoMapper.selectById(userId);
if (StringUtils.isNotBlank(userInfo.getEmail())) {
EmailDTO emailDTO = getEmailDTO(comment, userInfo, fromNickname, topicId, title);
rabbitTemplate.convertAndSend(EMAIL_EXCHANGE, "*", new Message(JSON.toJSONBytes(emailDTO), new MessageProperties()));
}
}
private EmailDTO getEmailDTO(Comment comment, UserInfo user, String fromNickname, String topicId, String title, Integer userId) {
private EmailDTO getEmailDTO(Comment comment, UserInfo userInfo, String fromNickname, String topicId, String title) {
EmailDTO emailDTO = new EmailDTO();
Map<String, Object> map = new HashMap<>();
if (comment.getIsReview().equals(TRUE)) {
Map<String, Object> map = new HashMap<>();
String url = websiteUrl + getCommentPath(comment.getType()) + topicId;
if (Objects.isNull(comment.getParentId())) {
emailDTO.setEmail(user.getEmail());
emailDTO.setSubject("评论提醒");
emailDTO.setEmail(userInfo.getEmail());
emailDTO.setSubject(COMMENT_REMIND);
emailDTO.setTemplate("owner.html");
String createTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(comment.getCreateTime());
map.put("time", createTime);
@ -260,26 +287,42 @@ public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> impl
map.put("nickname", fromNickname);
map.put("content", comment.getCommentContent());
} else {
Comment parentComment = commentMapper.selectOne(new LambdaQueryWrapper<Comment>().select(Comment::getCommentContent, Comment::getCreateTime).eq(Comment::getId, comment.getParentId()));
emailDTO.setEmail(user.getEmail());
emailDTO.setSubject("评论提醒");
Comment parentComment = commentMapper.selectOne(new LambdaQueryWrapper<Comment>().select(Comment::getUserId, Comment::getCommentContent, Comment::getCreateTime).eq(Comment::getId, comment.getParentId()));
if (!userInfo.getId().equals(parentComment.getUserId())) {
userInfo = userInfoMapper.selectById(parentComment.getUserId());
}
emailDTO.setEmail(userInfo.getEmail());
emailDTO.setSubject(COMMENT_REMIND);
emailDTO.setTemplate("user.html");
map.put("url", url);
map.put("title", title);
String createTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm").format(parentComment.getCreateTime());
map.put("time", createTime);
map.put("toUser", user.getNickname());
map.put("toUser", userInfo.getNickname());
map.put("fromUser", fromNickname);
map.put("parentComment", parentComment.getCommentContent());
map.put("replyComment", comment.getCommentContent());
if (!comment.getReplyUserId().equals(parentComment.getUserId())) {
UserInfo mentionUserInfo = userInfoMapper.selectById(comment.getReplyUserId());
if (Objects.nonNull(mentionUserInfo.getWebsite())) {
map.put("replyComment", "<a style=\"text-decoration:none;color:#12addb\" href=\""
+ mentionUserInfo.getWebsite()
+ "\">@" + mentionUserInfo.getNickname() + " " + "</a>" + parentComment.getCommentContent());
} else {
map.put("replyComment", "@" + mentionUserInfo.getNickname() + " " + parentComment.getCommentContent());
}
} else {
map.put("replyComment", parentComment.getCommentContent());
}
}
emailDTO.setCommentMap(map);
} else {
String adminEmail = userInfoMapper.selectById(BLOGGER_ID).getEmail();
emailDTO.setEmail(adminEmail);
emailDTO.setSubject("审核提醒");
emailDTO.setContent("您收到了一条新的回复,请前往后台管理页面审核");
emailDTO.setSubject(CHECK_REMIND);
emailDTO.setTemplate("common.html");
map.put("content", "您收到了一条新的回复,请前往后台管理页面审核");
}
emailDTO.setCommentMap(map);
return emailDTO;
}
}

@ -150,4 +150,5 @@ public class JobServiceImpl extends ServiceImpl<JobMapper, Job> implements JobSe
}
ScheduleUtil.createScheduleJob(scheduler, job);
}
}

@ -32,10 +32,7 @@ import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import static com.aurora.constant.RabbitMQConstant.EMAIL_EXCHANGE;
@ -78,10 +75,13 @@ public class UserAuthServiceImpl implements UserAuthService {
throw new BizException("请输入正确邮箱");
}
String code = getRandomCode();
Map<String, Object> map = new HashMap<>();
map.put("content", "您的验证码为 " + code + " 有效期15分钟请不要告诉他人哦");
EmailDTO emailDTO = EmailDTO.builder()
.email(username)
.subject("验证码")
.content("您的验证码为 " + code + " 有效期15分钟请不要告诉他人哦")
.template("common.html")
.commentMap(map)
.build();
rabbitTemplate.convertAndSend(EMAIL_EXCHANGE, "*", new Message(JSON.toJSONBytes(emailDTO), new MessageProperties()));
redisService.set(USER_CODE_KEY + username, code, CODE_EXPIRE_TIME);

@ -3,7 +3,6 @@ package com.aurora.util;
import com.aurora.model.dto.EmailDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
@ -25,15 +24,6 @@ public class EmailUtil {
@Autowired
private TemplateEngine templateEngine;
public void sendSimpleMail(EmailDTO emailDTO) {
SimpleMailMessage simpleMail = new SimpleMailMessage();
simpleMail.setFrom(email);
simpleMail.setTo(emailDTO.getEmail());
simpleMail.setSubject(emailDTO.getSubject());
simpleMail.setText(emailDTO.getContent());
javaMailSender.send(simpleMail);
}
public void sendHtmlMail(EmailDTO emailDTO) {
try {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="
border-radius: 10px 10px 10px 10px;
font-size: 13px;
color: #555555;
width: 666px;
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 rgb(0 0 0 / 15%);">
<div style="
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;">
<p style="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;">
来自<a style="text-decoration:none;
color:#12addb" href="https://www.linhaojun.top">花未眠的个人博客</a>的邮件
</p>
</div>
<div style="margin:20px auto;width:90%">
<div style="background: #f5f5f5;
margin:20px 0;
padding:15px;
border-radius:5px;
font-size:14px;">
<p th:utext="${content}"></p>
</div>
<div style="color: #8c8c8c; font-size: 10px;width: 100%;text-align: center;word-wrap: break-word;">
<p style="padding: 20px">不管当下的境遇如何,提瓦特大陆的星空永远会有你的位置。——《原神》</p>
</div>
</div>
</div>
</body>
</html>

@ -47,7 +47,7 @@
color:#12addb" th:href="@{${url}}" target="_blank">查看回复的完整內容</a>
</p>
<div style="color: #8c8c8c; font-size: 10px;width: 100%;text-align: center;word-wrap: break-word;">
<p style="padding: 20px">什么都无法舍弃的人,什么都改变不了。——《进击的巨人</p>
<p style="padding: 20px">不管当下的境遇如何,提瓦特大陆的星空永远会有你的位置。——《原神</p>
</div>
</div>
</div>

@ -147,20 +147,20 @@
</el-row>
<el-form-item label="邮箱通知">
<el-radio-group v-model="websiteConfigForm.isEmailNotice">
<el-radio :label="0">关闭</el-radio>
<el-radio :label="1">开启</el-radio>
<el-radio :label="0">关闭</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="评论审核">
<el-radio-group v-model="websiteConfigForm.isCommentReview">
<el-radio :label="0">关闭</el-radio>
<el-radio :label="1">开启</el-radio>
<el-radio :label="0">关闭</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="打赏状态">
<el-radio-group v-model="websiteConfigForm.isReward">
<el-radio :label="0">关闭</el-radio>
<el-radio :label="1">开启</el-radio>
<el-radio :label="0">关闭</el-radio>
</el-radio-group>
</el-form-item>
<el-row style="width: 600px" v-show="websiteConfigForm.isReward == 1">

@ -11,7 +11,7 @@
<b class="font-extrabold">{{ websiteConfig.author }}</b>
</li>
<li v-if="websiteConfig.beian_number != ''" class="flex flex-row gap-3 mx-auto">
<a href="https://beian.miit.gov.cn/">
<a href="https://beian.miit.gov.cn/" target="_blank">
<b class="font-extrabold border-b-2 border-ob hover:text-ob"> {{ websiteConfig.beianNumber }} </b>
</a>
</li>

@ -218,7 +218,7 @@ INSERT INTO `t_menu` VALUES (214, '网站管理', '/website', '/website/Website.
INSERT INTO `t_menu` VALUES (220, '定时任务日志', '/quartz/log/:quartzId', '/log/QuartzLog.vue', 'el-icon-myguanyuwo', '2022-07-28 10:53:23', '2022-08-05 10:27:47', 2, 19, 1);
INSERT INTO `t_menu` VALUES (221, '说说管理', '/talk-submenu', 'Layout', 'el-icon-mypinglun', '2022-08-15 17:27:10', '2022-08-15 17:27:39', 3, NULL, 0);
INSERT INTO `t_menu` VALUES (222, '说说列表', '/talk-list', '/talk/TalkList.vue', 'el-icon-myiconfontdongtaidianji', '2022-08-15 17:29:05', NULL, 1, 221, 0);
INSERT INTO `t_menu` VALUES (223, '发布说说', '/talks/:talkId', '/talk/Talk.vue', 'el-icon-myfabusekuai', '2022-08-15 17:34:26', '2022-08-16 16:06:04', 2, 221, 0);
INSERT INTO `t_menu` VALUES (223, '发布说说', '/talks', '/talk/Talk.vue', 'el-icon-myfabusekuai', '2022-08-15 17:34:26', '2022-08-16 16:06:04', 2, 221, 0);
INSERT INTO `t_menu` VALUES (224, '修改说说', '/talks/:talkId', '/talk/Talk.vue', 'el-icon-myfabusekuai', '2022-08-16 16:06:59', '2022-08-16 16:08:21', 3, 221, 1);
INSERT INTO `t_menu` VALUES (225, '异常日志', '/exception/log', '/log/ExceptionLog.vue', 'el-icon-myguanyuwo', '2022-08-25 13:40:08', '2022-08-25 13:40:31', 1, 19, 0);

Loading…
Cancel
Save