👽 代码优化

pull/21/head
ruibaby 2018-07-14 11:52:00 +08:00
parent 77eae8bddf
commit 2f3d64f8b6
10 changed files with 67 additions and 24 deletions

View File

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

View File

@ -74,7 +74,7 @@ public class CategoryController {
Category category = categoryService.removeByCateId(cateId); Category category = categoryService.removeByCateId(cateId);
log.info("删除的分类目录:" + category); log.info("删除的分类目录:" + category);
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:{}", e.getMessage());
} }
return "redirect:/admin/category"; return "redirect:/admin/category";
} }

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.User; import cc.ryanc.halo.model.domain.User;
import cc.ryanc.halo.model.dto.HaloConst; 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.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.MailService; import cc.ryanc.halo.service.MailService;
@ -74,9 +75,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(0, pageable).getTotalElements()); model.addAttribute("publicCount", commentService.findAllComments(CommentStatus.PUBLISHED.getCode(), pageable).getTotalElements());
model.addAttribute("checkCount", commentService.findAllComments(1, pageable).getTotalElements()); model.addAttribute("checkCount", commentService.findAllComments(CommentStatus.CHECKING.getCode(), pageable).getTotalElements());
model.addAttribute("trashCount", commentService.findAllComments(2, pageable).getTotalElements()); model.addAttribute("trashCount", commentService.findAllComments(CommentStatus.RECYCLE.getCode(), pageable).getTotalElements());
model.addAttribute("status", status); model.addAttribute("status", status);
return "admin/admin_comment"; return "admin/admin_comment";
} }
@ -92,9 +93,9 @@ public class CommentController extends BaseController {
public String moveToTrash(@PathParam("commentId") Long commentId, public String moveToTrash(@PathParam("commentId") Long commentId,
@PathParam("status") String status) { @PathParam("status") String status) {
try { try {
commentService.updateCommentStatus(commentId, 2); commentService.updateCommentStatus(commentId, CommentStatus.RECYCLE.getCode());
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:{0}", e.getMessage()); log.error("未知错误:{}", e.getMessage());
} }
return "redirect:/admin/comments?status=" + status; return "redirect:/admin/comments?status=" + status;
} }
@ -111,7 +112,7 @@ public class CommentController extends BaseController {
public String moveToPublish(@PathParam("commentId") Long commentId, public String moveToPublish(@PathParam("commentId") Long commentId,
@PathParam("status") Integer status, @PathParam("status") Integer status,
HttpSession session) { HttpSession session) {
Comment comment = commentService.updateCommentStatus(commentId, 0); Comment comment = commentService.updateCommentStatus(commentId, CommentStatus.PUBLISHED.getCode());
Post post = comment.getPost(); Post post = comment.getPost();
User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY); User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY);
@ -155,7 +156,7 @@ public class CommentController extends BaseController {
try { try {
commentService.removeByCommentId(commentId); commentService.removeByCommentId(commentId);
} catch (Exception e) { } catch (Exception e) {
log.error("删除评论失败:", e.getMessage()); log.error("删除评论失败:{}", e.getMessage());
} }
return "redirect:/admin/comments?status=" + status; return "redirect:/admin/comments?status=" + status;
} }
@ -185,7 +186,7 @@ public class CommentController extends BaseController {
Comment lastComment = commentService.findCommentById(commentId).get(); Comment lastComment = commentService.findCommentById(commentId).get();
//修改被回复的评论的状态 //修改被回复的评论的状态
lastComment.setCommentStatus(0); lastComment.setCommentStatus(CommentStatus.PUBLISHED.getCode());
commentService.saveByComment(lastComment); commentService.saveByComment(lastComment);
//保存评论 //保存评论
@ -201,7 +202,7 @@ public class CommentController extends BaseController {
comment.setCommentContent(lastContent + OwoUtil.markToImg(commentContent)); comment.setCommentContent(lastContent + OwoUtil.markToImg(commentContent));
comment.setCommentAgent(userAgent); comment.setCommentAgent(userAgent);
comment.setCommentParent(commentId); comment.setCommentParent(commentId);
comment.setCommentStatus(0); comment.setCommentStatus(CommentStatus.PUBLISHED.getCode());
comment.setIsAdmin(1); comment.setIsAdmin(1);
commentService.saveByComment(comment); commentService.saveByComment(comment);
@ -226,7 +227,7 @@ public class CommentController extends BaseController {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("回复评论失败!{0}", e.getMessage()); log.error("回复评论失败!{}", e.getMessage());
} }
return "redirect:/admin/comments"; return "redirect:/admin/comments";
} }

View File

@ -2,6 +2,8 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; 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.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.PostService;
@ -62,7 +64,7 @@ public class FrontArchiveController extends BaseController {
//所有文章数据分页material主题适用 //所有文章数据分页material主题适用
Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Sort sort = new Sort(Sort.Direction.DESC, "postDate");
Pageable pageable = PageRequest.of(page - 1, 5, sort); 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) { if (null == posts) {
return this.renderNotFound(); return this.renderNotFound();
} }
@ -100,7 +102,7 @@ public class FrontArchiveController extends BaseController {
@GetMapping(value = "{postUrl}") @GetMapping(value = "{postUrl}")
public String getPost(@PathVariable String postUrl, Model model) { public String getPost(@PathVariable String postUrl, Model model) {
Post post = postService.findByPostUrl(postUrl, PostType.POST_TYPE_POST.getDesc()); 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(); return this.renderNotFound();
} }
//获得当前文章的发布日期 //获得当前文章的发布日期
@ -118,7 +120,7 @@ public class FrontArchiveController extends BaseController {
} }
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);
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, 0); Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post, pageable, CommentStatus.PUBLISHED.getCode());
model.addAttribute("post", post); model.addAttribute("post", post);
model.addAttribute("comments", CommentUtil.getComments(comments.getContent())); model.addAttribute("comments", CommentUtil.getComments(comments.getContent()));
model.addAttribute("commentsCount", comments.getTotalElements()); model.addAttribute("commentsCount", comments.getTotalElements());

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult; 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.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.MailService; import cc.ryanc.halo.service.MailService;
@ -64,7 +65,7 @@ public class FrontCommentController {
Optional<Post> post = postService.findByPostId(postId); Optional<Post> post = postService.findByPostId(postId);
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, 0).getContent(); List<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post.get(), pageable, CommentStatus.PUBLISHED.getCode()).getContent();
if (null == comments) { if (null == comments) {
return null; return null;
} }
@ -84,7 +85,7 @@ public class FrontCommentController {
@RequestParam(value = "post") Post post){ @RequestParam(value = "post") Post post){
Sort sort = new Sort(Sort.Direction.DESC,"commentDate"); Sort sort = new Sort(Sort.Direction.DESC,"commentDate");
Pageable pageable = PageRequest.of(page-1,10,sort); 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; return comments;
} }

View File

@ -3,6 +3,7 @@ package cc.ryanc.halo.web.controller.front;
import cc.ryanc.halo.model.domain.Comment; import cc.ryanc.halo.model.domain.Comment;
import cc.ryanc.halo.model.domain.Gallery; import cc.ryanc.halo.model.domain.Gallery;
import cc.ryanc.halo.model.domain.Post; 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.model.enums.PostType;
import cc.ryanc.halo.service.CommentService; import cc.ryanc.halo.service.CommentService;
import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.GalleryService;
@ -72,7 +73,7 @@ public class FrontPageController extends BaseController {
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);
Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,0); Page<Comment> comments = commentService.findCommentsByPostAndCommentStatus(post,pageable,CommentStatus.PUBLISHED.getCode());
if(null==post){ if(null==post){
return this.renderNotFound(); return this.renderNotFound();
} }

View File

@ -250,13 +250,13 @@
<td> <td>
<#switch comment.commentStatus> <#switch comment.commentStatus>
<#case 0> <#case 0>
<a href="/admin/comments">${comment.commentContent}</a> ${comment.commentContent}
<#break> <#break>
<#case 1> <#case 1>
<a href="/admin/comments?status=1">${comment.commentContent}</a> ${comment.commentContent}
<#break> <#break>
<#case 2> <#case 2>
<a href="/admin/comments?status=2">${comment.commentContent}</a> ${comment.commentContent}
<#break> <#break>
</#switch> </#switch>
</td> </td>

View File

@ -313,11 +313,10 @@
</#list> </#list>
</#if> </#if>
</ul> </ul>
<#--<div class="native-nav">--> <#--<div class="native-nav" id="comment-nav">-->
<#--<ol class="page-nav">--> <#--<ol class="page-nav">-->
<#--<li>←</li>--> <#--<li><</li>-->
<#--<li>1</li>--> <#--<li>></li>-->
<#--<li>→</li>-->
<#--</ol>--> <#--</ol>-->
<#--</div>--> <#--</div>-->
</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