use of com.ch999.haha.admin.vo.CommentReplyVO in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method getCommentReplies.
@Override
public CommentReplyVO getCommentReplies(String commentId, PageableVo pageable, Integer userId) {
StopWatch stopWatch = new StopWatch("mongo");
stopWatch.start("查询");
CommentReplyVO commentReplyVO = new CommentReplyVO(newsCommentRepository.findOne(commentId), pageable);
stopWatch.stop();
if (commentReplyVO.getNewsCommentAndReply() != null) {
stopWatch.start("评论处理");
UserInfo userInfo = userInfoService.selectById(commentReplyVO.getNewsCommentAndReply().getUserId());
commentReplyVO.getNewsCommentAndReply().setAvatar(userInfo.getPicPath());
commentReplyVO.getNewsCommentAndReply().setUserName(userInfo.getUsername());
if (commentReplyVO.getNewsCommentAndReply().getZan() > 0 && userId != null) {
CommentZanBO one = commentZanRepository.findOne(commentReplyVO.getNewsCommentAndReply().getId());
if (one != null) {
commentReplyVO.getNewsCommentAndReply().setIsPraised(one.getZanUserList().parallelStream().anyMatch(li -> li.equals(userId)));
} else {
commentReplyVO.getNewsCommentAndReply().setIsPraised(false);
}
} else {
commentReplyVO.getNewsCommentAndReply().setIsPraised(false);
}
// 设置能否删除该评论字段
if (commentReplyVO.getNewsCommentAndReply().getUserId().equals(userId)) {
commentReplyVO.getNewsCommentAndReply().setIsCanDel(true);
} else {
commentReplyVO.getNewsCommentAndReply().setIsCanDel(false);
}
stopWatch.stop();
if (CollectionUtils.isNotEmpty(commentReplyVO.getNewsCommentAndReply().getReplies())) {
stopWatch.start("回复分页处理");
commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().stream().filter(li -> !li.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()));
Integer replySize = commentReplyVO.getNewsCommentAndReply().getReplies().size();
if (replySize >= pageable.getPage() * pageable.getSize() - pageable.getSize()) {
if (pageable.getPage() == 1) {
commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().subList(0, pageable.getSize() > replySize ? replySize : pageable.getSize()));
} else {
commentReplyVO.getNewsCommentAndReply().setReplies(commentReplyVO.getNewsCommentAndReply().getReplies().subList(pageable.getPage() * pageable.getSize() - pageable.getSize(), replySize > pageable.getPage() * pageable.getSize() ? pageable.getPage() * pageable.getSize() : replySize));
}
} else {
commentReplyVO.getNewsCommentAndReply().setReplies(new ArrayList<>());
}
stopWatch.stop();
stopWatch.start("数据库查询操作");
commentReplyVO.getNewsCommentAndReply().getReplies().forEach(li -> handleReplies(li, userId));
stopWatch.stop();
}
}
System.out.println(stopWatch.prettyPrint());
return commentReplyVO;
}
Aggregations