mirror of https://github.com/halo-dev/halo
👽 代码优化
parent
67418fd0cf
commit
8e9c4b14c3
|
@ -72,4 +72,11 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
|
||||||
@Query(value = "SELECT * FROM halo_comment ORDER BY comment_date DESC LIMIT 5", nativeQuery = true)
|
@Query(value = "SELECT * FROM halo_comment ORDER BY comment_date DESC LIMIT 5", nativeQuery = true)
|
||||||
List<Comment> findTopFive();
|
List<Comment> findTopFive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论状态查询数量
|
||||||
|
*
|
||||||
|
* @param status 评论状态
|
||||||
|
* @return 评论数量
|
||||||
|
*/
|
||||||
|
Integer countAllByCommentStatus(Integer status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,4 +204,13 @@ public interface PostRepository extends JpaRepository<Post, Long> {
|
||||||
*/
|
*/
|
||||||
@Query(value = "select sum(post_views) from halo_post", nativeQuery = true)
|
@Query(value = "select sum(post_views) from halo_post", nativeQuery = true)
|
||||||
Long getPostViewsSum();
|
Long getPostViewsSum();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章状态查询数量
|
||||||
|
*
|
||||||
|
* @param status 文章状态
|
||||||
|
* @param postType 文章类型
|
||||||
|
* @return 文章数量
|
||||||
|
*/
|
||||||
|
Integer countAllByPostStatusAndPostType(Integer status, String postType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,4 +104,12 @@ public interface CommentService {
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
List<Comment> findCommentsLatest();
|
List<Comment> findCommentsLatest();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论状态查询数量
|
||||||
|
*
|
||||||
|
* @param status 评论状态
|
||||||
|
* @return 评论数量
|
||||||
|
*/
|
||||||
|
Integer getCountByStatus(Integer status);
|
||||||
}
|
}
|
||||||
|
|
|
@ -239,6 +239,14 @@ public interface PostService {
|
||||||
*/
|
*/
|
||||||
Long getPostViews();
|
Long getPostViews();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章状态查询数量
|
||||||
|
*
|
||||||
|
* @param status 文章状态
|
||||||
|
* @return 文章数量
|
||||||
|
*/
|
||||||
|
Integer getCountByStatus(Integer status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成rss
|
* 生成rss
|
||||||
*
|
*
|
||||||
|
|
|
@ -159,4 +159,15 @@ public class CommentServiceImpl implements CommentService {
|
||||||
public List<Comment> findCommentsLatest() {
|
public List<Comment> findCommentsLatest() {
|
||||||
return commentRepository.findTopFive();
|
return commentRepository.findTopFive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据评论状态查询数量
|
||||||
|
*
|
||||||
|
* @param status 评论状态
|
||||||
|
* @return 评论数量
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Integer getCountByStatus(Integer status) {
|
||||||
|
return commentRepository.countAllByCommentStatus(status);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -408,6 +408,17 @@ public class PostServiceImpl implements PostService {
|
||||||
return postRepository.getPostViewsSum();
|
return postRepository.getPostViewsSum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据文章状态查询数量
|
||||||
|
*
|
||||||
|
* @param status 文章状态
|
||||||
|
* @return 文章数量
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Integer getCountByStatus(Integer status) {
|
||||||
|
return postRepository.countAllByPostStatusAndPostType(status, PostType.POST_TYPE_POST.getDesc());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成rss
|
* 生成rss
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,9 +20,9 @@ public class CommentUtil {
|
||||||
public static List<Comment> getComments(List<Comment> commentsRoot) {
|
public static List<Comment> getComments(List<Comment> commentsRoot) {
|
||||||
List<Comment> commentsResult = new ArrayList<>();
|
List<Comment> commentsResult = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < commentsRoot.size(); i++) {
|
for (Comment comment : commentsRoot) {
|
||||||
if (commentsRoot.get(i).getCommentParent() == 0) {
|
if (comment.getCommentParent() == 0) {
|
||||||
commentsResult.add(commentsRoot.get(i));
|
commentsResult.add(comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,9 +77,9 @@ public class CommentController extends BaseController {
|
||||||
Pageable pageable = PageRequest.of(page, size, sort);
|
Pageable pageable = PageRequest.of(page, size, sort);
|
||||||
Page<Comment> comments = commentService.findAllComments(status, pageable);
|
Page<Comment> comments = commentService.findAllComments(status, pageable);
|
||||||
model.addAttribute("comments", comments);
|
model.addAttribute("comments", comments);
|
||||||
model.addAttribute("publicCount", commentService.findAllComments(CommentStatus.PUBLISHED.getCode(), pageable).getTotalElements());
|
model.addAttribute("publicCount", commentService.getCountByStatus(CommentStatus.PUBLISHED.getCode()));
|
||||||
model.addAttribute("checkCount", commentService.findAllComments(CommentStatus.CHECKING.getCode(), pageable).getTotalElements());
|
model.addAttribute("checkCount", commentService.getCountByStatus(CommentStatus.CHECKING.getCode()));
|
||||||
model.addAttribute("trashCount", commentService.findAllComments(CommentStatus.RECYCLE.getCode(), pageable).getTotalElements());
|
model.addAttribute("trashCount", commentService.getCountByStatus(CommentStatus.RECYCLE.getCode()));
|
||||||
model.addAttribute("status", status);
|
model.addAttribute("status", status);
|
||||||
return "admin/admin_comment";
|
return "admin/admin_comment";
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,9 +92,9 @@ public class PostController extends BaseController {
|
||||||
Pageable pageable = PageRequest.of(page, size, sort);
|
Pageable pageable = PageRequest.of(page, size, sort);
|
||||||
Page<Post> posts = postService.findPostByStatus(status, PostType.POST_TYPE_POST.getDesc(), pageable);
|
Page<Post> posts = postService.findPostByStatus(status, PostType.POST_TYPE_POST.getDesc(), pageable);
|
||||||
model.addAttribute("posts", posts);
|
model.addAttribute("posts", posts);
|
||||||
model.addAttribute("publishCount", postService.findPostByStatus(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
|
model.addAttribute("publishCount", postService.getCountByStatus(PostStatus.PUBLISHED.getCode()));
|
||||||
model.addAttribute("draftCount", postService.findPostByStatus(PostStatus.DRAFT.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
|
model.addAttribute("draftCount", postService.getCountByStatus(PostStatus.DRAFT.getCode()));
|
||||||
model.addAttribute("trashCount", postService.findPostByStatus(PostStatus.RECYCLE.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable).getTotalElements());
|
model.addAttribute("trashCount", postService.getCountByStatus(PostStatus.RECYCLE.getCode()));
|
||||||
model.addAttribute("status", status);
|
model.addAttribute("status", status);
|
||||||
return "admin/admin_post";
|
return "admin/admin_post";
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,9 +68,6 @@ public class FrontCommentController {
|
||||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||||
Pageable pageable = PageRequest.of(0, 999, sort);
|
Pageable pageable = PageRequest.of(0, 999, sort);
|
||||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, CommentStatus.PUBLISHED.getCode()).getContent();
|
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, CommentStatus.PUBLISHED.getCode()).getContent();
|
||||||
if (null == comments) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return CommentUtil.getComments(comments);
|
return CommentUtil.getComments(comments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +130,7 @@ public class FrontCommentController {
|
||||||
commentService.saveByComment(comment);
|
commentService.saveByComment(comment);
|
||||||
if(comment.getCommentParent()>0){
|
if(comment.getCommentParent()>0){
|
||||||
new EmailToParent(comment,lastComment,post).start();
|
new EmailToParent(comment,lastComment,post).start();
|
||||||
|
new EmailToAdmin(comment, post).start();
|
||||||
}else{
|
}else{
|
||||||
new EmailToAdmin(comment,post).start();
|
new EmailToAdmin(comment,post).start();
|
||||||
}
|
}
|
||||||
|
@ -148,13 +146,14 @@ public class FrontCommentController {
|
||||||
class EmailToAdmin extends Thread{
|
class EmailToAdmin extends Thread{
|
||||||
private Comment comment;
|
private Comment comment;
|
||||||
private Post post;
|
private Post post;
|
||||||
public EmailToAdmin(Comment comment,Post post){
|
|
||||||
|
private EmailToAdmin(Comment comment, Post post) {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.post = post;
|
this.post = post;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void run(){
|
public void run(){
|
||||||
if (StringUtils.equals(HaloConst.OPTIONS.get("smtp_email_enable"), "true") && StringUtils.equals(HaloConst.OPTIONS.get("new_comment_notice"), "true")) {
|
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), "true") && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), "true")) {
|
||||||
try {
|
try {
|
||||||
//发送邮件到博主
|
//发送邮件到博主
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
@ -182,7 +181,8 @@ public class FrontCommentController {
|
||||||
private Comment comment;
|
private Comment comment;
|
||||||
private Comment lastComment;
|
private Comment lastComment;
|
||||||
private Post post;
|
private Post post;
|
||||||
public EmailToParent(Comment comment,Comment lastComment,Post post){
|
|
||||||
|
private EmailToParent(Comment comment, Comment lastComment, Post post) {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.lastComment = lastComment;
|
this.lastComment = lastComment;
|
||||||
this.post = post;
|
this.post = post;
|
||||||
|
@ -191,7 +191,7 @@ public class FrontCommentController {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//发送通知给对方
|
//发送通知给对方
|
||||||
if(StringUtils.equals(HaloConst.OPTIONS.get("smtp_email_enable"),"true") && StringUtils.equals(HaloConst.OPTIONS.get("comment_reply_notice"),"true")) {
|
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.SMTP_EMAIL_ENABLE.getProp()), "true") && StringUtils.equals(HaloConst.OPTIONS.get(BlogProperties.NEW_COMMENT_NOTICE.getProp()), "true")) {
|
||||||
if(Validator.isEmail(lastComment.getCommentAuthorEmail())){
|
if(Validator.isEmail(lastComment.getCommentAuthorEmail())){
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = new HashMap<>();
|
||||||
map.put("blogTitle",HaloConst.OPTIONS.get(BlogProperties.BLOG_TITLE.getProp()));
|
map.put("blogTitle",HaloConst.OPTIONS.get(BlogProperties.BLOG_TITLE.getProp()));
|
||||||
|
|
Loading…
Reference in New Issue