refactor: 后端核心模块功能增强与代码优化

- 完善 User/Product/Order 实体字段和关联关系
- 更新 DTO 适配新增字段
- 增强 Service 层业务逻辑和 Repository 查询方法
- 优化控制器接口,完善管理后台 API
- 新增请求监控过滤器和指标服务
This commit is contained in:
2026-03-10 23:18:08 +08:00
parent 977db8f333
commit 6788fcd5ea
21 changed files with 1194 additions and 120 deletions

View File

@@ -2,6 +2,7 @@ package com.org.flashsalesystem.controller;
import com.org.flashsalesystem.service.AdminService;
import com.org.flashsalesystem.service.FileUploadService;
import com.org.flashsalesystem.service.OrderMigrationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
@@ -28,6 +29,9 @@ public class AdminController {
@Autowired
private FileUploadService fileUploadService;
@Autowired
private OrderMigrationService orderMigrationService;
/**
* 获取仪表盘统计数据
*/
@@ -279,9 +283,10 @@ public class AdminController {
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String category,
@RequestParam(required = false) Integer status) {
try {
Object products = adminService.getProducts(page, size, keyword, status);
Object products = adminService.getProducts(page, size, keyword, category, status);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
@@ -488,4 +493,82 @@ public class AdminController {
return ResponseEntity.badRequest().body(response);
}
}
@GetMapping("/reviews/stats")
public ResponseEntity<Map<String, Object>> getReviewStats() {
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取评价统计成功");
response.put("data", adminService.getReviewStats());
return ResponseEntity.ok(response);
}
@GetMapping("/favorites/stats")
public ResponseEntity<Map<String, Object>> getFavoriteStats() {
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取收藏统计成功");
response.put("data", adminService.getFavoriteStats());
return ResponseEntity.ok(response);
}
@GetMapping("/reviews")
public ResponseEntity<Map<String, Object>> getReviews(@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword) {
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取评价列表成功");
response.put("data", adminService.getReviews(page, size, keyword));
return ResponseEntity.ok(response);
}
@PutMapping("/reviews/{id}")
public ResponseEntity<Map<String, Object>> updateReview(@PathVariable Long id,
@RequestBody com.org.flashsalesystem.dto.ProductReviewDTO.UpdateDTO updateDTO) {
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "更新评价成功");
response.put("data", adminService.updateReview(id, updateDTO));
return ResponseEntity.ok(response);
}
@DeleteMapping("/reviews/{id}")
public ResponseEntity<Map<String, Object>> deleteReview(@PathVariable Long id) {
adminService.deleteReview(id);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "删除评价成功");
return ResponseEntity.ok(response);
}
@GetMapping("/favorites")
public ResponseEntity<Map<String, Object>> getFavorites(@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword) {
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取收藏列表成功");
response.put("data", adminService.getFavorites(page, size, keyword));
return ResponseEntity.ok(response);
}
@DeleteMapping("/favorites/{id}")
public ResponseEntity<Map<String, Object>> deleteFavorite(@PathVariable Long id) {
adminService.deleteFavorite(id);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "删除收藏成功");
return ResponseEntity.ok(response);
}
@PostMapping("/orders/migrate-items")
public ResponseEntity<Map<String, Object>> migrateLegacyOrderItems() {
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "历史订单明细迁移完成");
response.put("data", orderMigrationService.migrateLegacyOrderItems());
return ResponseEntity.ok(response);
}
}