list() {
@@ -29,6 +49,7 @@ public class CommentService {
/**
* 获取评论总数
+ *
* @return 评论总数
*/
public long count() {
@@ -37,6 +58,7 @@ public class CommentService {
/**
* 根据id查询评论对象
+ *
* @param id 评论id
* @return id对应的评论对象
*/
@@ -46,17 +68,106 @@ public class CommentService {
/**
* 保存评论
+ *
* @param comment 待保存的评论对象
*/
public void save(Comment comment) {
- commentMapper.save(comment);
+ // 如果是新评论
+ if (Objects.isNull(comment.getId())) {
+ // 有人在你的网站评论了
+ sendMailToWebsite(comment.getArticle().getId());
+ comment.setCreated(new Date());
+ comment.setView(false);
+ if (comment.getPid() != 0) {
+ // 有人回复了你的评论
+ sendMailToComment(comment.getArticle().getId(), comment.getPid(), comment.getContent());
+ // 展示它的父评论
+ Comment parent = detail(comment.getPid());
+ comment.setContent("@" + parent.getNickname() + ": " + comment.getContent());
+ comment.setPid(findCommentPid(comment.getPid()));
+ }
+ commentMapper.save(comment);
+ } else {
+ Comment one = detail(comment.getId());
+ UpdateUtil.copyNullProperties(comment, one);
+ commentMapper.save(one);
+ }
+ }
+
+ /**
+ * 网站有人留言了发送一封邮件给站长
+ *
+ * @param id 文章id
+ */
+ @Async
+ public void sendMailToWebsite(Integer id) {
+ Article article = articleMapper.findById(id).orElse(null);
+ if (Objects.isNull(article)) {
+ return;
+ }
+ String content = "\n" + " 你的文章 " + article.getTitle()
+ + "收到了新评论," +
+ "" + "点此" + "查看\n" + "
\n" +
+ "\n" + "时间:\n" + new Date() + "
";
+ mailHelper.sendMail(webSite.getMail(), webSite.getTitle() + "收到新评论", content);
+ }
+
+ /**
+ * 异步方法: 有人回复了你的评论,需要给你发送一封邮件
+ *
+ * @param id 文章id
+ * @param cid 被评论的评论id
+ * @param reply 回复内容
+ */
+ @Async
+ public void sendMailToComment(Integer id, Integer cid, String reply) {
+ Article article = articleMapper.findById(id).orElse(null);
+ if (Objects.isNull(article)) {
+ return;
+ }
+ Comment comment = commentMapper.findById(cid).orElse(null);
+ if (Objects.isNull(comment)) {
+ return;
+ }
+ String content = "\n" + " 你在" + webSite.getTitle() + "对 " + article.getTitle() + "文章的评论收到了新回复,回复内容如下:\n" + "
\n" + "\n" + reply + "
\n" + "\n" + " 一一发件人:" + webSite.getTitle() + "
\n" + "\n" + "时间:" + new Date() + "
\n" + "\n" + " 此邮件是由" + webSite.getTitle() + "自动发送,请勿回复 \n" + "
";
+ mailHelper.sendMail(comment.getEmail(), webSite.getTitle() + "收到新回复", content);
+ }
+
+ /**
+ * 递归查找直到找到最原始评论
+ *
+ * @param id 评论id
+ * @return 祖先评论的id
+ */
+ private Integer findCommentPid(Integer id) {
+ Comment comment = detail(id);
+ // 直到找到某个评论的pid为0,因为他就是最原始的评论
+ if (comment.getPid() == 0) {
+ return comment.getId();
+ }
+ return findCommentPid(comment.getPid());
}
/**
* 根据id删除评论对象
+ *
* @param id 待删除评论的id
*/
public void delete(Integer id) {
commentMapper.deleteById(id);
}
+
+ /**
+ * 返回文章的评论
+ *
+ * @param id 文章id
+ * @param pageNumber 初始页号
+ * @return 评论分页
+ */
+ public PageHelper show(Integer id, int pageNumber) {
+ // 每页显示5个评论
+ Page page = commentMapper.findAllByArticleAndPidOrderByCreatedDesc(Article.builder().id(id).build(), 0, PageRequest.of(pageNumber - 1, 5));
+ // 评论内容-当前页数-评论总数-总页数
+ return PageHelper.builder().rows(page.getContent().stream().peek(x -> x.setChildren(commentMapper.findAllByPidOrderByCreatedDesc(x.getId()))).collect(Collectors.toList())).currentPage(pageNumber).total(page.getTotalElements()).totalPages(page.getTotalPages()).build();
+ }
}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index a8634cd..f80f902 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -34,6 +34,21 @@ spring:
type: ehcache
ehcache:
config: classpath:/ehcache-spring.xml
+ mail:
+ # 默认的邮件编码为UTF-8
+ default-encoding: UTF-8
+ # 邮箱服务器
+ host: smtp.qq.com
+ # 邮箱
+ username: 1337425156@qq.com
+ # 密码
+ password: yidyoatxwswwjgjj
+ # 端口
+ port: 587
+ # 其它属性,这里只开启debug输出错误信息
+ properties:
+ debug: true
+
logging:
file:
@@ -81,3 +96,19 @@ default-images:
- /static/image/3.jpg
- /static/image/4.jpg
- /static/image/5.jpg
+ avatars:
+ - /static/image/avatar/1.jpg
+ - /static/image/avatar/2.jpg
+ - /static/image/avatar/3.jpg
+ - /static/image/avatar/4.jpg
+ - /static/image/avatar/5.jpg
+ - /static/image/avatar/6.jpg
+ - /static/image/avatar/7.jpg
+ - /static/image/avatar/8.jpg
+ - /static/image/avatar/9.jpg
+ - /static/image/avatar/10.jpg
+ - /static/image/avatar/11.jpg
+ - /static/image/avatar/12.jpg
+ - /static/image/avatar/13.jpg
+ - /static/image/avatar/14.jpg
+
diff --git a/src/main/resources/static/image/avatar/1.jpg b/src/main/resources/static/image/avatar/1.jpg
new file mode 100644
index 0000000..332cafa
Binary files /dev/null and b/src/main/resources/static/image/avatar/1.jpg differ
diff --git a/src/main/resources/static/image/avatar/10.jpg b/src/main/resources/static/image/avatar/10.jpg
new file mode 100644
index 0000000..526fc4b
Binary files /dev/null and b/src/main/resources/static/image/avatar/10.jpg differ
diff --git a/src/main/resources/static/image/avatar/11.jpg b/src/main/resources/static/image/avatar/11.jpg
new file mode 100644
index 0000000..460afb4
Binary files /dev/null and b/src/main/resources/static/image/avatar/11.jpg differ
diff --git a/src/main/resources/static/image/avatar/12.jpg b/src/main/resources/static/image/avatar/12.jpg
new file mode 100644
index 0000000..714dd63
Binary files /dev/null and b/src/main/resources/static/image/avatar/12.jpg differ
diff --git a/src/main/resources/static/image/avatar/13.jpg b/src/main/resources/static/image/avatar/13.jpg
new file mode 100644
index 0000000..6dcd460
Binary files /dev/null and b/src/main/resources/static/image/avatar/13.jpg differ
diff --git a/src/main/resources/static/image/avatar/14.jpg b/src/main/resources/static/image/avatar/14.jpg
new file mode 100644
index 0000000..0495fa2
Binary files /dev/null and b/src/main/resources/static/image/avatar/14.jpg differ
diff --git a/src/main/resources/static/image/avatar/2.jpg b/src/main/resources/static/image/avatar/2.jpg
new file mode 100644
index 0000000..a65aec8
Binary files /dev/null and b/src/main/resources/static/image/avatar/2.jpg differ
diff --git a/src/main/resources/static/image/avatar/3.jpg b/src/main/resources/static/image/avatar/3.jpg
new file mode 100644
index 0000000..c02e287
Binary files /dev/null and b/src/main/resources/static/image/avatar/3.jpg differ
diff --git a/src/main/resources/static/image/avatar/4.jpg b/src/main/resources/static/image/avatar/4.jpg
new file mode 100644
index 0000000..a805f74
Binary files /dev/null and b/src/main/resources/static/image/avatar/4.jpg differ
diff --git a/src/main/resources/static/image/avatar/5.jpg b/src/main/resources/static/image/avatar/5.jpg
new file mode 100644
index 0000000..233a1ec
Binary files /dev/null and b/src/main/resources/static/image/avatar/5.jpg differ
diff --git a/src/main/resources/static/image/avatar/6.jpg b/src/main/resources/static/image/avatar/6.jpg
new file mode 100644
index 0000000..288a759
Binary files /dev/null and b/src/main/resources/static/image/avatar/6.jpg differ
diff --git a/src/main/resources/static/image/avatar/7.jpg b/src/main/resources/static/image/avatar/7.jpg
new file mode 100644
index 0000000..49c5bb0
Binary files /dev/null and b/src/main/resources/static/image/avatar/7.jpg differ
diff --git a/src/main/resources/static/image/avatar/8.jpg b/src/main/resources/static/image/avatar/8.jpg
new file mode 100644
index 0000000..1ad4131
Binary files /dev/null and b/src/main/resources/static/image/avatar/8.jpg differ
diff --git a/src/main/resources/static/image/avatar/9.jpg b/src/main/resources/static/image/avatar/9.jpg
new file mode 100644
index 0000000..828d6d8
Binary files /dev/null and b/src/main/resources/static/image/avatar/9.jpg differ
diff --git a/src/main/resources/templates/common.html b/src/main/resources/templates/common.html
index aafef98..0098b83 100644
--- a/src/main/resources/templates/common.html
+++ b/src/main/resources/templates/common.html
@@ -28,7 +28,7 @@
>
-
+
diff --git a/src/main/resources/templates/detail.html b/src/main/resources/templates/detail.html
index c4b7907..a92f23f 100644
--- a/src/main/resources/templates/detail.html
+++ b/src/main/resources/templates/detail.html
@@ -66,13 +66,15 @@
- 首页
-
+
- 正文
-
+
-
+
+
+
+
+
-
-
@@ -292,7 +288,8 @@
-
+
+
@@ -328,6 +325,8 @@
+
+
--
-
-
-
-
-
-
- -
-
-
-
-
-
-
- -
-
-
-
-
-
+
+
+
+
+
-
-
xpboy 2022-06-03 18:32 回复
-- 已经解决,问题是后台的的永久链接--重写功能,一定要开启成功,我是开启没有成功,但是可以使用,部分功能受限,如点赞、登录、注册等。我是windows - iis,添加web.config放到网站根目录就可以了,希望踩坑的朋友注意了。具体的web.config伪静态规则代码,可以联系我免费提供哦 - qq24985536,希望帮助到大家
---
-
-
-
-
-
-
-
-VOODOO 2022-09-28 19:53 回复
-- @xpboy -
-- 谢谢
anle 2022-06-03 18:32 回复
-- 您好~我是俺没偷前端的运营,关注了您在分享的技术文章,觉得您的这套模板很棒,我们诚挚邀请您加入俺没偷前端CP主计划。完整福利和详细介绍请见:https://anlenotes.com/cp - 我们会给作者提供包括流量、创作分成等, 我们诚挚的邀请您并期待您的加入~
-王伟忘记使自己快乐 2022-06-03 18:32 回复
-- 你好,请问一下,搭建的网页,在本地访问一点问题都没有,通过互联网域名访问,打开很慢,而且显示不正常,电脑手机都是一样的,是什么问题呢
-+-
+
+
+
+
+
+
+
++ + 回复 + 取消回复 +
+ ++-
+
+
+
+
+
+
+
++ + + 回复 + 取消回复 +
+ ++- 首页
+ -
+
- -
-
-
-
-
-
+ -
+ 尾页
+
+小布丁 2022-06-03 18:32 回复
-- 为什么启用这个主题 后,评论用不了了,报错。
--- 首页
- - 1
- - 2
- - 3
- - 4
- - 5
- - 尾页
-