ystx | 89bd544 | 2025-06-07 19:35:27 +0800 | [diff] [blame] | 1 | package com.pt.controller; |
| 2 | |
| 3 | import com.pt.entity.TorrentStats; |
| 4 | import com.pt.service.TorrentStatsService; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | import org.springframework.web.bind.annotation.*; |
| 7 | |
| 8 | import java.util.List; |
| 9 | |
| 10 | @RestController |
| 11 | @RequestMapping("/api/stats") |
Edwardsamaxl | af825a2 | 2025-06-09 21:17:29 +0800 | [diff] [blame] | 12 | @CrossOrigin(origins = "*") |
ystx | 89bd544 | 2025-06-07 19:35:27 +0800 | [diff] [blame] | 13 | public class TorrentStatsController { |
| 14 | |
| 15 | @Autowired |
| 16 | private TorrentStatsService statsService; |
| 17 | |
| 18 | // 1. 获取单个种子统计 |
| 19 | @GetMapping("/{torrentId}") |
| 20 | public TorrentStats getStats(@PathVariable Long torrentId) { |
| 21 | return statsService.getTorrentStats(torrentId); |
| 22 | } |
| 23 | |
| 24 | // 2. 获取热门种子(做种人数TOP N) |
| 25 | @GetMapping("/top-seeded") |
| 26 | public List<TorrentStats> getTopSeeded( |
| 27 | @RequestParam(defaultValue = "10") int limit) { |
| 28 | return statsService.getTopSeededTorrents(limit); |
| 29 | } |
| 30 | |
| 31 | // 3. 获取最近活跃种子 |
| 32 | @GetMapping("/recent-active") |
| 33 | public List<TorrentStats> getRecentActive( |
| 34 | @RequestParam(defaultValue = "10") int limit) { |
| 35 | return statsService.getRecentActiveTorrents(limit); |
| 36 | } |
| 37 | |
| 38 | // 4. 批量获取统计信息 |
| 39 | @PostMapping("/batch") |
| 40 | public List<TorrentStats> getBatchStats(@RequestBody List<Long> torrentIds) { |
| 41 | return statsService.getBatchStats(torrentIds); |
| 42 | } |
| 43 | } |