Merge "增加了种子状态的统计"
diff --git a/src/main/java/com/pt/controller/TorrentStatsController.java b/src/main/java/com/pt/controller/TorrentStatsController.java
new file mode 100644
index 0000000..63e4c72
--- /dev/null
+++ b/src/main/java/com/pt/controller/TorrentStatsController.java
@@ -0,0 +1,42 @@
+package com.pt.controller;
+
+import com.pt.entity.TorrentStats;
+import com.pt.service.TorrentStatsService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/api/stats")
+public class TorrentStatsController {
+
+    @Autowired
+    private TorrentStatsService statsService;
+
+    // 1. 获取单个种子统计
+    @GetMapping("/{torrentId}")
+    public TorrentStats getStats(@PathVariable Long torrentId) {
+        return statsService.getTorrentStats(torrentId);
+    }
+
+    // 2. 获取热门种子(做种人数TOP N)
+    @GetMapping("/top-seeded")
+    public List<TorrentStats> getTopSeeded(
+            @RequestParam(defaultValue = "10") int limit) {
+        return statsService.getTopSeededTorrents(limit);
+    }
+
+    // 3. 获取最近活跃种子
+    @GetMapping("/recent-active")
+    public List<TorrentStats> getRecentActive(
+            @RequestParam(defaultValue = "10") int limit) {
+        return statsService.getRecentActiveTorrents(limit);
+    }
+
+    // 4. 批量获取统计信息
+    @PostMapping("/batch")
+    public List<TorrentStats> getBatchStats(@RequestBody List<Long> torrentIds) {
+        return statsService.getBatchStats(torrentIds);
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/com/pt/service/TorrentStatsService.java b/src/main/java/com/pt/service/TorrentStatsService.java
index ee11689..9596784 100644
--- a/src/main/java/com/pt/service/TorrentStatsService.java
+++ b/src/main/java/com/pt/service/TorrentStatsService.java
@@ -109,4 +109,17 @@
         return statsRepository.findByTorrentId(torrentId)
                 .orElseThrow(() -> new ResourceNotFoundException("Stats not found"));
     }
+
+    // 新增方法
+    public List<TorrentStats> getTopSeededTorrents(int limit) {
+        return statsRepository.findTopBySeederCount(limit);
+    }
+
+    public List<TorrentStats> getRecentActiveTorrents(int limit) {
+        return statsRepository.findRecentActiveTorrents(limit);
+    }
+
+    public List<TorrentStats> getBatchStats(List<Long> torrentIds) {
+        return statsRepository.findByTorrentIds(torrentIds);
+    }
 }
\ No newline at end of file