From 659c74e7aaf751cc10ac47b7e0939f235a17d873 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期六, 06 九月 2025 10:12:01 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/org/jeecg/modules/cms/service/impl/CuttingInboundServiceImpl.java |  134 +++++++++++++++++++++++++++++++++-----------
 1 files changed, 101 insertions(+), 33 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/cms/service/impl/CuttingInboundServiceImpl.java b/src/main/java/org/jeecg/modules/cms/service/impl/CuttingInboundServiceImpl.java
index 991f67f..17ded30 100644
--- a/src/main/java/org/jeecg/modules/cms/service/impl/CuttingInboundServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/cms/service/impl/CuttingInboundServiceImpl.java
@@ -1,17 +1,25 @@
 package org.jeecg.modules.cms.service.impl;
 
+import io.micrometer.core.annotation.Timed;
+import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.cms.entity.CuttingInbound;
 import org.jeecg.modules.cms.entity.CuttingInboundDetail;
+import org.jeecg.modules.cms.entity.CuttingInboundInventory;
+import org.jeecg.modules.cms.entity.CuttingInventory;
 import org.jeecg.modules.cms.mapper.CuttingInboundMapper;
+import org.jeecg.modules.cms.service.ICuttingInboundInventoryService;
 import org.jeecg.modules.cms.service.ICuttingInboundService;
 import org.jeecg.modules.cms.service.ICuttingInboundDetailService;
+import org.jeecg.modules.cms.service.ICuttingInventoryService;
 import org.jeecg.modules.cms.vo.CuttingInboundExportVo;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,10 +30,18 @@
  * @Date:   2025-07-28
  * @Version: V1.0
  */
+
+@Slf4j
 @Service
 public class CuttingInboundServiceImpl extends ServiceImpl<CuttingInboundMapper, CuttingInbound> implements ICuttingInboundService {
     @Autowired
     private ICuttingInboundDetailService cuttingInboundDetailService; // 娉ㄥ叆浠庤〃鏈嶅姟
+
+    @Autowired
+    private ICuttingInventoryService cuttingInventoryService;
+
+    @Autowired
+    private ICuttingInboundInventoryService cuttingInboundInventoryService;
     /**
      * 閫氳繃Excel瀵煎叆鍒�鍏峰叆搴撳崟鏁版嵁
      *
@@ -35,39 +51,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Result<?> importExcelData(List<CuttingInboundExportVo> list) {
-//        try {
-//            for (CuttingInboundExportVo exportVo : list) {
-//                // 淇濆瓨涓昏〃鏁版嵁
-//                CuttingInbound cuttingInbound = new CuttingInbound();
-//                cuttingInbound.setReceiver(exportVo.getReceiver());
-//                cuttingInbound.setReceiveTime(exportVo.getReceiveTime());
-//                cuttingInbound.setReceiveComment(exportVo.getReceiveComment());
-//                cuttingInbound.setConfirmer(exportVo.getConfirmer());
-//                cuttingInbound.setConfirmTime(exportVo.getConfirmTime());
-//                cuttingInbound.setConfirmComment(exportVo.getConfirmComment());
-//                cuttingInbound.setOrderStatus(exportVo.getOrderStatus());
-//
-//                // 淇濆瓨涓昏〃鏁版嵁浠ヨ幏鍙朓D
-//                this.save(cuttingInbound);
-//
-//                // 鑾峰彇涓昏〃ID
-//                String orderId = cuttingInbound.getId();
-//
-//                // 澶勭悊浠庤〃鏁版嵁
-//                List<CuttingInboundDetail> detailList = exportVo.getDetailList();
-//                if (detailList != null && !detailList.isEmpty()) {
-//                    for (CuttingInboundDetail detail : detailList) {
-//                        detail.setOrderId(orderId); // 璁剧疆澶栭敭鍏宠仈
-//                        cuttingInboundDetailService.save(detail);
-//                    }
-//                }
-//            }
-//            return Result.ok("瀵煎叆鎴愬姛");
-//        } catch (Exception e) {
-//            log.error("瀵煎叆澶辫触", e);
-//            return Result.error("瀵煎叆澶辫触: " + e.getMessage());
-//        }
-//    }
+
         for (CuttingInboundExportVo exportVo : list) {
             // 淇濆瓨涓昏〃鏁版嵁
             CuttingInbound cuttingInbound = new CuttingInbound();
@@ -96,4 +80,88 @@
         }
         return Result.ok("瀵煎叆鎴愬姛");
     }
+
+
+    /*
+     * 鐢熸垚鍞竴鏉$爜鐨勬柟娉曪紙纭畾缂栫爜鐢熸垚瑙勫垯鍚庡湪姝ゅ閲嶅啓锛�
+     */
+    private String generateUniqueBarcode(String cuttingId, int index) {
+        // 鏉$爜鐢熸垚瑙勫垯绀轰緥锛氬垁鍏稩D + 搴忓彿(4浣�) + 闅忔満鏁�
+        return cuttingId + String.format("%04d", index + 1) + (int) (Math.random() * 10000);
+    }
+    @Override
+    @Timed(value = "cutting.inbound.submit", description = "鍒�鍏峰叆搴撴彁浜よ�楁椂")
+    public synchronized Result<?> submit(String orderId) {
+        long startTime = System.currentTimeMillis();
+        try {
+            // 1. 鏇存柊鍏ュ簱鍗曠姸鎬�
+            CuttingInbound cuttingInbound = this.getById(orderId);
+            if (cuttingInbound == null) {
+                return Result.error("鏈壘鍒板搴旂殑鍏ュ簱鍗�");
+            }
+
+            // 妫�鏌ュ叆搴撳崟鐘舵�侊紝鍙厑璁哥姸鎬佷负"1"鐨勫叆搴撳崟鎻愪氦
+            if (!"1".equals(cuttingInbound.getOrderStatus())) {
+                return Result.error("鍙湁鐘舵�佷负鏈彁浜ょ殑鍏ュ簱鍗曟墠鑳芥墽琛屾彁浜ゆ搷浣�");
+            }
+
+            cuttingInbound.setOrderStatus("2");
+            boolean updateResult = this.updateById(cuttingInbound);
+            if (!updateResult) {
+                return Result.error("鏇存柊鍏ュ簱鍗曠姸鎬佸け璐ワ紝鍙兘宸茶鍏朵粬鐢ㄦ埛澶勭悊");
+            }
+
+            // 2. 鑾峰彇鍏ュ簱鏄庣粏
+            List<CuttingInboundDetail> detailList = cuttingInboundDetailService.lambdaQuery()
+                    .eq(CuttingInboundDetail::getOrderId, orderId)
+                    .list();
+
+            // 3. 鏀堕泦鎵�鏈夐渶瑕佷繚瀛樼殑鏁版嵁
+            List<CuttingInventory> inventoryList = new ArrayList<>();
+            List<CuttingInboundInventory> inboundInventoryList = new ArrayList<>();
+
+            for (CuttingInboundDetail detail : detailList) {
+                int quantity = detail.getReceiveNumber() != null ? detail.getReceiveNumber().intValue() : 0;
+
+                for (int i = 0; i < quantity; i++) {
+                    // 鐢熸垚搴撳瓨璁板綍
+                    CuttingInventory cuttingInventory = new CuttingInventory();
+                    cuttingInventory.setCuttingId(detail.getCuttingId());
+                    cuttingInventory.setCuttingBarcode(generateUniqueBarcode(detail.getCuttingId(), i));
+                    cuttingInventory.setInventoryStatus("姝e父");
+                    cuttingInventory.setCurrentLife(BigDecimal.valueOf(100));
+                    inventoryList.add(cuttingInventory);
+                }
+            }
+
+            // 4. 鎵归噺淇濆瓨搴撳瓨璁板綍锛堜竴娆℃�ф搷浣滐級
+            if (!inventoryList.isEmpty()) {
+                cuttingInventoryService.saveBatch(inventoryList);
+
+                // 5. 涓烘瘡涓繚瀛樼殑搴撳瓨璁板綍鍒涘缓鍏宠仈鍏崇郴
+                for (CuttingInventory inventory : inventoryList) {
+                    CuttingInboundInventory cuttingInboundInventory = new CuttingInboundInventory();
+                    cuttingInboundInventory.setOrderId(orderId);
+                    cuttingInboundInventory.setInventoryId(inventory.getId());
+                    inboundInventoryList.add(cuttingInboundInventory);
+                }
+
+                // 6. 鎵归噺淇濆瓨鍏宠仈鍏崇郴锛堜竴娆℃�ф搷浣滐級
+                cuttingInboundInventoryService.saveBatch(inboundInventoryList);
+            }
+
+            long endTime = System.currentTimeMillis();
+            log.info("鍒�鍏峰叆搴撴彁浜ゅ畬鎴愶紝鑰楁椂: {} ms", (endTime - startTime));
+            return Result.ok("鎻愪氦鎴愬姛");
+
+        } catch (Exception e) {
+            long endTime = System.currentTimeMillis();
+            log.error("鎻愪氦鍏ュ簱鍗曞け璐ワ紝orderId: " + orderId + "锛岃�楁椂: " + (endTime - startTime) + " ms", e);
+            return Result.error("鎻愪氦澶辫触: " + e.getMessage());
+        }
+    }
+
+
+
+
 }

--
Gitblit v1.9.3