|
|
|
@ -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<Comment> 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<Comment> findByParentId(String parentId, int page, int size) {
|
|
|
|
|
|
|
|
|
|
Pageable pageable = PageRequest.of(page-1,size);
|
|
|
|
|
return commentDao.findByParentId(parentId,pageable);
|
|
|
|
|
return commentDao.findByRootIdAndReplyToUserIdNotNull(parentId,pageable);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|