|
|
@@ -0,0 +1,100 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.dto.ProductDTO;
|
|
|
+import com.etotem.cfc.entity.Product;
|
|
|
+import com.etotem.cfc.service.ProductService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 管理端-商品管理控制器
|
|
|
+ */
|
|
|
+@Tag(name = "管理端-商品管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/product")
|
|
|
+public class AdminProductController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
+ @Operation(summary = "商品列表")
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params) {
|
|
|
+ String status = (String) params.get("status");
|
|
|
+ String productType = (String) params.get("productType");
|
|
|
+ Integer page = params.get("page") != null ? ((Number) params.get("page")).intValue() : 1;
|
|
|
+ Integer size = params.get("size") != null ? ((Number) params.get("size")).intValue() : 20;
|
|
|
+
|
|
|
+ Page<Product> pageParam = new Page<>(page, size);
|
|
|
+ LambdaQueryWrapper<Product> wrapper = new LambdaQueryWrapper<Product>()
|
|
|
+ .orderByDesc(Product::getCreatedAt);
|
|
|
+
|
|
|
+ if (status != null && !status.isEmpty()) {
|
|
|
+ wrapper.eq(Product::getStatus, status);
|
|
|
+ }
|
|
|
+ if (productType != null && !productType.isEmpty()) {
|
|
|
+ wrapper.eq(Product::getProductType, productType);
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<Product> result = productService.adminProductList(pageParam, wrapper);
|
|
|
+ List<ProductDTO> records = result.getRecords().stream()
|
|
|
+ .map(ProductDTO::from)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("records", records);
|
|
|
+ data.put("total", result.getTotal());
|
|
|
+ data.put("page", result.getCurrent());
|
|
|
+ data.put("size", result.getSize());
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "审核商品")
|
|
|
+ @PostMapping("/review")
|
|
|
+ public Result<String> review(@RequestBody Map<String, Object> params) {
|
|
|
+ Long productId = params.get("productId") != null
|
|
|
+ ? Long.valueOf(params.get("productId").toString())
|
|
|
+ : null;
|
|
|
+ String action = (String) params.get("action");
|
|
|
+ String reason = (String) params.get("reason");
|
|
|
+
|
|
|
+ if (productId == null) {
|
|
|
+ return Result.error("productId不能为空");
|
|
|
+ }
|
|
|
+ if (action == null || (!"approve".equals(action) && !"reject".equals(action))) {
|
|
|
+ return Result.error("action必须为 approve 或 reject");
|
|
|
+ }
|
|
|
+
|
|
|
+ return productService.review(productId, action, reason);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "商品上下架")
|
|
|
+ @PostMapping("/shelve")
|
|
|
+ public Result<String> shelve(@RequestBody Map<String, Object> params) {
|
|
|
+ Long productId = params.get("productId") != null
|
|
|
+ ? Long.valueOf(params.get("productId").toString())
|
|
|
+ : null;
|
|
|
+ Boolean shelve = params.get("shelve") != null
|
|
|
+ ? (Boolean) params.get("shelve")
|
|
|
+ : null;
|
|
|
+
|
|
|
+ if (productId == null) {
|
|
|
+ return Result.error("productId不能为空");
|
|
|
+ }
|
|
|
+ if (shelve == null) {
|
|
|
+ return Result.error("shelve不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ return productService.adminShelve(productId, shelve);
|
|
|
+ }
|
|
|
+}
|