fix: comment reply nolimit

main
wangqing 9 months ago
parent d39a95bf3c
commit 42fbe19acc

@ -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<JournalRespDTO> findById(@PathVariable String id);
}

@ -8,6 +8,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
public interface CommentDao extends MongoRepository<Comment,String> { public interface CommentDao extends MongoRepository<Comment,String> {
public Page<Comment> findByParentId(String parentId, Pageable pageable); public Page<Comment> findByParentId(String parentId, Pageable pageable);
public Page<Comment> findByRootIdAndReplyToUserIdNotNull(String rootId, Pageable pageable);
public Page<Comment> findByJournalId(String journalId, Pageable pageable); public Page<Comment> findByJournalId(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable); public Page<Comment> findByJournalIdOrderByPublishTimeDesc(String journalId, Pageable pageable);
public Page<Comment> findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable); public Page<Comment> findByJournalIdOrderByThumbupCountDesc(String journalId, Pageable pageable);

@ -49,4 +49,17 @@ public class Comment implements Serializable {
private String journalImage; private String journalImage;
private boolean haveThumbup; private boolean haveThumbup;
/**
*
*/
private String rootId;
private String rootJournalId;
private String rootJournalName;
private String replyToUserId;
private String replyToNickname;
} }

@ -45,4 +45,14 @@ public class CommentResp implements Serializable {
private String journalId; private String journalId;
private boolean haveThumbup; private boolean haveThumbup;
// private String rootId;
//
// private String rootJournalId;
//
// private String rootJournalName;
private String replyToUserId;
private String replyToNickname;
} }

@ -15,5 +15,5 @@ public class CommentVo {
private String journalId; private String journalId;
private String journalImage; // private String journalImage;
} }

@ -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<String> 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<Comment> commentList;
@ApiModelProperty(value = "期刊总评论数,大于99显示99+")
private String totalCommentReply;
}

@ -1,14 +1,17 @@
package com.luoo.comment.service; package com.luoo.comment.service;
import com.luoo.comment.client.JournalClient;
import com.luoo.comment.dao.CommentDao; import com.luoo.comment.dao.CommentDao;
import com.luoo.comment.dao.CommentHisDao; import com.luoo.comment.dao.CommentHisDao;
import com.luoo.comment.pojo.Comment; import com.luoo.comment.pojo.Comment;
import com.luoo.comment.pojo.CommentHis; import com.luoo.comment.pojo.CommentHis;
import com.luoo.comment.pojo.JournalRespDTO;
import constants.Constants; import constants.Constants;
import dto.UserLoginDto; import dto.UserLoginDto;
import dto.UserMessageDto; import dto.UserMessageDto;
import enums.MessageTypeEnum; import enums.MessageTypeEnum;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
@ -43,6 +46,9 @@ public class CommentService {
@Autowired @Autowired
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@Autowired
private JournalClient journalClient;
public List<Comment> findAll(){ public List<Comment> findAll(){
return commentDao.findAll(); return commentDao.findAll();
} }
@ -57,8 +63,15 @@ public class CommentService {
comment.setThumbupCount(0); //点赞数 comment.setThumbupCount(0); //点赞数
comment.setCommentCount(0); //回复数 comment.setCommentCount(0); //回复数
comment.setState(1); 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())){ if (comment.getParentId()!=null && !"".equals(comment.getParentId())){
Comment parentComment = commentDao.findById(comment.getParentId()).get(); Comment parentComment = commentDao.findById(comment.getParentId()).get();
@ -76,8 +89,14 @@ public class CommentService {
commentHisDao.save(commentHis); commentHisDao.save(commentHis);
comment.setJournalId("");//如果有父节点,将期刊号置为空 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 query = new Query();
query.addCriteria(Criteria.where("_id").is(comment.getParentId())); query.addCriteria(Criteria.where("_id").is(comment.getRootId()));
Update update = new Update(); Update update = new Update();
update.inc("commentCount",1); update.inc("commentCount",1);
mongoTemplate.updateFirst(query,update,"comment"); mongoTemplate.updateFirst(query,update,"comment");
@ -117,7 +136,7 @@ public class CommentService {
public Page<Comment> findByParentId(String parentId, int page, int size) { public Page<Comment> findByParentId(String parentId, int page, int size) {
Pageable pageable = PageRequest.of(page-1,size); Pageable pageable = PageRequest.of(page-1,size);
return commentDao.findByParentId(parentId,pageable); return commentDao.findByRootIdAndReplyToUserIdNotNull(parentId,pageable);
} }

Loading…
Cancel
Save