Seamher | 0140612 | 2025-06-08 19:44:36 +0800 | [diff] [blame^] | 1 | package com.g9.g9backend.controller; |
| 2 | |
| 3 | import com.g9.g9backend.service.ResourceService; |
| 4 | import com.g9.g9backend.service.ThreadService; |
| 5 | import com.g9.g9backend.service.UserPurchaseService; |
| 6 | import com.g9.g9backend.service.UserUploadService; |
| 7 | import lombok.AllArgsConstructor; |
| 8 | import lombok.Data; |
| 9 | import lombok.NoArgsConstructor; |
| 10 | import org.slf4j.Logger; |
| 11 | import org.slf4j.LoggerFactory; |
| 12 | import org.springframework.http.ResponseEntity; |
| 13 | import org.springframework.web.bind.annotation.GetMapping; |
| 14 | import org.springframework.web.bind.annotation.RequestMapping; |
| 15 | import org.springframework.web.bind.annotation.RestController; |
| 16 | |
| 17 | @RestController |
| 18 | @RequestMapping("/total") |
| 19 | public class TotalController { |
| 20 | |
| 21 | private final ThreadService threadService; |
| 22 | |
| 23 | private final UserPurchaseService userPurchaseService; |
| 24 | |
| 25 | private final UserUploadService userUploadService; |
| 26 | |
| 27 | private final ResourceService resourceService; |
| 28 | |
| 29 | public TotalController(ThreadService threadService, UserPurchaseService userPurchaseService, UserUploadService userUploadService, ResourceService resourceService) { |
| 30 | this.threadService = threadService; |
| 31 | this.userPurchaseService = userPurchaseService; |
| 32 | this.userUploadService = userUploadService; |
| 33 | this.resourceService = resourceService; |
| 34 | } |
| 35 | |
| 36 | private final Logger logger = LoggerFactory.getLogger(TotalController.class); |
| 37 | |
| 38 | |
| 39 | @GetMapping(value = "/info") |
| 40 | public ResponseEntity<Info> getTotalInfo() { |
| 41 | |
| 42 | long threadCount = threadService.count(); |
| 43 | long downloadCount = userPurchaseService.count(); |
| 44 | long authorCount = userUploadService.count(); |
| 45 | long resourceCount = resourceService.count(); |
| 46 | |
| 47 | Info info = new Info(threadCount, downloadCount, authorCount, resourceCount); |
| 48 | logger.info("统计数据返回:{}", info); |
| 49 | |
| 50 | return ResponseEntity.ok(info); |
| 51 | } |
| 52 | |
| 53 | @Data |
| 54 | @AllArgsConstructor |
| 55 | @NoArgsConstructor |
| 56 | public static class Info { |
| 57 | |
| 58 | private long threadCount; |
| 59 | |
| 60 | private long downloadCount; |
| 61 | |
| 62 | private long authorCount; |
| 63 | |
| 64 | private long resourceCount; |
| 65 | |
| 66 | } |
| 67 | } |