use of com.ch999.haha.admin.document.mongo.NewsCommentBO in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method addComment.
@Override
public Boolean addComment(Integer newsId, String commentId, String content, Integer userId) {
NewsCommentBO newsCommentBO;
if (newsId != null) {
newsCommentBO = new NewsCommentBO(newsId, content, userId);
} else {
NewsCommentBO replyComment = newsCommentRepository.findOne(commentId);
NewsCommentBO replyReply = newsCommentRepository.findByHotReplyReplyId(commentId);
newsCommentBO = replyComment == null ? replyReply : replyComment;
if (newsCommentBO == null) {
return false;
}
NewsCommentBO.addReply(newsCommentBO, content, userId, commentId);
}
newsCommentRepository.save(newsCommentBO);
return true;
}
use of com.ch999.haha.admin.document.mongo.NewsCommentBO 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.mongo.NewsCommentBO 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.mongo.NewsCommentBO in project haha by hahafreeasair666.
the class NewsCommentServiceImpl method deleteCommentOrReplyById.
@Override
public Boolean deleteCommentOrReplyById(String id, Integer userId) {
NewsCommentBO newsCommentBO = newsCommentRepository.findOne(id);
newsCommentBO = newsCommentBO != null ? newsCommentBO : newsCommentRepository.findByHotReplyReplyId(id);
if (newsCommentBO == null) {
return null;
}
if (newsCommentBO.getUserId().equals(userId) && id.equals(newsCommentBO.getId())) {
newsCommentBO.setIsDel(true);
newsCommentRepository.save(newsCommentBO);
return true;
} else {
Map<String, Boolean> map = new HashMap<>();
map.put("flag", false);
newsCommentBO.getReplies().forEach(li -> {
if (li.getReplyUserId().equals(userId) && li.getReplyId().equals(id)) {
li.setIsDel(true);
map.put("flag", true);
}
});
newsCommentRepository.save(newsCommentBO);
return map.get("flag");
}
}
Aggregations