blob: 8e5419bd515665967b4feb514b865a4d87ac19f6 [file] [log] [blame]
22301126e1131602025-06-04 11:30:10 +08001<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
3 "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
5<mapper namespace="com.example.myproject.mapper.TorrentMapper">
6 <resultMap id="BaseResultMap" type="com.example.myproject.entity.TorrentEntity">
7 <id column="info_hash" property="infoHash"/>
8 <result column="file_name" property="fileName"/>
9 <result column="uploader" property="uploader"/>
10 <result column="upload_time" property="uploadTime"/>
11 <result column="size" property="size"/>
12 <result column="title" property="title"/>
13 <result column="description" property="description"/>
14 <result column="category" property="category"/>
15 <result column="image_url" property="imageUrl"/>
16 </resultMap>
17
18 <select id="selectByInfoHash" resultMap="BaseResultMap">
19 SELECT * FROM torrent WHERE info_hash = #{infoHash}
20 </select>
21 <select id="selectBySeedId" resultMap="BaseResultMap">
22 SELECT * FROM torrent WHERE seed_id = #{seedId}
23 </select>
24
25
26
27
28 <update id="update" parameterType="com.example.myproject.entity.TorrentEntity">
29 UPDATE torrent
30 SET file_name = #{fileName},
31 uploader = #{uploader},
32 upload_time = #{uploadTime},
33 size = #{size},
34 title = #{title},
35 description = #{description},
36 category = #{category},
37 image_url = #{imageUrl}
38 WHERE info_hash = #{infoHash}
39 </update>
40 <select id="search" resultType="com.example.myproject.entity.TorrentEntity">
41 SELECT * FROM torrent
42 <where>
43 <if test="param.category != null">
44 AND category = #{param.category}
45 </if>
46
47 <!-- <if test="param.free != null and param.free != ''">-->
48 <!-- AND free = #{param.free}-->
49 <!-- </if>-->
50 <if test="param.free != null">
51 <choose>
52 <!-- 筛选“正在促销中”的种子 -->
53 <when test="param.free == true">
54 AND EXISTS (
55 SELECT 1 FROM promotion p
56 WHERE
57 JSON_CONTAINS(p.applicable_torrent_ids, JSON_ARRAY(t.id))
58 AND NOW() BETWEEN p.start_time AND p.end_time
59 AND p.is_deleted = 0
60 )
61 </when>
62 <!-- 筛选“未在促销中”的种子 -->
63 <otherwise>
64 AND NOT EXISTS (
65 SELECT 1 FROM promotion p
66 WHERE
67 JSON_CONTAINS(p.applicable_torrent_ids, JSON_ARRAY(t.id))
68 AND NOW() BETWEEN p.start_time AND p.end_time
69 AND p.is_deleted = 0
70 )
71 </otherwise>
72 </choose>
73 </if>
74
75 <if test="param.likeExpressions != null and param.likeExpressions.size > 0">
76 AND (
77 <foreach collection="param.likeExpressions" item="item" open="(" separator=" AND " close=")">
78
79 ( title LIKE CONCAT('%', #{item}, '%') ) or ( description LIKE CONCAT('%', #{item}, '%') ) or ( tags LIKE CONCAT('%', #{item}, '%') )
80 </foreach>
81 )
82 </if>
83 </where>
84
85 <if test="param.prop != null and param.sort != null">
86 ORDER BY ${param.prop} ${param.sort}
87 </if>
88 </select>
89 <select id="checkFavorite" resultType="boolean">
90 SELECT COUNT(*) > 0
91 FROM favorite
92 WHERE seed_id = #{seedId} AND user_id = #{userId}
93 </select>
94 <insert id="addFavorite">
95 INSERT INTO favorite (seed_id, user_id)
96 VALUES (#{seedId}, #{userId})
97 </insert>
98 <delete id="removeFavorite">
99 DELETE FROM favorite
100 WHERE seed_id = #{seedId} AND user_id = #{userId}
101 </delete>
YelinCui09ee07c2025-06-07 05:09:55 +0800102 <select id="selectMyFavorite" resultType="com.example.myproject.entity.TorrentEntity">
103 SELECT t.*
104 FROM torrent t
105 JOIN favorite f ON t.id = f.seed_id
106 WHERE f.user_id = #{userId}
107 </select>
22301126e1131602025-06-04 11:30:10 +0800108
109</mapper>