blob: c07bd9162545282f75748223c9f3e58018a169aa [file] [log] [blame]
刘嘉昕92bb2902025-06-09 10:35:27 +08001package com.pt5.pthouduan.controller;
2
3import com.pt5.pthouduan.entity.UserTrafficStat;
4import com.pt5.pthouduan.mapper.UserTrafficMapper;
5import org.springframework.beans.factory.annotation.Autowired;
6import org.springframework.format.annotation.DateTimeFormat;
7import org.springframework.http.ResponseEntity;
8import org.springframework.web.bind.annotation.GetMapping;
9import org.springframework.web.bind.annotation.RequestMapping;
10import org.springframework.web.bind.annotation.RequestParam;
11import org.springframework.web.bind.annotation.RestController;
12
13import java.time.LocalDate;
14import java.util.List;
15
16@RestController
17@RequestMapping("/api/traffic")
18public 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}