22301115 | 90135d7 | 2025-06-03 17:11:40 +0800 | [diff] [blame^] | 1 | package com.example.myproject.mapper; |
| 2 | |
| 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| 4 | import com.example.myproject.entity.Promotion; |
| 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | import org.apache.ibatis.annotations.Param; |
| 7 | import org.apache.ibatis.annotations.Select; |
| 8 | import org.apache.ibatis.annotations.Update; |
| 9 | |
| 10 | import java.time.LocalDateTime; |
| 11 | import java.util.List; |
| 12 | |
| 13 | @Mapper |
| 14 | public interface PromotionMapper extends BaseMapper<Promotion> { |
| 15 | |
| 16 | @Select("SELECT * FROM promotion WHERE is_deleted = false " + |
| 17 | "AND start_time <= #{now} AND end_time >= #{now}") |
| 18 | List<Promotion> findActivePromotions(@Param("now") LocalDateTime now); |
| 19 | |
| 20 | /** |
| 21 | * 查找某个torrentId是否在促销活动的applicable_torrent_ids字符串中 |
| 22 | * 用MySQL的FIND_IN_SET判断 |
| 23 | */ |
| 24 | @Select("SELECT p.* FROM promotion p " + |
| 25 | "WHERE p.is_deleted = false " + |
| 26 | "AND p.start_time <= #{now} AND p.end_time >= #{now} " + |
| 27 | "AND FIND_IN_SET(#{torrentId}, p.applicable_torrent_ids) > 0") |
| 28 | List<Promotion> findActivePromotionsForTorrent( |
| 29 | @Param("torrentId") Long torrentId, |
| 30 | @Param("now") LocalDateTime now); |
| 31 | |
| 32 | /** |
| 33 | * 校验种子id是否存在,返回计数,0代表不存在,>0代表存在 |
| 34 | */ |
| 35 | @Select("SELECT COUNT(*) FROM torrent WHERE id = #{torrentId}") |
| 36 | int checkTorrentExists(@Param("torrentId") Long torrentId); |
| 37 | |
| 38 | /** |
| 39 | * 插入促销活动 |
| 40 | */ |
| 41 | // int insert(Promotion promotion); |
| 42 | |
| 43 | /** |
| 44 | * 根据ID更新促销活动(例如软删除) |
| 45 | */ |
| 46 | int updateById(Promotion promotion); |
| 47 | |
| 48 | /** |
| 49 | * 根据ID查询促销活动 |
| 50 | */ |
| 51 | Promotion selectById(@Param("id") Long id); |
| 52 | } |