From a7e0f7feee57200b19ce02a3e5635e0031cc3a82 Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 28 Jun 2021 08:06:37 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E6=96=87=E7=AB=A0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=202.=20=E8=AF=84=E8=AE=BA=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/dto/ArticleDTO.java | 2 ++ .../java/com/rymcu/forest/dto/CommentDTO.java | 2 ++ .../rymcu/forest/mapper/CommentMapper.java | 6 ++++ .../rymcu/forest/service/CommentService.java | 17 ++++++++++ .../service/impl/CommentServiceImpl.java | 10 ++++++ .../forest/web/api/admin/AdminController.java | 33 +++++++++++++++++++ src/main/java/mapper/CommentMapper.xml | 3 ++ 7 files changed, 73 insertions(+) diff --git a/src/main/java/com/rymcu/forest/dto/ArticleDTO.java b/src/main/java/com/rymcu/forest/dto/ArticleDTO.java index 43a84b4..530998c 100644 --- a/src/main/java/com/rymcu/forest/dto/ArticleDTO.java +++ b/src/main/java/com/rymcu/forest/dto/ArticleDTO.java @@ -1,5 +1,6 @@ package com.rymcu.forest.dto; +import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; import java.util.Date; @@ -44,6 +45,7 @@ public class ArticleDTO { /** 文章状态 */ private String articleStatus; /** 更新时间 */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date updatedTime; private Author articleAuthor; diff --git a/src/main/java/com/rymcu/forest/dto/CommentDTO.java b/src/main/java/com/rymcu/forest/dto/CommentDTO.java index 1f93a53..cb5826b 100644 --- a/src/main/java/com/rymcu/forest/dto/CommentDTO.java +++ b/src/main/java/com/rymcu/forest/dto/CommentDTO.java @@ -1,5 +1,6 @@ package com.rymcu.forest.dto; +import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; import java.util.Date; @@ -35,6 +36,7 @@ public class CommentDTO { /** 0:所有人可见,1:仅楼主和自己可见 */ private String commentVisible; /** 创建时间 */ + @JSONField(format = "yyyy-MM-dd HH:mm:ss") private Date createdTime; private Author commenter; diff --git a/src/main/java/com/rymcu/forest/mapper/CommentMapper.java b/src/main/java/com/rymcu/forest/mapper/CommentMapper.java index aa369ac..4969ece 100644 --- a/src/main/java/com/rymcu/forest/mapper/CommentMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/CommentMapper.java @@ -40,4 +40,10 @@ public interface CommentMapper extends Mapper { * @return */ Integer updateCommentSharpUrl(@Param("idComment") Integer idComment, @Param("commentSharpUrl") String commentSharpUrl); + + /** + * 获取评论列表数据 + * @return + */ + List selectComments(); } diff --git a/src/main/java/com/rymcu/forest/service/CommentService.java b/src/main/java/com/rymcu/forest/service/CommentService.java index 9199b90..92b2b9d 100644 --- a/src/main/java/com/rymcu/forest/service/CommentService.java +++ b/src/main/java/com/rymcu/forest/service/CommentService.java @@ -13,7 +13,24 @@ import java.util.Map; */ public interface CommentService extends Service { + /** + * 获取文章评论数据 + * @param idArticle + * @return + */ List getArticleComments(Integer idArticle); + /** + * 评论 + * @param comment + * @param request + * @return + */ Map postComment(Comment comment, HttpServletRequest request); + + /** + * 获取评论列表数据 + * @return + */ + List findComments(); } diff --git a/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java index 174e66e..0602e87 100644 --- a/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/CommentServiceImpl.java @@ -36,6 +36,10 @@ public class CommentServiceImpl extends AbstractService implements Comm @Override public List getArticleComments(Integer idArticle) { List commentDTOList = commentMapper.selectArticleComments(idArticle); + return genComments(commentDTOList); + } + + private List genComments(List commentDTOList) { commentDTOList.forEach(commentDTO -> { commentDTO.setTimeAgo(Utils.getTimeAgo(commentDTO.getCreatedTime())); if (commentDTO.getCommentAuthorId() != null) { @@ -113,4 +117,10 @@ public class CommentServiceImpl extends AbstractService implements Comm return map; } + + @Override + public List findComments() { + List commentDTOList = commentMapper.selectComments(); + return genComments(commentDTOList); + } } diff --git a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java index f39b423..216ea56 100644 --- a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java @@ -4,6 +4,9 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResultGenerator; +import com.rymcu.forest.dto.ArticleDTO; +import com.rymcu.forest.dto.ArticleSearchDTO; +import com.rymcu.forest.dto.CommentDTO; import com.rymcu.forest.dto.UserSearchDTO; import com.rymcu.forest.dto.admin.TopicTagDTO; import com.rymcu.forest.dto.admin.UserRoleDTO; @@ -36,6 +39,10 @@ public class AdminController { private TagService tagService; @Resource private SpecialDayService specialDayService; + @Resource + private ArticleService articleService; + @Resource + private CommentService commentService; @GetMapping("/users") public GlobalResult> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){ @@ -219,4 +226,30 @@ public class AdminController { return GlobalResultGenerator.genSuccessResult(map); } + @GetMapping("/articles") + public GlobalResult articles(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, ArticleSearchDTO articleSearchDTO) { + PageHelper.startPage(page, rows); + List list = articleService.findArticles(articleSearchDTO); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap<>(2); + map.put("articles", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + @GetMapping("/comments") + public GlobalResult comments(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows) { + PageHelper.startPage(page, rows); + List list = commentService.findComments(); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap<>(2); + map.put("comments", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + + + } diff --git a/src/main/java/mapper/CommentMapper.xml b/src/main/java/mapper/CommentMapper.xml index 646abb2..d49ce61 100644 --- a/src/main/java/mapper/CommentMapper.xml +++ b/src/main/java/mapper/CommentMapper.xml @@ -47,4 +47,7 @@ + \ No newline at end of file