From a4a0e2bd0ddcf0b6c55b701fc52875f3302cbe11 Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期三, 27 五月 2026 19:39:57 +0800
Subject: [PATCH] feat 校验提交修改

---
 src/main/java/com/ruoyi/basic/controller/ProductController.java |   51 ++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/ruoyi/basic/controller/ProductController.java b/src/main/java/com/ruoyi/basic/controller/ProductController.java
index a97bd7b..7ed56c2 100644
--- a/src/main/java/com/ruoyi/basic/controller/ProductController.java
+++ b/src/main/java/com/ruoyi/basic/controller/ProductController.java
@@ -3,12 +3,15 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.common.collect.Lists;
 import com.ruoyi.basic.dto.ProductDto;
 import com.ruoyi.basic.dto.ProductModelDto;
+import com.ruoyi.basic.dto.ProductModelExportDto;
 import com.ruoyi.basic.dto.ProductTreeDto;
 import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.basic.service.IProductModelService;
 import com.ruoyi.basic.service.IProductService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.web.controller.BaseController;
@@ -16,6 +19,8 @@
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.sales.service.ISalesLedgerProductService;
 import com.ruoyi.sales.service.ISalesLedgerService;
+import com.ruoyi.stock.pojo.StockInventory;
+import com.ruoyi.stock.service.StockInventoryService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
@@ -23,7 +28,9 @@
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @RestController
 @AllArgsConstructor
@@ -35,6 +42,9 @@
     private IProductModelService productModelService;
     @Autowired
     private ISalesLedgerProductService salesLedgerProductService;
+    @Autowired
+    private StockInventoryService stockInventoryService;
+
     /**
      * 鏌ヨ浜у搧
      */
@@ -78,13 +88,25 @@
         if (ids == null || ids.length == 0) {
             return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
         }
+        List<ProductModel> productModels = productModelService.selectModelListByProductIds(Lists.newArrayList(ids));
         // 妫�鏌ユ槸鍚︽湁閿�鍞晢鍝佽褰曞叧鑱旇浜у搧
-        LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.in(SalesLedgerProduct::getProductId, ids);
-        List<SalesLedgerProduct> salesLedgerProductList = salesLedgerProductService.list(queryWrapper);
-        if (salesLedgerProductList.size() > 0) {
-            return AjaxResult.error("璇ヤ骇鍝佸瓨鍦ㄩ攢鍞�/閲囪喘璁板綍锛屼笉鑳藉垹闄�");
+        if (!productModels.isEmpty()) {
+            LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.in(SalesLedgerProduct::getProductModelId, productModels.stream().map(ProductModel::getId).collect(Collectors.toList()));
+            List<SalesLedgerProduct> salesLedgerProductList = salesLedgerProductService.list(queryWrapper);
+            if (!salesLedgerProductList.isEmpty()) {
+                return AjaxResult.error("璇ヤ骇鍝佸瓨鍦ㄩ攢鍞�/閲囪喘璁板綍锛屼笉鑳藉垹闄�");
+            }
+            LambdaQueryWrapper<StockInventory> inventoryLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            inventoryLambdaQueryWrapper.in(StockInventory::getProductModelId, productModels.stream().map(ProductModel::getId).collect(Collectors.toList()));
+
+            List<StockInventory> list = stockInventoryService.list(inventoryLambdaQueryWrapper);
+            if (!list.isEmpty()) {
+                return AjaxResult.error("璇ヤ骇鍝佸瓨鍦ㄥ簱瀛樿褰曪紝涓嶈兘鍒犻櫎");
+            }
+            productModelService.removeBatchByIds(productModels);
         }
+
         return toAjax(productService.delProductByIds(ids));
     }
 
@@ -124,9 +146,20 @@
     /**
      * 瀵煎叆浜у搧
      */
-    @Log(title = "瀵煎叆浜у搧",businessType = BusinessType.IMPORT)
-    @PostMapping("import")
-    public AjaxResult importProduct(MultipartFile file) {
-        return AjaxResult.success(productModelService.importProduct(file));
+    @PostMapping("/import")
+    @Log(title = "瀵煎叆浜у搧", businessType = BusinessType.IMPORT)
+    public AjaxResult importProductModel(@RequestParam("file") MultipartFile file, Integer productId) {
+        return productModelService.importProductModel(file, productId);
+    }
+
+    /**
+     * 浜у搧瀵煎叆妯℃澘
+     */
+    @GetMapping("/export")
+    @ApiOperation("浜у搧瀵煎叆妯℃澘")
+    @Log(title = "浜у搧瀵煎叆妯℃澘", businessType = BusinessType.EXPORT)
+    public void importProduct(HttpServletResponse response) {
+        ExcelUtil<ProductModelExportDto> excelUtil = new ExcelUtil<>(ProductModelExportDto.class);
+        excelUtil.importTemplateExcel(response, "浜у搧瑙勬牸瀵煎叆妯℃澘");
     }
 }

--
Gitblit v1.9.3