From 42fbe19acc5fb28f28448f03c731236eabdd6f47 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Thu, 22 Feb 2024 10:00:22 +0800 Subject: [PATCH] fix: comment reply nolimit --- .../luoo/comment/client/JournalClient.java | 16 ++++++++ .../java/com/luoo/comment/dao/CommentDao.java | 1 + .../java/com/luoo/comment/pojo/Comment.java | 13 ++++++ .../com/luoo/comment/pojo/CommentResp.java | 10 +++++ .../java/com/luoo/comment/pojo/CommentVo.java | 2 +- .../com/luoo/comment/pojo/JournalRespDTO.java | 40 +++++++++++++++++++ .../luoo/comment/service/CommentService.java | 25 ++++++++++-- 7 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 luoo_comment/src/main/java/com/luoo/comment/client/JournalClient.java create mode 100644 luoo_comment/src/main/java/com/luoo/comment/pojo/JournalRespDTO.java diff --git a/luoo_comment/src/main/java/com/luoo/comment/client/JournalClient.java b/luoo_comment/src/main/java/com/luoo/comment/client/JournalClient.java new file mode 100644 index 0000000..2fe855a --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/client/JournalClient.java @@ -0,0 +1,16 @@ +package com.luoo.comment.client; + + +import api.Result; +import com.luoo.comment.pojo.JournalRespDTO; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@FeignClient("luoo-music") +public interface JournalClient { + + @GetMapping("/journal/{id}") + public Result findById(@PathVariable String id); + +} diff --git a/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java b/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java index 874144a..4e82322 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java +++ b/luoo_comment/src/main/java/com/luoo/comment/dao/CommentDao.java @@ -8,6 +8,7 @@ import org.springframework.data.mongodb.repository.MongoRepository; public interface CommentDao extends MongoRepository { public Page findByParentId(String parentId, Pageable pageable); + public Page findByRootIdAndReplyToUserIdNotNull(String rootId, Pageable pageable); public Page findByJournalId(String journalId, Pageable pageable); public Page findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable); public Page findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable); diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java index fc9137e..05a236e 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/Comment.java @@ -49,4 +49,17 @@ public class Comment implements Serializable { private String journalImage; private boolean haveThumbup; + + /** + * + */ + private String rootId; + + private String rootJournalId; + + private String rootJournalName; + + private String replyToUserId; + + private String replyToNickname; } diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java index abc85eb..1a0036a 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentResp.java @@ -45,4 +45,14 @@ public class CommentResp implements Serializable { private String journalId; private boolean haveThumbup; + +// private String rootId; +// +// private String rootJournalId; +// +// private String rootJournalName; + + private String replyToUserId; + + private String replyToNickname; } diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentVo.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentVo.java index 00e8568..ec6d3bf 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentVo.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentVo.java @@ -15,5 +15,5 @@ public class CommentVo { private String journalId; - private String journalImage; +// private String journalImage; } diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/JournalRespDTO.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/JournalRespDTO.java new file mode 100644 index 0000000..bfea6e5 --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/JournalRespDTO.java @@ -0,0 +1,40 @@ +package com.luoo.comment.pojo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +public class JournalRespDTO implements Serializable { + private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "ID") + private String id; + @ApiModelProperty(value = "剘刊号") + private String journalNo; + @ApiModelProperty(value = "期刊名") + private String title; + @ApiModelProperty(value = "期刊封面") + private String image; + @ApiModelProperty(value = "期刊标签") + private List tags; + @ApiModelProperty(value = "概要") + private String summary; + @ApiModelProperty(value = "文案") + private String content; + @ApiModelProperty(value = "编辑人") + private String editor; + @ApiModelProperty(value = "编辑日期,格式为: yyyy.MM.dd") + private String date; + @ApiModelProperty(value = "期刊发布于") + private String ipLocation; + @ApiModelProperty(value = "已收藏") + private boolean haveCollect; + + @ApiModelProperty(value = "期刊评论top5") + private List commentList; + + @ApiModelProperty(value = "期刊总评论数,大于99,显示99+") + private String totalCommentReply; +} diff --git a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java index f7d6965..e7d8153 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java +++ b/luoo_comment/src/main/java/com/luoo/comment/service/CommentService.java @@ -1,14 +1,17 @@ package com.luoo.comment.service; +import com.luoo.comment.client.JournalClient; import com.luoo.comment.dao.CommentDao; import com.luoo.comment.dao.CommentHisDao; import com.luoo.comment.pojo.Comment; import com.luoo.comment.pojo.CommentHis; +import com.luoo.comment.pojo.JournalRespDTO; import constants.Constants; import dto.UserLoginDto; import dto.UserMessageDto; import enums.MessageTypeEnum; +import org.apache.commons.lang.StringUtils; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -43,6 +46,9 @@ public class CommentService { @Autowired private RabbitTemplate rabbitTemplate; + @Autowired + private JournalClient journalClient; + public List findAll(){ return commentDao.findAll(); } @@ -57,8 +63,15 @@ public class CommentService { comment.setThumbupCount(0); //点赞数 comment.setCommentCount(0); //回复数 comment.setState(1); + comment.setRootId(comment.get_id()); + comment.setRootJournalId(comment.getJournalId()); + if(StringUtils.isNotEmpty(comment.getJournalId())){ + JournalRespDTO journalRespDTO = journalClient.findById(comment.getJournalId()).getData(); + comment.setRootJournalName(journalRespDTO.getTitle()); + comment.setJournalImage(journalRespDTO.getImage()); + } - // 如果当前添加的评论,有父节点,那么父节点的评论回复数要加一 + // 如果当前添加的评论,有父节点,那么根节点的评论回复数要加一 if (comment.getParentId()!=null && !"".equals(comment.getParentId())){ Comment parentComment = commentDao.findById(comment.getParentId()).get(); @@ -76,8 +89,14 @@ public class CommentService { commentHisDao.save(commentHis); comment.setJournalId("");//如果有父节点,将期刊号置为空 + // 将parentComment的rootID值带过来 + comment.setRootId(parentComment.getRootId()); + comment.setRootJournalId(parentComment.getRootJournalId()); + comment.setRootJournalName(parentComment.getRootJournalName()); + comment.setReplyToNickname(parentComment.getNickName()); + comment.setReplyToUserId(parentComment.getUserId()); Query query = new Query(); - query.addCriteria(Criteria.where("_id").is(comment.getParentId())); + query.addCriteria(Criteria.where("_id").is(comment.getRootId())); Update update = new Update(); update.inc("commentCount",1); mongoTemplate.updateFirst(query,update,"comment"); @@ -117,7 +136,7 @@ public class CommentService { public Page findByParentId(String parentId, int page, int size) { Pageable pageable = PageRequest.of(page-1,size); - return commentDao.findByParentId(parentId,pageable); + return commentDao.findByRootIdAndReplyToUserIdNotNull(parentId,pageable); }