种子,促销
Change-Id: I0ce919ce4228dcefec26ef636bacd3298c0dc77a
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index b753da7..0590333 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -19,3 +19,13 @@
spring.jpa.enabled=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.open-in-view=false
+
+# tracker??
+pt.tracker.port=6969
+
+pt.tracker.torrent-dir=${user.dir}/data/torrents
+
+pt.tracker.allow-foreign=false
+pt.tracker.announce-url=/custom-announce
+
+mybatis-plus.mapper-locations=classpath:/mapper/**/*.xml
diff --git a/src/main/resources/files/files.torrent b/src/main/resources/files/files.torrent
new file mode 100644
index 0000000..e04974f
--- /dev/null
+++ b/src/main/resources/files/files.torrent
@@ -0,0 +1 @@
+d8:announce22:https://tracker.byr.pt10:created by21:qBittorrent v4.5.3.1013:creation datei1747717901e4:infod5:filesld6:lengthi173e4:pathl13:valid.torrenteee4:name5:files12:piece lengthi16384e6:pieces20:/ñíèEô5ã<òûìÕQ¡ûee
\ No newline at end of file
diff --git a/src/main/resources/mapper/FavoriteMapper.xml b/src/main/resources/mapper/FavoriteMapper.xml
new file mode 100644
index 0000000..1048ec2
--- /dev/null
+++ b/src/main/resources/mapper/FavoriteMapper.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.myproject.mapper.FavoriteMapper">
+
+</mapper>
diff --git a/src/main/resources/mapper/PromotionMapper.xml b/src/main/resources/mapper/PromotionMapper.xml
new file mode 100644
index 0000000..72ffd95
--- /dev/null
+++ b/src/main/resources/mapper/PromotionMapper.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.example.myproject.mapper.PromotionMapper">
+
+ <insert id="insert" parameterType="com.example.myproject.entity.Promotion">
+ INSERT INTO promotion (
+ name, description, start_time, end_time, discount_percentage, applicable_torrent_ids
+ ) VALUES (
+ #{name}, #{description}, #{startTime}, #{endTime}, #{discountPercentage}, #{applicableTorrentIds}
+ )
+ </insert>
+
+</mapper>
diff --git a/src/main/resources/mapper/TorrentMapper.xml b/src/main/resources/mapper/TorrentMapper.xml
new file mode 100644
index 0000000..d5f018e
--- /dev/null
+++ b/src/main/resources/mapper/TorrentMapper.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.example.myproject.mapper.TorrentMapper">
+ <resultMap id="BaseResultMap" type="com.example.myproject.entity.TorrentEntity">
+ <id column="info_hash" property="infoHash"/>
+ <result column="file_name" property="fileName"/>
+ <result column="uploader" property="uploader"/>
+ <result column="upload_time" property="uploadTime"/>
+ <result column="size" property="size"/>
+ <result column="title" property="title"/>
+ <result column="description" property="description"/>
+ <result column="category" property="category"/>
+ <result column="image_url" property="imageUrl"/>
+ </resultMap>
+
+ <select id="selectByInfoHash" resultMap="BaseResultMap">
+ SELECT * FROM torrent WHERE info_hash = #{infoHash}
+ </select>
+ <select id="selectBySeedId" resultMap="BaseResultMap">
+ SELECT * FROM torrent WHERE seed_id = #{seedId}
+ </select>
+
+
+
+
+ <update id="update" parameterType="com.example.myproject.entity.TorrentEntity">
+ UPDATE torrent
+ SET file_name = #{fileName},
+ uploader = #{uploader},
+ upload_time = #{uploadTime},
+ size = #{size},
+ title = #{title},
+ description = #{description},
+ category = #{category},
+ image_url = #{imageUrl}
+ WHERE info_hash = #{infoHash}
+ </update>
+ <select id="search" resultType="com.example.myproject.entity.TorrentEntity">
+ SELECT * FROM torrent
+ <where>
+ <if test="param.category != null">
+ AND category = #{param.category}
+ </if>
+
+ <!-- <if test="param.free != null and param.free != ''">-->
+ <!-- AND free = #{param.free}-->
+ <!-- </if>-->
+ <if test="param.free != null">
+ <choose>
+ <!-- 筛选“正在促销中”的种子 -->
+ <when test="param.free == true">
+ AND EXISTS (
+ SELECT 1 FROM promotion p
+ WHERE
+ JSON_CONTAINS(p.applicable_torrent_ids, JSON_ARRAY(t.id))
+ AND NOW() BETWEEN p.start_time AND p.end_time
+ AND p.is_deleted = 0
+ )
+ </when>
+ <!-- 筛选“未在促销中”的种子 -->
+ <otherwise>
+ AND NOT EXISTS (
+ SELECT 1 FROM promotion p
+ WHERE
+ JSON_CONTAINS(p.applicable_torrent_ids, JSON_ARRAY(t.id))
+ AND NOW() BETWEEN p.start_time AND p.end_time
+ AND p.is_deleted = 0
+ )
+ </otherwise>
+ </choose>
+ </if>
+
+ <if test="param.likeExpressions != null and param.likeExpressions.size > 0">
+ AND (
+ <foreach collection="param.likeExpressions" item="item" open="(" separator=" AND " close=")">
+
+ ( title LIKE CONCAT('%', #{item}, '%') ) or ( description LIKE CONCAT('%', #{item}, '%') ) or ( tags LIKE CONCAT('%', #{item}, '%') )
+ </foreach>
+ )
+ </if>
+ </where>
+
+ <if test="param.prop != null and param.sort != null">
+ ORDER BY ${param.prop} ${param.sort}
+ </if>
+ </select>
+ <select id="checkFavorite" resultType="boolean">
+ SELECT COUNT(*) > 0
+ FROM favorite
+ WHERE seed_id = #{seedId} AND user_id = #{userId}
+ </select>
+ <insert id="addFavorite">
+ INSERT INTO favorite (seed_id, user_id)
+ VALUES (#{seedId}, #{userId})
+ </insert>
+ <delete id="removeFavorite">
+ DELETE FROM favorite
+ WHERE seed_id = #{seedId} AND user_id = #{userId}
+ </delete>
+
+
+</mapper>
\ No newline at end of file
diff --git a/src/main/resources/output/valid.torrent b/src/main/resources/output/valid.torrent
new file mode 100644
index 0000000..6a90e52
--- /dev/null
+++ b/src/main/resources/output/valid.torrent
@@ -0,0 +1 @@
+d10:created by18:qBittorrent v5.1.013:creation datei1745948995e4:infod6:lengthi22e4:name15:example.torrent12:piece lengthi16384e6:pieces20:Fnð¶)ú<Ç æÂh£tl7:privatei1eee
\ No newline at end of file