夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame] | 1 | package com.example.g8backend.controller; |
| 2 | |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 3 | import com.example.g8backend.dto.ApiResponse; |
| 4 | import com.example.g8backend.entity.Report; |
夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame] | 5 | import com.example.g8backend.service.AdminService; |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 6 | import com.example.g8backend.service.IReportService; |
夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame] | 7 | import org.springframework.beans.factory.annotation.Autowired; |
| 8 | import org.springframework.security.access.prepost.PreAuthorize; |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 9 | import org.springframework.security.core.context.SecurityContextHolder; |
| 10 | import org.springframework.web.bind.annotation.*; |
| 11 | |
| 12 | import java.util.List; |
夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame] | 13 | |
| 14 | @RestController |
| 15 | @RequestMapping("/admin") |
| 16 | public class AdminController { |
| 17 | @Autowired |
| 18 | private AdminService adminService; |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 19 | private IReportService reportService; |
夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame] | 20 | @PostMapping("/grant-vip/{userId}") |
| 21 | @PreAuthorize("hasRole('ADMIN')") // 仅允许管理员访问 |
| 22 | public String grantVip(@PathVariable Long userId) { |
| 23 | boolean success = adminService.grantVip(userId); |
| 24 | return success ? "VIP授予成功" : "操作失败(用户不存在)"; |
| 25 | } |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 26 | // 获取举报记录(支持按状态过滤) |
| 27 | @GetMapping("/reports") |
| 28 | @PreAuthorize("hasRole('ADMIN')") |
| 29 | public ApiResponse<List<Report>> getReports( |
| 30 | @RequestParam(required = false) String status) { |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 31 | Long adminId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); |
| 32 | return ApiResponse.success(reportService.getReports(status, adminId)); |
| 33 | } |
| 34 | // 处理举报 |
| 35 | @PutMapping("/reports/{reportId}") |
| 36 | @PreAuthorize("hasRole('ADMIN')") |
| 37 | public ApiResponse<String> resolveReport( |
| 38 | @PathVariable Long reportId, |
| 39 | @RequestParam String status, |
| 40 | @RequestParam(required = false) String notes) { |
夜雨声烦 | 45c25dd | 2025-05-20 11:59:03 +0800 | [diff] [blame] | 41 | Long adminId = (Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal();//这里之前不太对,service改了 |
夜雨声烦 | 363e536 | 2025-05-20 02:01:13 +0800 | [diff] [blame] | 42 | reportService.resolveReport(reportId, adminId, status, notes); |
夜雨声烦 | 70f4c65 | 2025-05-20 01:52:41 +0800 | [diff] [blame] | 43 | return ApiResponse.success("举报处理完成"); |
| 44 | } |
| 45 | |
夜雨声烦 | 451d71c | 2025-05-20 00:58:36 +0800 | [diff] [blame] | 46 | } |