后台完成修复,初始化项目

This commit is contained in:
2025-07-01 17:18:04 +08:00
commit 5916f076b7
74 changed files with 17444 additions and 0 deletions

View File

@@ -0,0 +1,452 @@
package com.org.flashsalesystem.controller;
import com.org.flashsalesystem.service.AdminService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 管理后台API控制器
*/
@Tag(name = "管理后台API", description = "管理后台相关接口")
@RestController
@RequestMapping("/api/admin")
@Slf4j
public class AdminController {
@Autowired
private AdminService adminService;
/**
* 获取仪表盘统计数据
*/
@Operation(summary = "获取仪表盘统计数据")
@GetMapping("/dashboard/stats")
public ResponseEntity<Map<String, Object>> getDashboardStats() {
try {
Map<String, Object> stats = adminService.getDashboardStats();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取统计数据成功");
response.put("data", stats);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取仪表盘统计数据失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取统计数据失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取用户统计数据
*/
@Operation(summary = "获取用户统计数据")
@GetMapping("/users/stats")
public ResponseEntity<Map<String, Object>> getUserStats() {
try {
Map<String, Object> stats = adminService.getUserStats();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取用户统计数据成功");
response.put("data", stats);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取用户统计数据失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取用户统计数据失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取订单统计数据
*/
@Operation(summary = "获取订单统计数据")
@GetMapping("/orders/stats")
public ResponseEntity<Map<String, Object>> getOrderStats() {
try {
Map<String, Object> stats = adminService.getOrderStats();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取订单统计数据成功");
response.put("data", stats);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取订单统计数据失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取订单统计数据失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取商品统计数据
*/
@Operation(summary = "获取商品统计数据")
@GetMapping("/products/stats")
public ResponseEntity<Map<String, Object>> getProductStats() {
try {
Map<String, Object> stats = adminService.getProductStats();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取商品统计数据成功");
response.put("data", stats);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取商品统计数据失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取商品统计数据失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取秒杀统计数据
*/
@Operation(summary = "获取秒杀统计数据")
@GetMapping("/flashsales/stats")
public ResponseEntity<Map<String, Object>> getFlashSaleStats() {
try {
Map<String, Object> stats = adminService.getFlashSaleStats();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取秒杀统计数据成功");
response.put("data", stats);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取秒杀统计数据失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取秒杀统计数据失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取最近订单列表
*/
@Operation(summary = "获取最近订单列表")
@GetMapping("/orders/recent")
public ResponseEntity<Map<String, Object>> getRecentOrders(@RequestParam(defaultValue = "10") int limit) {
try {
Object orders = adminService.getRecentOrders(limit);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取最近订单成功");
response.put("data", orders);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取最近订单失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取最近订单失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取热门商品列表
*/
@Operation(summary = "获取热门商品列表")
@GetMapping("/products/hot")
public ResponseEntity<Map<String, Object>> getHotProducts(@RequestParam(defaultValue = "5") int limit) {
try {
Object products = adminService.getHotProducts(limit);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取热门商品成功");
response.put("data", products);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取热门商品失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取热门商品失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取用户列表
*/
@Operation(summary = "获取用户列表")
@GetMapping("/users")
public ResponseEntity<Map<String, Object>> getUsers(
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) Integer status) {
try {
Object users = adminService.getUsers(page, size, keyword, status);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取用户列表成功");
response.put("data", users);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取用户列表失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取用户列表失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取订单列表
*/
@Operation(summary = "获取订单列表")
@GetMapping("/orders")
public ResponseEntity<Map<String, Object>> getOrders(
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) String status) {
try {
Object orders = adminService.getOrders(page, size, keyword, status);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取订单列表成功");
response.put("data", orders);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取订单列表失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取订单列表失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取商品列表
*/
@Operation(summary = "获取商品列表")
@GetMapping("/products")
public ResponseEntity<Map<String, Object>> getProducts(
@RequestParam(defaultValue = "1") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String keyword,
@RequestParam(required = false) Integer status) {
try {
Object products = adminService.getProducts(page, size, keyword, status);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取商品列表成功");
response.put("data", products);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取商品列表失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取商品列表失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取系统状态
*/
@Operation(summary = "获取系统状态")
@GetMapping("/monitor/system")
public ResponseEntity<Map<String, Object>> getSystemStatus() {
try {
Object systemStatus = adminService.getSystemStatus();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取系统状态成功");
response.put("data", systemStatus);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取系统状态失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取系统状态失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取Redis状态
*/
@Operation(summary = "获取Redis状态")
@GetMapping("/monitor/redis")
public ResponseEntity<Map<String, Object>> getRedisStatus() {
try {
Object redisStatus = adminService.getRedisStatus();
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取Redis状态成功");
response.put("data", redisStatus);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取Redis状态失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取Redis状态失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 获取单个商品详情
*/
@Operation(summary = "获取商品详情")
@GetMapping("/products/{id}")
public ResponseEntity<Map<String, Object>> getProduct(@PathVariable Long id) {
try {
Object product = adminService.getProduct(id);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "获取商品详情成功");
response.put("data", product);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("获取商品详情失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "获取商品详情失败");
return ResponseEntity.badRequest().body(response);
}
}
/**
* 更新商品
*/
@Operation(summary = "更新商品")
@PutMapping("/products/{id}")
public ResponseEntity<Map<String, Object>> updateProduct(@PathVariable Long id,
@RequestBody Map<String, Object> productData) {
try {
adminService.updateProduct(id, productData);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "商品更新成功");
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("更新商品失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "更新商品失败: " + e.getMessage());
return ResponseEntity.badRequest().body(response);
}
}
/**
* 删除商品
*/
@Operation(summary = "删除商品")
@DeleteMapping("/products/{id}")
public ResponseEntity<Map<String, Object>> deleteProduct(@PathVariable Long id) {
try {
adminService.deleteProduct(id);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "商品删除成功");
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("删除商品失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "删除商品失败: " + e.getMessage());
return ResponseEntity.badRequest().body(response);
}
}
/**
* 添加商品
*/
@Operation(summary = "添加商品")
@PostMapping("/products")
public ResponseEntity<Map<String, Object>> addProduct(@RequestBody Map<String, Object> productData) {
try {
Object product = adminService.addProduct(productData);
Map<String, Object> response = new HashMap<>();
response.put("success", true);
response.put("message", "商品添加成功");
response.put("data", product);
return ResponseEntity.ok(response);
} catch (Exception e) {
log.error("添加商品失败", e);
Map<String, Object> response = new HashMap<>();
response.put("success", false);
response.put("message", "添加商品失败: " + e.getMessage());
return ResponseEntity.badRequest().body(response);
}
}
}