From faa7c7cfa76bd05d658244a052fa4b6676bc49bb Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Sun, 3 Mar 2024 13:36:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20delete=20comment=20->"=E5=8E=9F=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=B7=B2=E5=88=A0=E9=99=A4"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/luoo/comment/pojo/CommentHis.java | 1 + .../luoo/comment/service/CommentService.java | 30 +++++++++++++++++-- .../java/com/luoo/user/pojo/CommentHis.java | 2 ++ 3 files changed, 31 insertions(+), 2 deletions(-) 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 index 20ca750..a416875 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentHis.java +++ b/luoo_comment/src/main/java/com/luoo/comment/pojo/CommentHis.java @@ -17,6 +17,7 @@ public class CommentHis { private String userId; // 被评论人userid; + private String parentCommentId; // 父评论ID(被评论的ID) private String content; // 被评论的内容; 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 20ceca7..28f2eff 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 @@ -7,6 +7,7 @@ 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 com.luoo.comment.pojo.PublicationLike; import constants.Constants; import dto.UserLoginDto; import dto.UserMessageDto; @@ -96,6 +97,7 @@ public class CommentService { commentHis.setNickName(userLoginDto.getNickName()); commentHis.setCommentContent(comment.getContent()); commentHis.setContent(parentComment.getContent()); + commentHis.setParentCommentId(parentComment.get_id()); commentHis.setCommenterAvatar(Constants.RESOURCE_PREFIX+userLoginDto.getAvatar()); commentHis.setJournalId(parentComment.getJournalId()); commentHis.setJournalImage(parentComment.getJournalImage()); @@ -151,8 +153,32 @@ public class CommentService { cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_HOT+"_"+comment.getRootJournalId()); cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_NEW+"_"+comment.getRootJournalId()); } - commentDao.deleteById(id); - + comment.setContent("原评论已删除"); + // 同步publicationLike和CommentHis + + // 同步更新publicationLike中的评论信息 + Query query1 = new Query(); + query1.addCriteria(Criteria.where("likedItemId").is(id)); + Update update1 = new Update(); + update1.set("commentContent","原评论已删除"); + mongoTemplate.updateMulti(query1,update1, PublicationLike.class); + + + + // 同步更新CommentHis中的评论信息 + Query query2 = new Query(); + query2.addCriteria(Criteria.where("parentCommentId").is(id)); + Update update2 = new Update(); + update2.set("content","原评论已删除"); + mongoTemplate.updateMulti(query2,update2,CommentHis.class); + + Query query3 = new Query(); + query3.addCriteria(Criteria.where("commentId").is(id)); + Update update3 = new Update(); + update3.set("commentContent","原评论已删除"); + mongoTemplate.updateMulti(query3,update3,CommentHis.class); +// commentDao.deleteById(id); + commentDao.save(comment); } public Page findByParentId(String parentId, int page, int size) { 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 index 68e026e..4990a4c 100644 --- a/luoo_user/src/main/java/com/luoo/user/pojo/CommentHis.java +++ b/luoo_user/src/main/java/com/luoo/user/pojo/CommentHis.java @@ -18,6 +18,8 @@ public class CommentHis { private String userId; // 被评论人userid; + private String parentCommentId; // 父评论ID(被评论的ID) + private String content; // 被评论的内容; private String commenterId; // 评论人userId