From e8ff3810af334a5355a53b3b1c546a1fd5d012bf Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 7 Feb 2024 20:15:12 +0800 Subject: [PATCH] feat:my available comment detail list --- .../com/luoo/comment/dao/CommentHisDao.java | 8 ++++ .../java/com/luoo/comment/pojo/Comment.java | 2 + .../com/luoo/comment/pojo/CommentHis.java | 42 +++++++++++++++++++ .../java/com/luoo/comment/pojo/CommentVo.java | 2 + .../luoo/comment/service/CommentService.java | 26 +++++++++++- .../luoo/user/controller/MyController.java | 9 ++-- .../java/com/luoo/user/dao/CommentHisDao.java | 13 ++++++ .../java/com/luoo/user/pojo/CommentHis.java | 42 +++++++++++++++++++ .../java/com/luoo/user/service/MyService.java | 12 ++++-- 9 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 luoo_comment/src/main/java/com/luoo/comment/dao/CommentHisDao.java create mode 100644 luoo_comment/src/main/java/com/luoo/comment/pojo/CommentHis.java create mode 100644 luoo_user/src/main/java/com/luoo/user/dao/CommentHisDao.java create mode 100644 luoo_user/src/main/java/com/luoo/user/pojo/CommentHis.java diff --git a/luoo_comment/src/main/java/com/luoo/comment/dao/CommentHisDao.java b/luoo_comment/src/main/java/com/luoo/comment/dao/CommentHisDao.java new file mode 100644 index 0000000..587d565 --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/dao/CommentHisDao.java @@ -0,0 +1,8 @@ +package com.luoo.comment.dao; + +import com.luoo.comment.pojo.CommentHis; +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface CommentHisDao extends MongoRepository { + +} 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 3d71ce4..fc9137e 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 @@ -46,5 +46,7 @@ public class Comment implements Serializable { private String journalId; + private String journalImage; + private boolean haveThumbup; } diff --git a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentHis.java b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentHis.java new file mode 100644 index 0000000..a9d631d --- /dev/null +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentHis.java @@ -0,0 +1,42 @@ +package com.luoo.comment.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + + +@Data +public class CommentHis { + + @Id + private String _id; + + + private String userId; // 被评论人userid; + + + private String content; // 被评论的内容; + + private String commenterId; // 评论人userId + + private String commenterAvatar; // 评论人头像 + + + private String commentContent; //评论的内容 + + + + private String nickName; // 评论人昵称 + + private String journalId; // 期刊ID + + private String journalImage; // 期刊封面 + + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; +} 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 53b9f90..00e8568 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 @@ -14,4 +14,6 @@ public class CommentVo { private String parentId; private String journalId; + + private String journalImage; } 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 208db47..f66c66d 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 @@ -2,7 +2,9 @@ package com.luoo.comment.service; 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 constants.Constants; import dto.UserLoginDto; import dto.UserMessageDto; @@ -24,12 +26,14 @@ import java.util.Date; import java.util.List; @Service -@Transactional public class CommentService { @Autowired private CommentDao commentDao; + @Autowired + private CommentHisDao commentHisDao; + @Autowired private IdWorker idWorker; @@ -56,6 +60,20 @@ public class CommentService { // 如果当前添加的评论,有父节点,那么父节点的评论回复数要加一 if (comment.getParentId()!=null && !"".equals(comment.getParentId())){ + Comment parentComment = commentDao.findById(comment.getParentId()).get(); + + CommentHis commentHis = new CommentHis(); + commentHis.set_id(idWorker.nextId()+""); + commentHis.setCommenterId(userLoginDto.getUserId()); + commentHis.setUserId(parentComment.getUserId()); + commentHis.setNickName(userLoginDto.getNickName()); + commentHis.setCommentContent(comment.getContent()); + commentHis.setContent(parentComment.getContent()); + commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); + commentHis.setJournalId(parentComment.getJournalId()); + commentHis.setJournalImage(parentComment.getJournalImage()); + commentHis.setCreateTime(new Date()); + commentHisDao.save(commentHis); comment.setJournalId("");//如果有父节点,将期刊号置为空 Query query = new Query(); @@ -64,7 +82,8 @@ public class CommentService { update.inc("commentCount",1); mongoTemplate.updateFirst(query,update,"comment"); - Comment parentComment = commentDao.findById(comment.getParentId()).get(); + + /** * 向被评论者发消息 */ @@ -77,6 +96,9 @@ public class CommentService { userMessageDto.setSendUserId(userLoginDto.getUserId()); userMessageDto.setSendUserNickName(userLoginDto.getNickName()); rabbitTemplate.convertAndSend("userMessage",userMessageDto); + + + } commentDao.save(comment); diff --git a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java index 68eab22..674afd8 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/MyController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/MyController.java @@ -9,9 +9,7 @@ import java.util.function.Function; import java.util.stream.Collectors; import com.luoo.user.dto.TotalCommentVo; -import com.luoo.user.pojo.Feedback; -import com.luoo.user.pojo.PublicationLike; -import com.luoo.user.pojo.UserCollectInfo; +import com.luoo.user.pojo.*; import com.luoo.user.service.*; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -38,7 +36,6 @@ import controller.BaseController; import com.luoo.user.dto.UserInfoUpdateDto; import com.luoo.user.dto.response.UserRespDTO; -import com.luoo.user.pojo.UserInfo; import com.luoo.user.util.IpUtil; import annotation.GlobalInterceptor; @@ -341,8 +338,8 @@ public class MyController extends BaseController { return Result.unauthorized(null); } String userId = userLoginDto.getUserId(); - myService.getMyCommentReplyList(userId); - return null; + Page pageList = myService.getMyCommentReplyList(userId,page,size); + return Result.success(new PageResult(pageList.getTotalElements(),pageList.getContent())); } diff --git a/luoo_user/src/main/java/com/luoo/user/dao/CommentHisDao.java b/luoo_user/src/main/java/com/luoo/user/dao/CommentHisDao.java new file mode 100644 index 0000000..cb20191 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dao/CommentHisDao.java @@ -0,0 +1,13 @@ +package com.luoo.user.dao; + +import com.luoo.user.pojo.CommentHis; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.mongodb.repository.MongoRepository; + +public interface CommentHisDao extends MongoRepository { + + + public Page findByUserIdOrderByCreateTimeDesc(String userId, Pageable pageable); + +} diff --git a/luoo_user/src/main/java/com/luoo/user/pojo/CommentHis.java b/luoo_user/src/main/java/com/luoo/user/pojo/CommentHis.java new file mode 100644 index 0000000..c01faec --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/pojo/CommentHis.java @@ -0,0 +1,42 @@ +package com.luoo.user.pojo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + + +@Data +public class CommentHis { + + @Id + private String _id; + + + private String userId; // 被评论人userid; + + + private String content; // 被评论的内容; + + private String commenterId; // 评论人userId + + private String commenterAvatar; // 评论人头像 + + + private String commentContent; //评论的内容 + + + + private String nickName; // 评论人昵称 + + private String journalId; // 期刊ID + + private String journalImage; // 期刊封面 + + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private Date createTime; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/MyService.java b/luoo_user/src/main/java/com/luoo/user/service/MyService.java index fb35398..958eee4 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/MyService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/MyService.java @@ -1,7 +1,9 @@ package com.luoo.user.service; +import com.luoo.user.dao.CommentHisDao; import com.luoo.user.dao.PublicationLikeDao; +import com.luoo.user.pojo.CommentHis; import com.luoo.user.pojo.PublicationLike; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -13,19 +15,23 @@ import org.springframework.stereotype.Service; @Service public class MyService { - @Autowired - private MongoTemplate mongoTemplate; @Autowired private PublicationLikeDao publicationLikeDao; + + @Autowired + private CommentHisDao commentHisDao; + /** * 我收到的评论 * @param userId */ - public void getMyCommentReplyList(String userId) { + public Page getMyCommentReplyList(String userId, int page, int size) { + Pageable pageable = PageRequest.of(page-1,size); + return commentHisDao.findByUserIdOrderByCreateTimeDesc(userId,pageable); }