Files
happy-life-star/server/src/main/java/com/emotionmuseum/mapper/CommentMapper.java
T

52 lines
1.9 KiB
Java

package com.emotionmuseum.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.emotionmuseum.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* 评论Mapper接口
*
* @author emotion-museum
* @version 1.0.0
* @since 2024-01-01
*/
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
/**
* 分页查询内容的评论
*/
@Select("SELECT * FROM comment WHERE content_type = #{contentType} AND content_id = #{contentId} AND parent_id IS NULL AND deleted = 0 ORDER BY create_time DESC")
IPage<Comment> selectContentComments(Page<Comment> page, @Param("contentType") String contentType, @Param("contentId") String contentId);
/**
* 查询评论的回复
*/
@Select("SELECT * FROM comment WHERE parent_id = #{parentId} AND deleted = 0 ORDER BY create_time ASC")
List<Comment> selectCommentReplies(@Param("parentId") String parentId);
/**
* 统计内容的评论数量
*/
@Select("SELECT COUNT(*) FROM comment WHERE content_type = #{contentType} AND content_id = #{contentId} AND deleted = 0")
int countByContent(@Param("contentType") String contentType, @Param("contentId") String contentId);
/**
* 统计用户的评论数量
*/
@Select("SELECT COUNT(*) FROM comment WHERE user_id = #{userId} AND deleted = 0")
int countByUserId(@Param("userId") String userId);
/**
* 查询用户的最新评论
*/
@Select("SELECT * FROM comment WHERE user_id = #{userId} AND deleted = 0 ORDER BY create_time DESC LIMIT #{limit}")
List<Comment> selectUserLatestComments(@Param("userId") String userId, @Param("limit") int limit);
}