刘嘉昕 | 92bb290 | 2025-06-09 10:35:27 +0800 | [diff] [blame^] | 1 | package com.pt5.pthouduan.controller; |
| 2 | |
| 3 | import com.pt5.pthouduan.entity.UserTrafficStat; |
| 4 | import com.pt5.pthouduan.mapper.UserTrafficMapper; |
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | import org.springframework.format.annotation.DateTimeFormat; |
| 7 | import org.springframework.http.ResponseEntity; |
| 8 | import org.springframework.web.bind.annotation.GetMapping; |
| 9 | import org.springframework.web.bind.annotation.RequestMapping; |
| 10 | import org.springframework.web.bind.annotation.RequestParam; |
| 11 | import org.springframework.web.bind.annotation.RestController; |
| 12 | |
| 13 | import java.time.LocalDate; |
| 14 | import java.util.List; |
| 15 | |
| 16 | @RestController |
| 17 | @RequestMapping("/api/traffic") |
| 18 | public class TrafficController { |
| 19 | |
| 20 | @Autowired |
| 21 | private UserTrafficMapper userTrafficMapper; |
| 22 | |
| 23 | /** |
| 24 | * 获取指定用户在指定时间范围内的上传和下载量统计 |
| 25 | * @param passkey 用户唯一标识(passkey) |
| 26 | * @param startDate 开始时间(格式:yyyy-MM-dd) |
| 27 | * @param endDate 结束时间(格式:yyyy-MM-dd) |
| 28 | * @return 该用户的上传和下载量统计 |
| 29 | */ |
| 30 | @GetMapping("/user-stats") |
| 31 | public ResponseEntity<UserTrafficStat> getUserTrafficStats( |
| 32 | @RequestParam String passkey, // 必须传入 passkey |
| 33 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate, |
| 34 | @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate) { |
| 35 | |
| 36 | // 调用 Mapper 查询数据 |
| 37 | UserTrafficStat stats = userTrafficMapper.getUserTrafficStats(passkey, startDate, endDate); |
| 38 | |
| 39 | return ResponseEntity.ok(stats); |
| 40 | } |
| 41 | } |