blob: 4ff79ea297a9e8597a71e0287cd1d6d8ddc25954 [file] [log] [blame]
2230111590135d72025-06-03 17:11:40 +08001package com.example.myproject.mapper;
2
3import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4import com.example.myproject.entity.Promotion;
5import org.apache.ibatis.annotations.Mapper;
6import org.apache.ibatis.annotations.Param;
7import org.apache.ibatis.annotations.Select;
8import org.apache.ibatis.annotations.Update;
9
10import java.time.LocalDateTime;
11import java.util.List;
12
13@Mapper
14public 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} " +
YelinCui09ee07c2025-06-07 05:09:55 +080027// "AND FIND_IN_SET(#{torrentId}, p.applicable_torrent_ids) > 0"
YelinCuib71605e2025-06-07 09:58:42 +080028 "AND JSON_CONTAINS(p.applicable_torrent_ids, CAST(#{torrentId} AS JSON))")
2230111590135d72025-06-03 17:11:40 +080029 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}