mirror of https://github.com/halo-dev/halo
👽 代码优化
parent
77eae8bddf
commit
2f3d64f8b6
|
@ -0,0 +1,39 @@
|
|||
package cc.ryanc.halo.model.enums;
|
||||
|
||||
/**
|
||||
* @author : RYAN0UP
|
||||
* @date : 2018/7/1
|
||||
*/
|
||||
public enum CommentStatus {
|
||||
|
||||
/**
|
||||
* 已发布
|
||||
*/
|
||||
PUBLISHED(0,"已发布"),
|
||||
|
||||
/**
|
||||
* 待审核
|
||||
*/
|
||||
CHECKING(1,"待审核"),
|
||||
|
||||
/**
|
||||
* 回收站
|
||||
*/
|
||||
RECYCLE(2,"回收站");
|
||||
|
||||
private Integer code;
|
||||
private String desc;
|
||||
|
||||
CommentStatus(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
}
|
|
@ -74,7 +74,7 @@ public class CategoryController {
|
|||
Category category = categoryService.removeByCateId(cateId);
|
||||
log.info("删除的分类目录:" + category);
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:{}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/category";
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
|
|||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.domain.User;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
|
@ -74,9 +75,9 @@ public class CommentController extends BaseController {
|
|||
Pageable pageable = PageRequest.of(page, size, sort);
|
||||
Page<Comment> comments = commentService.findAllComments(status, pageable);
|
||||
model.addAttribute("comments", comments);
|
||||
model.addAttribute("publicCount", commentService.findAllComments(0, pageable).getTotalElements());
|
||||
model.addAttribute("checkCount", commentService.findAllComments(1, pageable).getTotalElements());
|
||||
model.addAttribute("trashCount", commentService.findAllComments(2, pageable).getTotalElements());
|
||||
model.addAttribute("publicCount", commentService.findAllComments(CommentStatus.PUBLISHED.getCode(), pageable).getTotalElements());
|
||||
model.addAttribute("checkCount", commentService.findAllComments(CommentStatus.CHECKING.getCode(), pageable).getTotalElements());
|
||||
model.addAttribute("trashCount", commentService.findAllComments(CommentStatus.RECYCLE.getCode(), pageable).getTotalElements());
|
||||
model.addAttribute("status", status);
|
||||
return "admin/admin_comment";
|
||||
}
|
||||
|
@ -92,9 +93,9 @@ public class CommentController extends BaseController {
|
|||
public String moveToTrash(@PathParam("commentId") Long commentId,
|
||||
@PathParam("status") String status) {
|
||||
try {
|
||||
commentService.updateCommentStatus(commentId, 2);
|
||||
commentService.updateCommentStatus(commentId, CommentStatus.RECYCLE.getCode());
|
||||
} catch (Exception e) {
|
||||
log.error("未知错误:{0}", e.getMessage());
|
||||
log.error("未知错误:{}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status=" + status;
|
||||
}
|
||||
|
@ -111,7 +112,7 @@ public class CommentController extends BaseController {
|
|||
public String moveToPublish(@PathParam("commentId") Long commentId,
|
||||
@PathParam("status") Integer status,
|
||||
HttpSession session) {
|
||||
Comment comment = commentService.updateCommentStatus(commentId, 0);
|
||||
Comment comment = commentService.updateCommentStatus(commentId, CommentStatus.PUBLISHED.getCode());
|
||||
Post post = comment.getPost();
|
||||
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
|
||||
|
||||
|
@ -155,7 +156,7 @@ public class CommentController extends BaseController {
|
|||
try {
|
||||
commentService.removeByCommentId(commentId);
|
||||
} catch (Exception e) {
|
||||
log.error("删除评论失败:", e.getMessage());
|
||||
log.error("删除评论失败:{}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments?status=" + status;
|
||||
}
|
||||
|
@ -185,7 +186,7 @@ public class CommentController extends BaseController {
|
|||
Comment lastComment = commentService.findCommentById(commentId).get();
|
||||
|
||||
//修改被回复的评论的状态
|
||||
lastComment.setCommentStatus(0);
|
||||
lastComment.setCommentStatus(CommentStatus.PUBLISHED.getCode());
|
||||
commentService.saveByComment(lastComment);
|
||||
|
||||
//保存评论
|
||||
|
@ -201,7 +202,7 @@ public class CommentController extends BaseController {
|
|||
comment.setCommentContent(lastContent + OwoUtil.markToImg(commentContent));
|
||||
comment.setCommentAgent(userAgent);
|
||||
comment.setCommentParent(commentId);
|
||||
comment.setCommentStatus(0);
|
||||
comment.setCommentStatus(CommentStatus.PUBLISHED.getCode());
|
||||
comment.setIsAdmin(1);
|
||||
commentService.saveByComment(comment);
|
||||
|
||||
|
@ -226,7 +227,7 @@ public class CommentController extends BaseController {
|
|||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("回复评论失败!{0}", e.getMessage());
|
||||
log.error("回复评论失败!{}", e.getMessage());
|
||||
}
|
||||
return "redirect:/admin/comments";
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package cc.ryanc.halo.web.controller.front;
|
|||
|
||||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
|
@ -62,7 +64,7 @@ public class FrontArchiveController extends BaseController {
|
|||
//所有文章数据,分页,material主题适用
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
Pageable pageable = PageRequest.of(page - 1, 5, sort);
|
||||
Page<Post> posts = postService.findPostByStatus(0, PostType.POST_TYPE_POST.getDesc(), pageable);
|
||||
Page<Post> posts = postService.findPostByStatus(PostStatus.PUBLISHED.getCode(), PostType.POST_TYPE_POST.getDesc(), pageable);
|
||||
if (null == posts) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
@ -100,7 +102,7 @@ public class FrontArchiveController extends BaseController {
|
|||
@GetMapping(value = "{postUrl}")
|
||||
public String getPost(@PathVariable String postUrl, Model model) {
|
||||
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc());
|
||||
if (null == post || post.getPostStatus() != 0) {
|
||||
if (null == post || !post.getPostStatus().equals(PostStatus.PUBLISHED.getCode())) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
//获得当前文章的发布日期
|
||||
|
@ -118,7 +120,7 @@ public class FrontArchiveController extends BaseController {
|
|||
}
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
Pageable pageable = PageRequest.of(0, 999, sort);
|
||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, 0);
|
||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, CommentStatus.PUBLISHED.getCode());
|
||||
model.addAttribute("post", post);
|
||||
model.addAttribute("comments", CommentUtil.getComments(comments.getContent()));
|
||||
model.addAttribute("commentsCount", comments.getTotalElements());
|
||||
|
|
|
@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
|
|||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.dto.JsonResult;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.MailService;
|
||||
|
@ -64,7 +65,7 @@ public class FrontCommentController {
|
|||
Optional<Post> post = postService.findByPostId(postId);
|
||||
Sort sort = new Sort(Sort.Direction.DESC, "commentDate");
|
||||
Pageable pageable = PageRequest.of(0, 999, sort);
|
||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, 0).getContent();
|
||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, CommentStatus.PUBLISHED.getCode()).getContent();
|
||||
if (null == comments) {
|
||||
return null;
|
||||
}
|
||||
|
@ -84,7 +85,7 @@ public class FrontCommentController {
|
|||
@RequestParam(value = "post") Post post){
|
||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||
Pageable pageable = PageRequest.of(page-1,10,sort);
|
||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,2).getContent();
|
||||
List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,CommentStatus.PUBLISHED.getCode()).getContent();
|
||||
return comments;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.front;
|
|||
import cc.ryanc.halo.model.domain.Comment;
|
||||
import cc.ryanc.halo.model.domain.Gallery;
|
||||
import cc.ryanc.halo.model.domain.Post;
|
||||
import cc.ryanc.halo.model.enums.CommentStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.service.CommentService;
|
||||
import cc.ryanc.halo.service.GalleryService;
|
||||
|
@ -72,7 +73,7 @@ public class FrontPageController extends BaseController {
|
|||
|
||||
Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
|
||||
Pageable pageable = PageRequest.of(0,999,sort);
|
||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0);
|
||||
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,CommentStatus.PUBLISHED.getCode());
|
||||
if(null==post){
|
||||
return this.renderNotFound();
|
||||
}
|
||||
|
|
|
@ -250,13 +250,13 @@
|
|||
<td>
|
||||
<#switch comment.commentStatus>
|
||||
<#case 0>
|
||||
<a href="/admin/comments">${comment.commentContent}</a>
|
||||
${comment.commentContent}
|
||||
<#break>
|
||||
<#case 1>
|
||||
<a href="/admin/comments?status=1">${comment.commentContent}</a>
|
||||
${comment.commentContent}
|
||||
<#break>
|
||||
<#case 2>
|
||||
<a href="/admin/comments?status=2">${comment.commentContent}</a>
|
||||
${comment.commentContent}
|
||||
<#break>
|
||||
</#switch>
|
||||
</td>
|
||||
|
|
|
@ -313,11 +313,10 @@
|
|||
</#list>
|
||||
</#if>
|
||||
</ul>
|
||||
<#--<div class="native-nav">-->
|
||||
<#--<div class="native-nav" id="comment-nav">-->
|
||||
<#--<ol class="page-nav">-->
|
||||
<#--<li>←</li>-->
|
||||
<#--<li>1</li>-->
|
||||
<#--<li>→</li>-->
|
||||
<#--<li><</li>-->
|
||||
<#--<li>></li>-->
|
||||
<#--</ol>-->
|
||||
<#--</div>-->
|
||||
</div>
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 59 KiB |
Binary file not shown.
Before Width: | Height: | Size: 152 KiB After Width: | Height: | Size: 129 KiB |
Loading…
Reference in New Issue