From 7d467bd6bfad406c178fa009cf5b20533433e5ed Mon Sep 17 00:00:00 2001
From: dubin <bindu_bean@163.com>
Date: 星期三, 19 十一月 2025 09:30:36 +0800
Subject: [PATCH] 商品档案excel导入;报废物料与托盘解绑

---
 src/main/java/com/zy/asrs/utils/MatExcelListener.java |   40 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/asrs/utils/MatExcelListener.java b/src/main/java/com/zy/asrs/utils/MatExcelListener.java
index a3858b4..081e136 100644
--- a/src/main/java/com/zy/asrs/utils/MatExcelListener.java
+++ b/src/main/java/com/zy/asrs/utils/MatExcelListener.java
@@ -5,9 +5,13 @@
 import com.core.common.Cools;
 import com.core.common.SpringUtils;
 import com.core.exception.CoolException;
+import com.zy.asrs.entity.InOut;
 import com.zy.asrs.entity.Mat;
+import com.zy.asrs.entity.MatBarcode;
 import com.zy.asrs.entity.Tag;
 import com.zy.asrs.mapper.TagMapper;
+import com.zy.asrs.service.InOutService;
+import com.zy.asrs.service.MatBarcodeService;
 import com.zy.asrs.service.MatService;
 import com.zy.asrs.service.TagService;
 import com.zy.common.entity.MatExcel;
@@ -57,6 +61,8 @@
         TagService tagService = SpringUtils.getBean(TagService.class);
         TagMapper tagMapper = SpringUtils.getBean(TagMapper.class);
         MatService matService = SpringUtils.getBean(MatService.class);
+        InOutService inOutService = SpringUtils.getBean(InOutService.class);
+        MatBarcodeService matBarcodeService = SpringUtils.getBean(MatBarcodeService.class);
         Date now = new Date();
         Long tagId;
         // 鍒嗙被
@@ -127,15 +133,43 @@
             tagId = tagService.getTop().getId();
         }
         // 鍟嗗搧
-        Mat mat = matService.selectByMatnr(excel.getMatnr());
+        Mat mat = matService.selectByMatnr(excel.getMatnr() + "__" + excel.getName());
         if (mat == null) {
+            InOut inOut=new InOut();
+            mat = excel;
+            mat.setTagId(tagId);
+            mat.setMatnr(excel.getMatnr()+"__"+excel.getName());
+            inOut.setMatnr(mat.getMatnr());
+            inOut.setMaktx(mat.getMaktx());
+            inOut.setColor(mat.getColor());
+            inOut.setSpecs(mat.getSpecs());
+            inOut.setTemp1("");
+            if (!matService.insert(mat)) {
+                throw new CoolException("淇濆瓨鍟嗗搧妗f澶辫触锛屽晢鍝佺紪鐮侊細" + excel.getMatnr());
+            }
+            if (!inOutService.insert(inOut)){
+                throw new CoolException("淇濆瓨鍟嗗搧淇℃伅澶辫触锛屽晢鍝佺紪鐮侊細" + excel.getMatnr());
+            }
+            total++;
+        } else {
+            if (excel.getColor().equals("鎶ュ簾")){
+                //妯″叿鐘舵�佹洿鏂颁负鎶ュ簾 妯″叿涓庢墭鐩樿В缁�
+                List<MatBarcode> list = new ArrayList<>();
+                MatBarcode matBarcode = matBarcodeService.selectbyMatnr(excel.getMatnr() + "__" + excel.getName());
+                if (matBarcode != null){
+                    list.add(matBarcode);
+                    matBarcodeService.deleteMatBarcode(list);
+                }
+
+            }
+            //妯″叿淇℃伅鏇存柊
+            matService.deleteById(mat.getId());
             mat = excel;
             mat.setTagId(tagId);
             mat.setMatnr(excel.getMatnr()+"__"+excel.getName());
             if (!matService.insert(mat)) {
-                throw new CoolException("淇濆瓨鍟嗗搧淇℃伅澶辫触锛屽晢鍝佺紪鐮侊細" + excel.getMatnr());
+                throw new CoolException("淇濆瓨鍟嗗搧妗f澶辫触锛屽晢鍝佺紪鐮侊細" + excel.getMatnr());
             }
-            total++;
         }
     }
 

--
Gitblit v1.9.1