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") |
| 12 | public class TorrentStatsController { |
| 13 | |
| 14 | @Autowired |
| 15 | private TorrentStatsService statsService; |
| 16 | |
| 17 | // 1. 获取单个种子统计 |
| 18 | @GetMapping("/{torrentId}") |
| 19 | public TorrentStats getStats(@PathVariable Long torrentId) { |
| 20 | return statsService.getTorrentStats(torrentId); |
| 21 | } |
| 22 | |
| 23 | // 2. 获取热门种子(做种人数TOP N) |
| 24 | @GetMapping("/top-seeded") |
| 25 | public List<TorrentStats> getTopSeeded( |
| 26 | @RequestParam(defaultValue = "10") int limit) { |
| 27 | return statsService.getTopSeededTorrents(limit); |
| 28 | } |
| 29 | |
| 30 | // 3. 获取最近活跃种子 |
| 31 | @GetMapping("/recent-active") |
| 32 | public List<TorrentStats> getRecentActive( |
| 33 | @RequestParam(defaultValue = "10") int limit) { |
| 34 | return statsService.getRecentActiveTorrents(limit); |
| 35 | } |
| 36 | |
| 37 | // 4. 批量获取统计信息 |
| 38 | @PostMapping("/batch") |
| 39 | public List<TorrentStats> getBatchStats(@RequestBody List<Long> torrentIds) { |
| 40 | return statsService.getBatchStats(torrentIds); |
| 41 | } |
| 42 | } |