From 185d1e382d1baf33b2431a58a27caf7ac489117c Mon Sep 17 00:00:00 2001 From: barney <15270405776@163.com> Date: Tue, 25 Oct 2022 17:03:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E7=B3=BB=E7=BB=9F=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=81=E6=98=BE=E7=A4=BA=E5=8D=9A=E4=B8=BB=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E3=80=81=E4=BC=98=E5=8C=96=E5=A4=9A=E4=B8=AA=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/bnblogs/common/DefaultImages.java | 6 +++-- .../java/cc/bnblogs/config/WebConfig.java | 1 - .../bnblogs/controller/AdminController.java | 6 ++--- .../java/cc/bnblogs/enums/ResultEnum.java | 1 - .../java/cc/bnblogs/mapper/ArticleMapper.java | 12 +++++++--- .../cc/bnblogs/mapper/CategoryMapper.java | 2 -- .../java/cc/bnblogs/mapper/TagMapper.java | 2 -- .../cc/bnblogs/service/ArticleService.java | 7 +++++- .../cc/bnblogs/service/CategoryService.java | 3 ++- .../cc/bnblogs/service/CommentService.java | 14 ++++++++++- .../java/cc/bnblogs/service/TagService.java | 1 - .../java/cc/bnblogs/utils/UpdateUtil.java | 2 ++ src/main/resources/application.yml | 23 +++++++++++++------ src/main/resources/templates/admin/index.html | 2 +- src/main/resources/templates/detail.html | 4 +++- 15 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/main/java/cc/bnblogs/common/DefaultImages.java b/src/main/java/cc/bnblogs/common/DefaultImages.java index 6b2df3d..6e47e22 100644 --- a/src/main/java/cc/bnblogs/common/DefaultImages.java +++ b/src/main/java/cc/bnblogs/common/DefaultImages.java @@ -1,8 +1,6 @@ package cc.bnblogs.common; -import cc.bnblogs.config.WebConfig; import lombok.Data; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.thymeleaf.util.StringUtils; @@ -43,6 +41,10 @@ public class DefaultImages { public String avatar(String mail) { Pattern pattern = Pattern.compile("(\\d{5,10})@qq.com"); + // 评论使用站长自定义的头像 + if (mail.equals(webSite.getMail())) { + return webSite.getAvatar(); + } Matcher matcher = pattern.matcher(mail); if (matcher.find()) { String qq = matcher.group(1); diff --git a/src/main/java/cc/bnblogs/config/WebConfig.java b/src/main/java/cc/bnblogs/config/WebConfig.java index c83304d..db3c15d 100644 --- a/src/main/java/cc/bnblogs/config/WebConfig.java +++ b/src/main/java/cc/bnblogs/config/WebConfig.java @@ -3,7 +3,6 @@ package cc.bnblogs.config; import cc.bnblogs.common.LRUCache; import cc.bnblogs.interceptor.LoginInterceptor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.server.ConfigurableWebServerFactory; import org.springframework.boot.web.server.ErrorPage; diff --git a/src/main/java/cc/bnblogs/controller/AdminController.java b/src/main/java/cc/bnblogs/controller/AdminController.java index 4639253..457e586 100644 --- a/src/main/java/cc/bnblogs/controller/AdminController.java +++ b/src/main/java/cc/bnblogs/controller/AdminController.java @@ -1,7 +1,6 @@ package cc.bnblogs.controller; import cc.bnblogs.common.ArticleSearch; -import cc.bnblogs.common.Result; import cc.bnblogs.common.WebSite; import cc.bnblogs.pojo.Article; import cc.bnblogs.pojo.Category; @@ -42,8 +41,9 @@ public class AdminController { @GetMapping("/") public String index(Model model) { - // 获取文章总数、分类总数、总评论数、未读评论数、最新的5篇文章、最新的5条评论 - model.addAttribute("ArticleCount",articleService.count()); + // 获取文章总数、页面总数、分类总数、总评论数、未读评论数、最新的5篇文章、最新的5条评论 + model.addAttribute("ArticleCount",articleService.count() - articleService.countPages()); + model.addAttribute("PagesCount",articleService.countPages()); model.addAttribute("CategoryCount",categoryService.count()); model.addAttribute("CommentAll",commentService.count(null)); model.addAttribute("CommentNotReadCount",commentService.count(false)); diff --git a/src/main/java/cc/bnblogs/enums/ResultEnum.java b/src/main/java/cc/bnblogs/enums/ResultEnum.java index dc17832..e7edd5b 100644 --- a/src/main/java/cc/bnblogs/enums/ResultEnum.java +++ b/src/main/java/cc/bnblogs/enums/ResultEnum.java @@ -1,6 +1,5 @@ package cc.bnblogs.enums; -import ch.qos.logback.classic.spi.ILoggingEvent; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/cc/bnblogs/mapper/ArticleMapper.java b/src/main/java/cc/bnblogs/mapper/ArticleMapper.java index e8541cc..b715d1f 100644 --- a/src/main/java/cc/bnblogs/mapper/ArticleMapper.java +++ b/src/main/java/cc/bnblogs/mapper/ArticleMapper.java @@ -25,12 +25,11 @@ public interface ArticleMapper extends JpaRepository, JpaSpecif List
hotList(int limit); /** - * 统计该分类文章数 - * todo 应该减去页面数 + * 统计该分类文章数(但是不统计页面) * @param category 分类 * @return 文章个数 */ - Long countByCategory(Category category); + Long countByCategoryAndType(Category category, Integer type); /** * 返回该分类下最后一次更新时间 @@ -61,5 +60,12 @@ public interface ArticleMapper extends JpaRepository, JpaSpecif "where bc.name='默认分类' and ba.category_id=?1", nativeQuery = true) void updateToDefaultCategory(Integer articleCategoryId); + /** + * 根据页面类型返回博客数量 + * @param type 页面类型(文章/页面) + * @return 博客数量 + */ + Long countArticleByType(Integer type); + } diff --git a/src/main/java/cc/bnblogs/mapper/CategoryMapper.java b/src/main/java/cc/bnblogs/mapper/CategoryMapper.java index 09f60af..94c7fd4 100644 --- a/src/main/java/cc/bnblogs/mapper/CategoryMapper.java +++ b/src/main/java/cc/bnblogs/mapper/CategoryMapper.java @@ -7,8 +7,6 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * @author zfp@bnblogs.cc * @createTime: 2022/10/16 diff --git a/src/main/java/cc/bnblogs/mapper/TagMapper.java b/src/main/java/cc/bnblogs/mapper/TagMapper.java index 33c2203..b1e2013 100644 --- a/src/main/java/cc/bnblogs/mapper/TagMapper.java +++ b/src/main/java/cc/bnblogs/mapper/TagMapper.java @@ -3,8 +3,6 @@ package cc.bnblogs.mapper; import cc.bnblogs.pojo.Tag; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; - -import javax.persistence.criteria.CriteriaBuilder; import java.util.List; /** diff --git a/src/main/java/cc/bnblogs/service/ArticleService.java b/src/main/java/cc/bnblogs/service/ArticleService.java index 41aacab..33bb882 100644 --- a/src/main/java/cc/bnblogs/service/ArticleService.java +++ b/src/main/java/cc/bnblogs/service/ArticleService.java @@ -67,13 +67,18 @@ public class ArticleService { public long count() { return articleMapper.count(); } + + public long countPages() { + return articleMapper.countArticleByType(Article.TYPE_PAGE); + } + /** * 获取该分类下的文章数 * @param id 分类id * @return 文章数 */ public long countByCategoryId(Integer id){ - return articleMapper.countByCategory(categoryMapper.getOne(id)); + return articleMapper.countByCategoryAndType(categoryMapper.getOne(id),1); } /** diff --git a/src/main/java/cc/bnblogs/service/CategoryService.java b/src/main/java/cc/bnblogs/service/CategoryService.java index f9ebdfa..3f0c3da 100644 --- a/src/main/java/cc/bnblogs/service/CategoryService.java +++ b/src/main/java/cc/bnblogs/service/CategoryService.java @@ -2,6 +2,7 @@ package cc.bnblogs.service; import cc.bnblogs.mapper.ArticleMapper; import cc.bnblogs.mapper.CategoryMapper; +import cc.bnblogs.pojo.Article; import cc.bnblogs.pojo.Category; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; @@ -79,7 +80,7 @@ public class CategoryService { public List show() { return categoryMapper.findAll().stream().peek(category -> { // 返回该分类下的文章总数 - category.setArticleCount(articleMapper.countByCategory(category)); + category.setArticleCount(articleMapper.countByCategoryAndType(category, Article.TYPE_ARTICLE)); category.setLastUpdated(articleMapper.lastUpdated(category.getId())); }).filter(category -> category.getArticleCount() > 0) .collect(Collectors.toList()); diff --git a/src/main/java/cc/bnblogs/service/CommentService.java b/src/main/java/cc/bnblogs/service/CommentService.java index 80ec148..033c82d 100644 --- a/src/main/java/cc/bnblogs/service/CommentService.java +++ b/src/main/java/cc/bnblogs/service/CommentService.java @@ -77,11 +77,23 @@ public class CommentService { // 如果是新评论 if (Objects.isNull(comment.getId())) { // 有人在你的网站评论了 - sendMailToWebsite(comment.getArticle().getId()); comment.setCreated(new Date()); comment.setView(false); + // 站长评论则不发送邮件 + if (comment.getEmail().equals(webSite.getMail())) { + // 设置该评论为已读 + comment.setView(true); + }else { + sendMailToWebsite(comment.getArticle().getId()); + } if (comment.getPid() != 0) { // 有人回复了你的评论 + // 如果是站长回复的,则把父评论设置为已读 + if (comment.getEmail().equals(webSite.getMail())) { + // 获取父评论 + Comment commentParent = detail(comment.getPid()); + commentParent.setView(true); + } sendMailToComment(comment.getArticle().getId(), comment.getPid(), comment.getContent()); // 展示它的父评论 Comment parent = detail(comment.getPid()); diff --git a/src/main/java/cc/bnblogs/service/TagService.java b/src/main/java/cc/bnblogs/service/TagService.java index 1fa3a93..a523fd2 100644 --- a/src/main/java/cc/bnblogs/service/TagService.java +++ b/src/main/java/cc/bnblogs/service/TagService.java @@ -77,7 +77,6 @@ public class TagService { * @param limit 标签数量 * @return 标签云 */ - @Cacheable public List list(int limit) { return tagMapper.findRandom(limit); } diff --git a/src/main/java/cc/bnblogs/utils/UpdateUtil.java b/src/main/java/cc/bnblogs/utils/UpdateUtil.java index 68cfd77..cfbbf49 100644 --- a/src/main/java/cc/bnblogs/utils/UpdateUtil.java +++ b/src/main/java/cc/bnblogs/utils/UpdateUtil.java @@ -11,6 +11,8 @@ import java.util.Set; /** * 更新工具类(忽略为null的字段) + * @author zfp@bnblogs.cc + * @createTime: 2022/10/21 */ public class UpdateUtil { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 016b5fd..31a0f4a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,3 @@ - spring: jackson: date-format: yyyy-MM-dd HH:mm:ss @@ -49,8 +48,7 @@ spring: # 其它属性,这里只开启debug输出错误信息 properties: debug: true - - +# 日志输出 logging: file: path: ./logs @@ -70,36 +68,46 @@ website: - hugo - SpringBoot - 学习 + # 网站描述 description: All the truth is simple! - domain: http://localhost:8081 #域名 + # 域名 + domain: http://localhost:8080 + # 头像 + # 和评论邮箱绑定,作为评论头像 avatar: https://hugo.bnblogs.cc/images/img/20220215001349.png + # 昵称 nickname: barney username: admin + # 管理员加密后的密码 password: 0192023a7bbd73250516f069df18b500 address: 广东 广州 - # 作者头像 + # 标签 tags: - java - springboot - web - 自律 - 学习 - navdesc: 取乎其上,得乎其中;取乎其中,得乎其下;取乎其下,则无所得矣 + # 社交链接 qq: 1337425156 github: https://git.bnblogs.cc/zfp sina: https://weibo.com/6289381214 mail: 1337425156@qq.com logo: https://cravatar.cn/avatar/a2bc729e1ee6040fff197c705e19d449?s=400&r=G&d=mp&ver=1664632345 + # 页尾信息(作者、备案信息) footer: '© 2020-2022 barney
赣ICP备2022002184号-1
赣公网安备 36092202000146号
' +# 默认图片 default-images: + # 默认文章图片 images: - /static/image/1.jpg - /static/image/2.jpg - /static/image/3.jpg - /static/image/4.jpg - /static/image/5.jpg + # 默认评论头像 avatars: - /static/image/avatar/1.jpg - /static/image/avatar/2.jpg @@ -115,5 +123,6 @@ default-images: - /static/image/avatar/12.jpg - /static/image/avatar/13.jpg - /static/image/avatar/14.jpg +# 程序启动端口 server: - port: 8081 # 程序启动端口 + port: 8080 diff --git a/src/main/resources/templates/admin/index.html b/src/main/resources/templates/admin/index.html index fd74db5..b9471a2 100644 --- a/src/main/resources/templates/admin/index.html +++ b/src/main/resources/templates/admin/index.html @@ -10,7 +10,7 @@

网站概要

-

目前有 篇文章, 并有 条关于你的评论在 个分类中.

+

目前有 篇文章, 个独立页面, 并有 条关于你的评论在 个分类中.

其中有 条 评论未查看:

点此查看

diff --git a/src/main/resources/templates/detail.html b/src/main/resources/templates/detail.html index dede6ec..fafa663 100644 --- a/src/main/resources/templates/detail.html +++ b/src/main/resources/templates/detail.html @@ -110,7 +110,7 @@ - 版权所属: 版权所属:
  • @@ -187,6 +187,7 @@
  • + 回复 @@ -201,6 +202,7 @@

    +