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 { /** * 分页查询内容的评论 */ @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 selectContentComments(Page 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 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 selectUserLatestComments(@Param("userId") String userId, @Param("limit") int limit); }