From f7b8a02843673c19e21b275d1c54e2a778bfedd4 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期三, 08 四月 2026 11:05:41 +0800
Subject: [PATCH] 相同产品型号的生产订单批号需要唯一

---
 src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java |   29 ++++++++++++++++++++++++-----
 1 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
index 3d694ca..f4609eb 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -24,6 +24,7 @@
 import com.ruoyi.production.service.ProductOrderService;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
 import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.pojo.StockInventory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -160,6 +161,15 @@
 
     @Override
     public Boolean addProductOrder(ProductOrder productOrder) {
+        // 妫�鏌ョ浉鍚屼骇鍝佸瀷鍙峰拰鎵瑰彿鏄惁宸插瓨鍦�
+        if (productOrder.getProductModelId() != null && productOrder.getBatchNo() != null) {
+            LambdaQueryWrapper<ProductOrder> queryWrapper = Wrappers.<ProductOrder>lambdaQuery()
+                    .eq(ProductOrder::getProductModelId, productOrder.getProductModelId())
+                    .eq(ProductOrder::getBatchNo, productOrder.getBatchNo());
+            if (this.count(queryWrapper) > 0) {
+                throw new RuntimeException("鐩稿悓浜у搧鍨嬪彿鍜屾壒鍙风殑鐢熶骇璁㈠崟宸插瓨鍦�");
+            }
+        }
         String string = generateNextOrderNo(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
         productOrder.setNpsNo(string);
         productOrder.setCompleteQuantity(BigDecimal.ZERO);
@@ -247,8 +257,9 @@
 
     @Override
     public List<SelectOptionDTO<String>> getProductOrderBatchNo() {
-        List<ProductOrder> productOrders = productOrderMapper.selectList(null);
-        return productOrders.stream().map(productOrder -> new SelectOptionDTO<>(productOrder.getBatchNo(), productOrder.getBatchNo())).collect(Collectors.toList());
+        //鏌ヨ搴撳瓨鎵瑰彿
+        List<StockInventory> stockInventoryList = stockInventoryMapper.selectList(null);
+        return stockInventoryList.stream().map(stockInventory -> new SelectOptionDTO<>(stockInventory.getBatchNo(), stockInventory.getBatchNo())).collect(Collectors.toList());
     }
 
     @Override
@@ -275,10 +286,12 @@
         }
         // 濡傛灉鏈夋暟鎹厛鍔犲簱瀛�
         ProductOrder productOrder = productOrderMapper.selectById(productOrderDto.getId());
-        if (productOrder != null) {
+        if (productOrder.getDrawMaterials() != null) {
             List<DrawMaterialDto> materialDtoList = JSON.parseArray(productOrder.getDrawMaterials(), DrawMaterialDto.class);
             for (DrawMaterialDto drawMaterialDto : materialDtoList) {
-                stockUtils.addStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(), null, productOrderDto.getId());
+                stockUtils.addStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(), null, productOrderDto.getId(),
+                        drawMaterialDto.getBatchNo(), drawMaterialDto.getCustomer(),drawMaterialDto.getProductionDate()
+                );
             }
         }
 
@@ -288,7 +301,13 @@
                 if (drawMaterialDto.getProductModelId() == null) {
                     throw new RuntimeException("浜у搧鍨嬪彿ID涓嶈兘涓虹┖");
                 }
-                stockUtils.substractStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(), StockOutQualifiedRecordTypeEnum.DRAW_MATERIALS_STOCK_OUT.getCode(), productOrderDto.getId());
+                if (drawMaterialDto.getQualitity() == null  || drawMaterialDto.getQualitity().compareTo(BigDecimal.ZERO) == 0) {
+                    throw new RuntimeException("浜у搧" + drawMaterialDto.getProductName() + "鍨嬪彿" + drawMaterialDto.getModel()
+                     + "鎵瑰彿" + drawMaterialDto.getBatchNo() + "搴撳瓨涓嶈冻锛�");
+                }
+                stockUtils.substractStock(drawMaterialDto.getProductModelId(), drawMaterialDto.getRequisitionQty(),
+                        StockOutQualifiedRecordTypeEnum.DRAW_MATERIALS_STOCK_OUT.getCode(), productOrderDto.getId(),
+                        drawMaterialDto.getBatchNo(),drawMaterialDto.getCustomer());
             }
         } catch (Exception e) {
             throw new RuntimeException("棰嗘枡澶辫触锛�" + e.getMessage());

--
Gitblit v1.9.3