刘嘉昕 | f28ea23 | 2025-04-15 16:55:43 +0800 | [diff] [blame] | 1 | package com.pt5.pthouduan.mapper; |
| 2 | |
| 3 | import com.pt5.pthouduan.entity.Post; |
| 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| 5 | import org.apache.ibatis.annotations.Mapper; |
ym923 | f1d9f45 | 2025-05-27 18:29:44 +0800 | [diff] [blame^] | 6 | import org.apache.ibatis.annotations.Param; |
| 7 | |
| 8 | import java.util.List; |
刘嘉昕 | f28ea23 | 2025-04-15 16:55:43 +0800 | [diff] [blame] | 9 | |
| 10 | /** |
| 11 | * <p> |
ym923 | f1d9f45 | 2025-05-27 18:29:44 +0800 | [diff] [blame^] | 12 | * 帖子 Mapper 接口 |
刘嘉昕 | f28ea23 | 2025-04-15 16:55:43 +0800 | [diff] [blame] | 13 | * </p> |
| 14 | * |
ym923 | f1d9f45 | 2025-05-27 18:29:44 +0800 | [diff] [blame^] | 15 | * 功能:增、删、改、查(按关键词)、点赞、置顶、用户帖子查询、置顶帖子查询 |
| 16 | * |
| 17 | * 作者:杨蔓 |
刘嘉昕 | f28ea23 | 2025-04-15 16:55:43 +0800 | [diff] [blame] | 18 | * @since 2025-04-14 |
| 19 | */ |
| 20 | @Mapper |
| 21 | public interface PostMapper extends BaseMapper<Post> { |
| 22 | |
ym923 | f1d9f45 | 2025-05-27 18:29:44 +0800 | [diff] [blame^] | 23 | // 创建帖子 |
| 24 | void save(Post post); |
| 25 | |
| 26 | // 根据帖子ID删除 |
| 27 | int deleteByPostid(@Param("postid") Integer postid); |
| 28 | |
| 29 | // 更新帖子 |
| 30 | int updatePost(Post post); |
| 31 | |
| 32 | // 模糊搜索(标题或标签) |
| 33 | List<Post> searchByKeyword(@Param("keyword") String keyword); |
| 34 | |
| 35 | // 点赞 +1 |
| 36 | int incrementLikes(@Param("postid") Integer postid); |
| 37 | |
| 38 | // 取消点赞 -1(最小为0) |
| 39 | int decrementLikes(@Param("postid") Integer postid); |
| 40 | |
| 41 | // 设置置顶状态 |
| 42 | int updatePinnedStatus(@Param("postid") Integer postid, @Param("pinned") boolean pinned); |
| 43 | |
| 44 | // 根据用户ID查询该用户所有帖子 |
| 45 | List<Post> findByUserid(@Param("userid") Long userid); |
| 46 | |
| 47 | // 查询所有置顶帖子 |
| 48 | List<Post> findPinnedPosts(); |
| 49 | |
| 50 | // ✅ 新增:查询所有帖子(置顶优先,时间倒序) |
| 51 | List<Post> selectAllSorted(); |
刘嘉昕 | f28ea23 | 2025-04-15 16:55:43 +0800 | [diff] [blame] | 52 | } |