冷门种子推荐,冷门种子下载不计入下载量,冷门种子自动化判断

Change-Id: Iba4d232d8408195c5af01d2f1686d171e3d5eeac
diff --git a/src/main/resources/mapper/PeerMapper.xml b/src/main/resources/mapper/PeerMapper.xml
index b3d4780..4c90eae 100644
--- a/src/main/resources/mapper/PeerMapper.xml
+++ b/src/main/resources/mapper/PeerMapper.xml
@@ -10,6 +10,22 @@
         SELECT * FROM peers
         WHERE info_hash = #{infoHash} and peer_id = #{peerId}
     </select>
+    <select id="selectAllInfoHashesWithPeers" resultType="String">
+        SELECT DISTINCT info_hash FROM peers
+    </select>
+
+    <select id="countRecentActivity" resultType="Long" parameterType="String">
+        SELECT COUNT(*) FROM peers
+        WHERE info_hash = #{infoHash}
+        AND last_activity_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
+    </select>
+    <select id="selectByInfoHashList" parameterType="list" resultType="com.example.g8backend.entity.Torrent">
+        SELECT * FROM torrents
+        WHERE info_hash IN
+        <foreach item="item" index="index" collection="infoHashes" open="(" separator="," close=")">
+            #{item}
+        </foreach>
+    </select>
     <update id="updatePeer">
         UPDATE peers
         SET uploaded = #{uploaded}, downloaded = #{downloaded}
diff --git a/src/main/resources/mapper/TorrentMapper.xml b/src/main/resources/mapper/TorrentMapper.xml
index 243fd92..cec75eb 100644
--- a/src/main/resources/mapper/TorrentMapper.xml
+++ b/src/main/resources/mapper/TorrentMapper.xml
@@ -31,4 +31,26 @@
         FROM torrents
         WHERE torrent_id = #{torrentId}
     </select>
+
+    <select id="selectByInfoHashList" resultType="com.example.g8backend.entity.Torrent" parameterType="list">
+        SELECT
+        torrent_id,
+        user_id,
+        torrent_name,
+        file_path,
+        HEX(info_hash) AS infoHash,
+        file_size
+        FROM torrents
+        WHERE info_hash IN
+        <foreach collection="infoHashes" item="hash" open="(" separator="," close=")">
+            UNHEX(#{hash})
+        </foreach>
+    </select>
+
+    <update id="updateIsRareByInfoHash">
+        UPDATE torrent
+        SET israre = #{israre}
+        WHERE info_hash = #{infoHash}
+    </update>
+
 </mapper>
\ No newline at end of file
diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql
index 8a2387c..0ace8eb 100644
--- a/src/main/resources/schema.sql
+++ b/src/main/resources/schema.sql
@@ -33,6 +33,8 @@
   `file_path` VARCHAR(255) NOT NULL,
   `info_hash` BINARY(20) NOT NULL,
   `file_size` FLOAT NOT NULL,
+  `upload_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '种子上传时间(第一次插入时自动填充)',
+  `is_rare` BOOLEAN NOT NULL DEFAULT FALSE COMMENT '是否为冷门种子',
   FOREIGN KEY (`user_id`) REFERENCES `users`(`user_id`)
 );
 -- Peer表(保持不变)
@@ -163,7 +165,7 @@
     `post_id` INT NOT NULL COMMENT '被举报的帖子ID',
     `user_id` INT NOT NULL COMMENT '举报人ID',
     `reason` TEXT NOT NULL COMMENT '举报原因',
-    `status` ENUM('pending', 'resolved', 'rejected') DEFAULT 'pending' COMMENT '处理状态(待处理/已解决/已驳回)',
+        `status` ENUM('pending', 'resolved', 'rejected') DEFAULT 'pending' COMMENT '处理状态(待处理/已解决/已驳回)',
     `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '举报时间',
     `resolved_by` INT DEFAULT NULL COMMENT '处理人ID(管理员)',
     `resolved_at` TIMESTAMP DEFAULT NULL COMMENT '处理时间',