blob: a4788355b385b2f43db7bc6b1ccd55a143957c2d [file] [log] [blame]
YelinCuifdf4ed72025-05-26 11:49:36 +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} " +
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}