Search in sources :

Example 6 with CommentZanBO

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

Aggregations

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