Просмотр исходного кода

chore: auto bump version and changelog [skip ci]

Xiaogang Liao 2 месяцев назад
Родитель
Сommit
9ec606eaeb

+ 4 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/AdminProductController.java

@@ -50,6 +50,10 @@ public class AdminProductController {
         if (keyword != null && !keyword.isEmpty()) {
         if (keyword != null && !keyword.isEmpty()) {
             wrapper.like(Product::getName, keyword);
             wrapper.like(Product::getName, keyword);
         }
         }
+        if (params.get("distributionSystemId") != null) {
+            wrapper.eq(Product::getDistributionSystemId,
+                    Long.valueOf(params.get("distributionSystemId").toString()));
+        }
 
 
         Page<Product> result = productService.adminProductList(pageParam, wrapper);
         Page<Product> result = productService.adminProductList(pageParam, wrapper);
         List<ProductDTO> records = result.getRecords().stream()
         List<ProductDTO> records = result.getRecords().stream()

+ 223 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/SupplierProductController.java

@@ -0,0 +1,223 @@
+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.ProductCreateRequest;
+import com.etotem.cfc.dto.ProductDTO;
+import com.etotem.cfc.entity.Product;
+import com.etotem.cfc.entity.SupplySystem;
+import com.etotem.cfc.service.ProductService;
+import com.etotem.cfc.service.SupplySystemService;
+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/supplier/product")
+public class SupplierProductController {
+
+    @Resource
+    private SupplySystemService supplySystemService;
+
+    @Resource
+    private ProductService productService;
+
+    /**
+     * 获取当前供应商管理员所属的供应体系
+     */
+    private SupplySystem getMySystem(Long userId) {
+        return supplySystemService.getByAdminId(userId);
+    }
+
+    @Operation(summary = "供应商商品列表")
+    @PostMapping("/list")
+    public Result<Map<String, Object>> list(@RequestBody Map<String, Object> params,
+                                            @RequestAttribute("userId") Long adminId) {
+        SupplySystem system = getMySystem(adminId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+
+        String status = (String) params.get("status");
+        String keyword = (String) params.get("keyword");
+        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>()
+                .eq(Product::getDistributionSystemId, system.getId())
+                .orderByDesc(Product::getCreatedAt);
+
+        if (status != null && !status.isEmpty()) {
+            wrapper.eq(Product::getStatus, status);
+        }
+        if (keyword != null && !keyword.isEmpty()) {
+            wrapper.like(Product::getName, keyword);
+        }
+
+        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("/create")
+    public Result<ProductDTO> create(@RequestBody ProductCreateRequest request,
+                                     @RequestAttribute("userId") Long adminId) {
+        SupplySystem system = getMySystem(adminId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+
+        Product product = request.getProduct();
+        if (product == null || product.getName() == null || product.getName().isEmpty()) {
+            return Result.error("商品名称不能为空");
+        }
+
+        // 自动绑定到供应商的体系
+        product.setDistributionSystemId(system.getId());
+        product.setVendorName(system.getName());
+
+        return productService.adminCreate(product, request.getAssessmentExt());
+    }
+
+    @Operation(summary = "供应商更新商品")
+    @PostMapping("/update")
+    public Result<ProductDTO> update(@RequestBody ProductCreateRequest request,
+                                     @RequestAttribute("userId") Long adminId) {
+        SupplySystem system = getMySystem(adminId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+
+        Product product = request.getProduct();
+        if (product == null || product.getId() == null) {
+            return Result.error("商品ID不能为空");
+        }
+
+        // 校验商品是否属于该供应商的体系
+        Product existing = productService.getById(product.getId());
+        if (existing == null) {
+            return Result.error("商品不存在");
+        }
+        if (!system.getId().equals(existing.getDistributionSystemId())) {
+            return Result.error("无权操作该商品");
+        }
+
+        // 不允许修改 distributionSystemId
+        product.setDistributionSystemId(system.getId());
+
+        return productService.adminUpdate(product, request.getAssessmentExt());
+    }
+
+    @Operation(summary = "供应商商品详情")
+    @PostMapping("/detail")
+    public Result<ProductDTO> detail(@RequestBody Map<String, Object> params,
+                                     @RequestAttribute("userId") Long adminId) {
+        SupplySystem system = getMySystem(adminId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+
+        Long productId = params.get("productId") != null
+                ? Long.valueOf(params.get("productId").toString())
+                : null;
+        if (productId == null) {
+            return Result.error("productId不能为空");
+        }
+
+        // 校验商品是否属于该供应商的体系
+        Product existing = productService.getById(productId);
+        if (existing == null) {
+            return Result.error("商品不存在");
+        }
+        if (!system.getId().equals(existing.getDistributionSystemId())) {
+            return Result.error("无权查看该商品");
+        }
+
+        return productService.adminDetail(productId);
+    }
+
+    @Operation(summary = "供应商删除商品")
+    @PostMapping("/delete")
+    public Result<String> delete(@RequestBody Map<String, Object> params,
+                                 @RequestAttribute("userId") Long adminId) {
+        SupplySystem system = getMySystem(adminId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+
+        Long productId = params.get("productId") != null
+                ? Long.valueOf(params.get("productId").toString())
+                : null;
+        if (productId == null) {
+            return Result.error("productId不能为空");
+        }
+
+        // 校验商品是否属于该供应商的体系
+        Product existing = productService.getById(productId);
+        if (existing == null) {
+            return Result.error("商品不存在");
+        }
+        if (!system.getId().equals(existing.getDistributionSystemId())) {
+            return Result.error("无权操作该商品");
+        }
+
+        return productService.adminDelete(productId);
+    }
+
+    @Operation(summary = "供应商上下架商品")
+    @PostMapping("/shelve")
+    public Result<String> shelve(@RequestBody Map<String, Object> params,
+                                 @RequestAttribute("userId") Long adminId) {
+        SupplySystem system = getMySystem(adminId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+
+        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不能为空");
+        }
+
+        // 校验商品是否属于该供应商的体系
+        Product existing = productService.getById(productId);
+        if (existing == null) {
+            return Result.error("商品不存在");
+        }
+        if (!system.getId().equals(existing.getDistributionSystemId())) {
+            return Result.error("无权操作该商品");
+        }
+
+        return productService.adminShelve(productId, shelve);
+    }
+}

+ 9 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/admin/SupplySystemController.java

@@ -56,6 +56,15 @@ public class SupplySystemController {
         return Result.success(supplySystemService.listAll());
         return Result.success(supplySystemService.listAll());
     }
     }
 
 
+    @PostMapping("/my-system")
+    public Result<SupplySystem> getMySystem(@RequestAttribute("userId") Long userId) {
+        SupplySystem system = supplySystemService.getByAdminId(userId);
+        if (system == null) {
+            return Result.error("您没有关联的供应商体系");
+        }
+        return Result.success(system);
+    }
+
     // ========== Member Management ==========
     // ========== Member Management ==========
 
 
     @PostMapping("/member/list")
     @PostMapping("/member/list")

+ 8 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/SupplySystemService.java

@@ -83,6 +83,14 @@ public class SupplySystemService extends ServiceImpl<SupplySystemMapper, SupplyS
         return this.list(wrapper);
         return this.list(wrapper);
     }
     }
 
 
+    public SupplySystem getByAdminId(Long adminId) {
+        LambdaQueryWrapper<SupplySystem> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(SupplySystem::getAdminId, adminId)
+               .eq(SupplySystem::getStatus, "active")
+               .last("LIMIT 1");
+        return this.getOne(wrapper);
+    }
+
     // ========== Member Management ==========
     // ========== Member Management ==========
 
 
     public List<SupplySystemMember> memberList(Long systemId) {
     public List<SupplySystemMember> memberList(Long systemId) {