use of com.ch999.haha.admin.document.redis.CommentZanBO in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method addZan.
@Override
public Boolean addZan(String id, Integer userId) {
NewsCommentBO newsCommentBO = newsCommentRepository.findOne(id);
newsCommentBO = newsCommentBO != null ? newsCommentBO : newsCommentRepository.findByHotReplyReplyId(id);
if (newsCommentBO == null) {
return null;
}
CommentZanBO one = commentZanRepository.findOne(id);
if (one != null) {
if (one.getZanUserList().parallelStream().anyMatch(li -> li.equals(userId))) {
return false;
} else {
one.getZanUserList().add(userId);
}
} else {
one = new CommentZanBO();
one.setCommentId(id);
List<Integer> zanList = new ArrayList<>();
zanList.add(userId);
one.setZanUserList(zanList);
}
NewsCommentBO.updateZanCount(newsCommentBO, id, one.getZanUserList().size());
newsCommentRepository.save(newsCommentBO);
commentZanRepository.save(one);
return true;
}
use of com.ch999.haha.admin.document.redis.CommentZanBO in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method getNewsCommentList.
@Override
public PageVO<NewsCommentBO> getNewsCommentList(Integer newsId, Pageable pageable, Integer userId) {
Page<NewsCommentBO> allByNewsIdAndIsDel = newsCommentRepository.findAllByNewsIdAndIsDel(newsId, false, pageable);
List<NewsCommentBO> commentList = allByNewsIdAndIsDel.getContent();
commentList.forEach(li -> {
// 评论中评论的回复只显示未删除的点赞最多的三条
if (li.getReplies().size() > 3) {
li.setReplies(li.getReplies().stream().filter(de -> !de.getIsDel()).sorted(Comparator.comparing(NewsCommentBO.Reply::getZan).reversed()).collect(Collectors.toList()).subList(0, 3));
li.setIsNeedOpen(true);
} else {
li.setIsNeedOpen(false);
}
// 评论字段赋值
UserInfo userInfo = userInfoService.selectById(li.getUserId());
li.setUserName(userInfo.getUsername());
li.setAvatar(userInfo.getPicPath());
if (li.getZan() > 0 && userId != null) {
CommentZanBO zanInfo = commentZanRepository.findOne(li.getId());
if (zanInfo != null && zanInfo.getZanUserList().parallelStream().anyMatch(zan -> zan.equals(userId))) {
li.setIsPraised(true);
} else {
li.setIsPraised(false);
}
} else {
li.setIsPraised(false);
}
// 设置能否删除该评论字段
if (li.getUserId().equals(userId)) {
li.setIsCanDel(true);
} else {
li.setIsCanDel(false);
}
// 回复字段赋值
li.getReplies().forEach(re -> handleReplies(re, userId));
});
return new PageVO(allByNewsIdAndIsDel, pageable.getPageNumber(), commentList);
}
use of com.ch999.haha.admin.document.redis.CommentZanBO in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method handleReplies.
private void handleReplies(NewsCommentBO.Reply re, Integer userId) {
UserInfo replyUserInfo = userInfoService.selectById(re.getReplyUserId());
UserInfo toUserInfo = userInfoService.selectById(re.getToUserId());
re.setReplyUserAvatar(replyUserInfo.getPicPath());
re.setReplyUserName(replyUserInfo.getUsername());
re.setToUserName(toUserInfo.getUsername());
if (re.getZan() > 0 && userId != null) {
CommentZanBO toZanInfo = commentZanRepository.findOne(re.getReplyId());
if (toZanInfo != null) {
re.setIsPraised(toZanInfo.getZanUserList().parallelStream().anyMatch(z -> z.equals(userId)));
} else {
re.setIsPraised(false);
}
} else {
re.setIsPraised(false);
}
// 设置能否删除该评论字段
if (re.getReplyUserId().equals(userId)) {
re.setIsCanDel(true);
} else {
re.setIsCanDel(false);
}
}
use of com.ch999.haha.admin.document.redis.CommentZanBO 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;
}
use of com.ch999.haha.admin.document.redis.CommentZanBO in project haha by hahafreeasair666.
the class NewsServiceImpl method addNewsZan.
@Override
public Boolean addNewsZan(Integer id, Integer userId) {
News news = this.selectById(id);
if (news == null) {
return null;
}
CommentZanBO one = commentZanRepository.findOne(id.toString());
if (one != null) {
if (one.getZanUserList().stream().anyMatch(li -> li.equals(userId))) {
return false;
}
one.getZanUserList().add(userId);
} else {
one = new CommentZanBO();
one.setCommentId(id.toString());
List<Integer> list = new ArrayList<>();
list.add(userId);
one.setZanUserList(list);
}
news.setZan(one.getZanUserList().size());
this.updateById(news);
commentZanRepository.save(one);
return true;
}
Aggregations