CommentService.java 2.39 KB
Newer Older
刘基明's avatar
刘基明 committed
1 2 3
package com.tanpu.community.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
刘基明's avatar
刘基明 committed
4
import com.tanpu.common.uuid.UuidGenHelper;
刘基明's avatar
刘基明 committed
5 6
import com.tanpu.community.api.enums.DeleteTagEnum;
import com.tanpu.community.api.enums.TopicStatusEnum;
刘基明's avatar
刘基明 committed
7 8
import com.tanpu.community.dao.entity.community.CommentEntity;
import com.tanpu.community.dao.mapper.community.CommentMapper;
刘基明's avatar
刘基明 committed
9
import org.springframework.beans.factory.annotation.Autowired;
刘基明's avatar
刘基明 committed
10 11 12 13
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
刘基明's avatar
刘基明 committed
14 15
import java.util.Set;
import java.util.stream.Collectors;
刘基明's avatar
刘基明 committed
16 17 18 19 20 21 22

@Service
public class CommentService {

    @Resource
    private CommentMapper commentMapper;

刘基明's avatar
刘基明 committed
23 24 25
    @Autowired
    private UuidGenHelper uuidGenHelper;

刘基明's avatar
刘基明 committed
26
    public void insertComment(CommentEntity commentEntity) {
刘基明's avatar
刘基明 committed
27
        commentEntity.setCommentId(uuidGenHelper.getUuidStr());
刘基明's avatar
刘基明 committed
28 29 30 31
        commentMapper.insert(commentEntity);
    }


刘基明's avatar
刘基明 committed
32 33
    public List<CommentEntity> selectByUserId(String userId) {
        return commentMapper.selectList(new LambdaQueryWrapper<CommentEntity>().eq(CommentEntity::getAuthorId, userId));
刘基明's avatar
刘基明 committed
34
    }
刘基明's avatar
刘基明 committed
35 36

    //统计主题集合的评论量
刘基明's avatar
刘基明 committed
37 38
    public Integer getCommentCountByThemeIds(List<String> themeIds) {
        return  commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
刘基明's avatar
刘基明 committed
39
                .in(CommentEntity::getThemeId, themeIds)))
刘基明's avatar
刘基明 committed
40 41
                .size();
    }
刘基明's avatar
刘基明 committed
42

刘基明's avatar
刘基明 committed
43
    public Set<String> getCommentUserCount(List<String> themeIds) {
刘基明's avatar
刘基明 committed
44
        return commentMapper.selectList((new LambdaQueryWrapper<CommentEntity>()
刘基明's avatar
刘基明 committed
45
                .in(CommentEntity::getThemeId, themeIds)))
刘基明's avatar
刘基明 committed
46 47
                .stream().map(CommentEntity::getAuthorId).collect(Collectors.toSet());
    }
刘基明's avatar
刘基明 committed
48

刘基明's avatar
刘基明 committed
49 50 51
    public List<CommentEntity> selectByThemeIdAndParentId(String themeId, String parentId) {
        LambdaQueryWrapper<CommentEntity> queryWrapper = new LambdaQueryWrapper<CommentEntity>()
                .eq(CommentEntity::getThemeId, themeId)
刘基明's avatar
刘基明 committed
52 53
                .eq(CommentEntity::getDeleteTag, DeleteTagEnum.NOT_DELETED.getCode())
                .eq(CommentEntity::getIsBlock, TopicStatusEnum.FALSE.getCode())
刘基明's avatar
刘基明 committed
54 55 56 57 58 59 60
                .orderByDesc(CommentEntity::getCreateTime);
        if (parentId == null) {
            queryWrapper.isNull(CommentEntity::getParentId);
        } else {
            queryWrapper.eq(CommentEntity::getParentId, parentId);
        }
        return commentMapper.selectList(queryWrapper);
刘基明's avatar
刘基明 committed
61 62 63
    }


刘基明's avatar
刘基明 committed
64
}