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.DiaryPost; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; /** * 日记Mapper接口 * * @author emotion-museum * @version 1.0.0 * @since 2024-01-01 */ @Mapper public interface DiaryPostMapper extends BaseMapper { /** * 分页查询用户的日记 */ @Select("SELECT * FROM diary_post WHERE user_id = #{userId} AND deleted = 0 ORDER BY create_time DESC") IPage selectUserDiaries(Page page, @Param("userId") String userId); /** * 分页查询公开的日记 */ @Select("SELECT * FROM diary_post WHERE is_public = 1 AND status = 1 AND deleted = 0 ORDER BY create_time DESC") IPage selectPublicDiaries(Page page); /** * 根据情绪标签查询日记 */ @Select("SELECT * FROM diary_post WHERE emotion_tags LIKE CONCAT('%', #{emotionTag}, '%') AND is_public = 1 AND status = 1 AND deleted = 0 ORDER BY create_time DESC") IPage selectDiariesByEmotionTag(Page page, @Param("emotionTag") String emotionTag); /** * 统计用户的日记数量 */ @Select("SELECT COUNT(*) FROM diary_post WHERE user_id = #{userId} AND deleted = 0") int countByUserId(@Param("userId") String userId); /** * 统计公开日记数量 */ @Select("SELECT COUNT(*) FROM diary_post WHERE is_public = 1 AND status = 1 AND deleted = 0") int countPublicDiaries(); }