Search in sources :

Example 1 with NewsCommentBO

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;
}
Also used : NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO)

Example 2 with NewsCommentBO

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);
}
Also used : java.util(java.util) CommentZanRepository(com.ch999.haha.admin.repository.redis.CommentZanRepository) PageVO(com.ch999.haha.admin.vo.PageVO) Resource(javax.annotation.Resource) NewsCommentService(com.ch999.haha.admin.service.NewsCommentService) StopWatch(org.springframework.util.StopWatch) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) UserInfoService(com.ch999.haha.admin.service.UserInfoService) CommentReplyVO(com.ch999.haha.admin.vo.CommentReplyVO) CollectionUtils(org.apache.commons.collections.CollectionUtils) PageableVo(com.ch999.haha.common.PageableVo) Service(org.springframework.stereotype.Service) UserInfo(com.ch999.haha.admin.entity.UserInfo) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO) NewsCommentRepository(com.ch999.haha.admin.repository.mongo.NewsCommentRepository) Pageable(org.springframework.data.domain.Pageable) PageVO(com.ch999.haha.admin.vo.PageVO) UserInfo(com.ch999.haha.admin.entity.UserInfo) NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO)

Example 3 with NewsCommentBO

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;
}
Also used : NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO) CommentZanBO(com.ch999.haha.admin.document.redis.CommentZanBO)

Example 4 with NewsCommentBO

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");
    }
}
Also used : NewsCommentBO(com.ch999.haha.admin.document.mongo.NewsCommentBO)

Aggregations

NewsCommentBO (com.ch999.haha.admin.document.mongo.NewsCommentBO)4 CommentZanBO (com.ch999.haha.admin.document.redis.CommentZanBO)2 UserInfo (com.ch999.haha.admin.entity.UserInfo)1 NewsCommentRepository (com.ch999.haha.admin.repository.mongo.NewsCommentRepository)1 CommentZanRepository (com.ch999.haha.admin.repository.redis.CommentZanRepository)1 NewsCommentService (com.ch999.haha.admin.service.NewsCommentService)1 UserInfoService (com.ch999.haha.admin.service.UserInfoService)1 CommentReplyVO (com.ch999.haha.admin.vo.CommentReplyVO)1 PageVO (com.ch999.haha.admin.vo.PageVO)1 PageableVo (com.ch999.haha.common.PageableVo)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Resource (javax.annotation.Resource)1 CollectionUtils (org.apache.commons.collections.CollectionUtils)1 Page (org.springframework.data.domain.Page)1 Pageable (org.springframework.data.domain.Pageable)1 Service (org.springframework.stereotype.Service)1 StopWatch (org.springframework.util.StopWatch)1