From dc5cb9eb1d29c9c15f21d373378fd39ec0e1ed49 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 01 四月 2026 11:45:46 +0800
Subject: [PATCH] fix: 编辑生产计划数据新增数据判断

---
 src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java |   42 ++++++++++++++++++++++++++++++------------
 1 files changed, 30 insertions(+), 12 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 5702c18..cf217d3 100644
--- a/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
+++ b/src/main/java/com/ruoyi/productionPlan/service/impl/ProductionPlanServiceImpl.java
@@ -148,6 +148,7 @@
         productOrder.setPlanCompleteTime(productionPlanDto.getPlanCompleteTime());
         productOrder.setStatus(ProductOrderStatusEnum.WAIT.getCode());
         productOrder.setStrength(productionPlanDto.getStrength());
+        productOrder.setProductMaterialSkuId(productionPlanDto.getProductMaterialSkuId());
 
         Long orderId = productOrderService.insertProductOrder(productOrder);
 
@@ -181,11 +182,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,17 +192,28 @@
             }
 
             // 鍒嗛厤褰撳墠璁″垝鏂规暟
-            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);
             // 鍒涘缓鍏宠仈鍏崇郴
             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;
     }
@@ -220,9 +230,17 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean update(ProductionPlanDto productionPlanDto) {
+        if (productionPlanDto == null) {
+            throw new ServiceException("缂栬緫澶辫触,鏁版嵁涓嶈兘涓虹┖");
+        }
+        ProductionPlan productionPlan = getById(productionPlanDto.getId());
+        if (productionPlan == null) {
+            throw new ServiceException("缂栬緫澶辫触,涓荤敓浜ц鍒掍笉瀛樺湪");
+        }
+
         // 宸蹭笅鍙戠姸鎬侊紝涓嶈兘缂栬緫
-        if (productionPlanDto.getStatus() != 0) {
-            throw new BaseException("宸蹭笅鍙戞垨閮ㄥ垎涓嬪彂鐘舵�侊紝涓嶈兘缂栬緫");
+        if (productionPlan.getStatus() != 0) {
+            throw new BaseException("缂栬緫澶辫触,璇ョ敓浜ц鍒掑凡涓嬪彂鎴栭儴鍒嗕笅鍙戠姸鎬�,绂佹缂栬緫");
         }
         // 鏌ヨ鏄惁鏈夊叧鑱旇鍗�
         boolean hasProductOrderPlan = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().eq(ProductOrderPlan::getProductionPlanId, productionPlanDto.getId())).stream().anyMatch(p -> p.getProductOrderId() != null);

--
Gitblit v1.9.3