CommentService.java 1.36 KB
package com.tanpu.community.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.mapper.community.CommentMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class CommentService {

    @Resource
    private CommentMapper commentMapper;

    public void insertComment(CommentEntity commentEntity) {
        commentMapper.insert(commentEntity);
    }


    public List<CommentEntity> selectByUserId(String userId) {
        return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>().eq(CommentEntity::getAuthorId, userId));
    }

    //统计主题集合的评论量
    public Long getCommentAmountByThemeIds(List<String> themeIds) {
        return (long) commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
                .in(CommentEntity::getTargetId, themeIds)))
                .size();
    }

    public Set<String> getCommentUserAmount(List<String> themeIds) {
        return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
                .in(CommentEntity::getTargetId, themeIds)))
                .stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet());
    }
}