评论系统优化、显示博主标签、优化多个页面

master
barney 2 years ago
parent 2146682e53
commit 185d1e382d
  1. 6
      src/main/java/cc/bnblogs/common/DefaultImages.java
  2. 1
      src/main/java/cc/bnblogs/config/WebConfig.java
  3. 6
      src/main/java/cc/bnblogs/controller/AdminController.java
  4. 1
      src/main/java/cc/bnblogs/enums/ResultEnum.java
  5. 12
      src/main/java/cc/bnblogs/mapper/ArticleMapper.java
  6. 2
      src/main/java/cc/bnblogs/mapper/CategoryMapper.java
  7. 2
      src/main/java/cc/bnblogs/mapper/TagMapper.java
  8. 7
      src/main/java/cc/bnblogs/service/ArticleService.java
  9. 3
      src/main/java/cc/bnblogs/service/CategoryService.java
  10. 14
      src/main/java/cc/bnblogs/service/CommentService.java
  11. 1
      src/main/java/cc/bnblogs/service/TagService.java
  12. 2
      src/main/java/cc/bnblogs/utils/UpdateUtil.java
  13. 23
      src/main/resources/application.yml
  14. 2
      src/main/resources/templates/admin/index.html
  15. 4
      src/main/resources/templates/detail.html

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

@ -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;

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

@ -1,6 +1,5 @@
package cc.bnblogs.enums;
import ch.qos.logback.classic.spi.ILoggingEvent;
import lombok.AllArgsConstructor;
import lombok.Getter;

@ -25,12 +25,11 @@ public interface ArticleMapper extends JpaRepository<Article,Integer>, JpaSpecif
List<Article> 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<Article,Integer>, JpaSpecif
"where bc.name='默认分类' and ba.category_id=?1", nativeQuery = true)
void updateToDefaultCategory(Integer articleCategoryId);
/**
* 根据页面类型返回博客数量
* @param type 页面类型(文章/页面)
* @return 博客数量
*/
Long countArticleByType(Integer type);
}

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

@ -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;
/**

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

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

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

@ -77,7 +77,6 @@ public class TagService {
* @param limit 标签数量
* @return 标签云
*/
@Cacheable
public List<Tag> list(int limit) {
return tagMapper.findRandom(limit);
}

@ -11,6 +11,8 @@ import java.util.Set;
/**
* 更新工具类(忽略为null的字段)
* @author zfp@bnblogs.cc
* @createTime: 2022/10/21
*/
public class UpdateUtil {

@ -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 <a href="https://hugo.bnblogs.cc">barney</a><br /><a target="_blank" href="https://beian.miit.gov.cn">赣ICP备2022002184号-1</a>
<a style="margin-left: 10px" target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11011402012109"><br /><img style="vertical-align: top;" src="https://imagebed-1252410096.cos.ap-nanjing.myqcloud.com/2046/d4ab98835b8842c88eededac6e7c9e35.png">
赣公网安备 36092202000146号</a>'
# 默认图片
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

@ -10,7 +10,7 @@
<div class="container lw-main">
<div class="jumbotron">
<h3>网站概要</h3>
<p>目前有 <i th:text="${ArticleCount}"></i> 篇文章, 并有 <i th:text="${CommentAll}"></i> 条关于你的评论在 <i th:text="${CategoryCount}"></i> 个分类中.</p>
<p>目前有 <i th:text="${ArticleCount}"></i> 篇文章, <i th:text="${PagesCount}"></i> 个独立页面, 并有 <i th:text="${CommentAll}"></i> 条关于你的评论在 <i th:text="${CategoryCount}"></i> 个分类中.</p>
<p>其中有 <i th:text="${CommentNotReadCount}"></i>条 评论未查看:</p>
<p><a class="btn btn-primary btn-lg" th:href="@{/admin/comment.html(view=false)}" role="button">点此查看</a></p>
</div>

@ -110,7 +110,7 @@
<path d="M676.5 701c-9 0-16.6-6.3-18.1-15-1.1-6-2.5-11.6-4.2-16.7l-0.1-0.2-0.1-0.2c-9.1-31.5-29.1-59-56.6-78-26.2 13.2-55.6 20.1-85.3 20.1-29.8 0-59.2-7-85.5-20.2-27.6 19-47.7 46.5-56.8 78.1-0.2 0.7-2.1 7.9-4.8 18.5-2 8.1-9.3 13.7-17.8 13.7h-10.7c-4.8 0-9.4-2-12.5-5.6-3.1-3.5-4.6-8.2-4-12.8 8.1-60.2 46.2-113.1 101.7-141.5l5.4-2.8 5.1 3.4c23.5 15.9 51.1 24.3 79.8 24.3 28.7 0 56.2-8.4 79.7-24.2l5.1-3.4 5.4 2.8c55.4 28.4 93.4 81.3 101.5 141.4 0.6 4.6-0.8 9.3-4 12.8s-7.7 5.6-12.5 5.6h-10.7zM512.2 526.3c-74.5 0-135-60-135-133.6S437.7 259 512.2 259s135 60 135 133.6c0 73.7-60.5 133.7-135 133.7z m0-222.4c-49.6 0-89.9 39.8-89.9 88.8s40.3 88.8 89.9 88.8c49.6 0 89.9-39.8 89.9-88.8s-40.3-88.8-89.9-88.8z"
fill="#FFFFFF" p-id="921"></path>
</svg>
<span>版权所属: <a href="https://hugo.bnblos.cc/"><th:block
<span>版权所属: <a th:href="@{/}"><th:block
th:text="${@webSite.getNickname()}"></th:block></a></span>
</li>
<li>
@ -187,6 +187,7 @@
</div>
<div class="lw-comment-content">
<p>
<button th:if="${comment.email eq @webSite.getMail() and comment.nickname eq @webSite.nickname}" style="border: none; border-radius: 4px; background-color: #dddddd">博主</button>
<b th:text="${comment.nickname}"></b> <span
th:text="${#dates.format(comment.created,'yyyy-MM-dd HH:mm')}"></span>
<a th:data-id="${comment.id}" href="javascript:void(0);" class="comment-reply">回复</a>
@ -201,6 +202,7 @@
</div>
<div class="lw-comment-content">
<p>
<button th:if="${child.email eq @webSite.getMail() and child.nickname eq @webSite.nickname}" style="border: none; border-radius: 4px; background-color: #dddddd">博主</button>
<b th:text="${child.nickname}"></b>
<span th:text="${#dates.format(child.created,'yyyy-MM-dd HH:mm')}"></span>
<a th:data-id="${child.id}" href="javascript:void(0)"

Loading…
Cancel
Save