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} " + |
YelinCui | 09ee07c | 2025-06-07 05:09:55 +0800 | [diff] [blame] | 27 | // "AND FIND_IN_SET(#{torrentId}, p.applicable_torrent_ids) > 0" |
YelinCui | b71605e | 2025-06-07 09:58:42 +0800 | [diff] [blame^] | 28 | "AND JSON_CONTAINS(p.applicable_torrent_ids, CAST(#{torrentId} AS JSON))") |
22301115 | 90135d7 | 2025-06-03 17:11:40 +0800 | [diff] [blame] | 29 | List<Promotion> findActivePromotionsForTorrent( |
| 30 | @Param("torrentId") Long torrentId, |
| 31 | @Param("now") LocalDateTime now); |
| 32 | |
| 33 | /** |
| 34 | * 校验种子id是否存在,返回计数,0代表不存在,>0代表存在 |
| 35 | */ |
| 36 | @Select("SELECT COUNT(*) FROM torrent WHERE id = #{torrentId}") |
| 37 | int checkTorrentExists(@Param("torrentId") Long torrentId); |
| 38 | |
| 39 | /** |
| 40 | * 插入促销活动 |
| 41 | */ |
| 42 | // int insert(Promotion promotion); |
| 43 | |
| 44 | /** |
| 45 | * 根据ID更新促销活动(例如软删除) |
| 46 | */ |
| 47 | int updateById(Promotion promotion); |
| 48 | |
| 49 | /** |
| 50 | * 根据ID查询促销活动 |
| 51 | */ |
| 52 | Promotion selectById(@Param("id") Long id); |
| 53 | } |