From cd079ba388c160caa8c9836b9bf16fd25a589909 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 20 三月 2026 15:56:05 +0800
Subject: [PATCH] fix: 和并下发状态未修改

---
 src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
index 3cd448b..9fccff8 100644
--- a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -7,7 +7,6 @@
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.appendix.service.AppendixService;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.StringUtils;
@@ -18,6 +17,7 @@
 import com.ruoyi.production.enums.ProductOrderStatusEnum;
 import com.ruoyi.production.pojo.ProductMaterialSku;
 import com.ruoyi.production.pojo.ProductOrder;
+import com.ruoyi.production.service.IProductionOrderAppendixService;
 import com.ruoyi.production.service.ProductMaterialService;
 import com.ruoyi.production.service.ProductMaterialSkuService;
 import com.ruoyi.production.service.ProductOrderService;
@@ -79,7 +79,7 @@
     private ProductMaterialService productMaterialService;
 
     @Autowired
-    private AppendixService appendixService;
+    private IProductionOrderAppendixService productionOrderAppendixService;
 
     /**
      * 鍚屾閿侊紝纭繚鎵嬪姩鍜屽畾鏃朵换鍔′笉鍚屾椂鎵ц
@@ -153,10 +153,10 @@
 
         //  褰撲笅鍙戠殑浜у搧涓虹爩鍧楁垨鏉挎潗锛屽氨鎷夊彇BOM瀛愰泦涓庡伐鑹鸿矾绾垮瓙闆嗘暟鎹瓨鍏ュ埌闄勮〃涓�
         if ("鐮屽潡".equals(productionPlanDto.getProductName())) {
-            productOrder.setRouteId(appendixService.populateBlocks(orderId, productionPlanDto));
+            productOrder.setRouteId(productionOrderAppendixService.populateBlocks(orderId, productionPlanDto));
         }
         if ("鏉挎潗".equals(productionPlanDto.getProductName())) {
-            productOrder.setRouteId(appendixService.populatePlates(orderId, productionPlanDto));
+            productOrder.setRouteId(productionOrderAppendixService.populatePlates(orderId, productionPlanDto));
         }
         //  鏇存柊缁戝畾鐨勫伐鑹鸿矾绾�
         productOrderService.updateById(productOrder);
@@ -181,11 +181,9 @@
             if (assignedVolume.add(remainingVolume).compareTo(productionPlanDto.getTotalAssignedQuantity()) >= 0) {
                 // 鏈�鍚庝竴涓鍒掞紝鍒嗛厤鍓╀綑鏂规暟
                 BigDecimal lastRemainingVolume = productionPlanDto.getTotalAssignedQuantity().subtract(assignedVolume);
-                plan.setStatus(1);
-                plan.setAssignedQuantity(plan.getAssignedQuantity().add(lastRemainingVolume));
-                if (plan.getAssignedQuantity().compareTo(plan.getVolume()) >= 0) {
-                    plan.setStatus(2);
-                }
+                BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(lastRemainingVolume);
+                plan.setAssignedQuantity(assignedQuantity);
+                plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1);
                 productOrderPlan.setAssignedQuantity(lastRemainingVolume);
                 productionPlanMapper.updateById(plan);
                 productOrderPlanMapper.insert(productOrderPlan);
@@ -193,11 +191,9 @@
             }
 
             // 鍒嗛厤褰撳墠璁″垝鏂规暟
-            plan.setStatus(1);
-            if (remainingVolume.compareTo(BigDecimal.ZERO) <= 0) {
-                plan.setStatus(2);
-            }
-            plan.setAssignedQuantity(plan.getAssignedQuantity().add(remainingVolume));
+            BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO).add(remainingVolume);
+            plan.setAssignedQuantity(assignedQuantity);
+            plan.setStatus(assignedQuantity.compareTo(plan.getVolume()) >= 0 ? 2 : 1);
             productOrderPlan.setAssignedQuantity(remainingVolume);
             // 鏇存柊鐢熶骇璁″垝
             productionPlanMapper.updateById(plan);
@@ -205,6 +201,19 @@
             productOrderPlanMapper.insert(productOrderPlan);
             assignedVolume = assignedVolume.add(remainingVolume);
         }
+
+        for (ProductionPlan plan : plans) {
+            BigDecimal assignedQuantity = Optional.ofNullable(plan.getAssignedQuantity()).orElse(BigDecimal.ZERO);
+            BigDecimal volume = Optional.ofNullable(plan.getVolume()).orElse(BigDecimal.ZERO);
+            if (assignedQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+                plan.setStatus(0);
+            } else if (assignedQuantity.compareTo(volume) >= 0) {
+                plan.setStatus(2);
+            } else {
+                plan.setStatus(1);
+            }
+            productionPlanMapper.updateById(plan);
+        }
         return true;
     }
 

--
Gitblit v1.9.3