From c3b81ea987501dc2f5dc3c8db23038eeb8f290e9 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 12 三月 2026 17:56:16 +0800
Subject: [PATCH] fix: 产品保存时唯一性导致数据丢失

---
 src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+), 0 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 8a1099c..15a2d3c 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductOrderServiceImpl.java
@@ -15,10 +15,15 @@
 import com.ruoyi.production.mapper.*;
 import com.ruoyi.production.pojo.*;
 import com.ruoyi.production.service.ProductOrderService;
+import com.ruoyi.productionPlan.mapper.ProductOrderPlanMapper;
+import com.ruoyi.productionPlan.mapper.ProductionPlanMapper;
+import com.ruoyi.productionPlan.pojo.ProductOrderPlan;
+import com.ruoyi.productionPlan.pojo.ProductionPlan;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
 import com.ruoyi.quality.pojo.QualityInspect;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -49,6 +54,12 @@
 
     @Autowired
     private ProductionProductMainMapper productionProductMainMapper;
+
+    @Autowired
+    private ProductOrderPlanMapper productOrderPlanMapper;
+
+    @Autowired
+    private ProductionPlanMapper productionPlanMapper;
 
     @Autowired
     private ProductionProductOutputMapper productionProductOutputMapper;
@@ -123,6 +134,29 @@
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean revoke(ProductOrder productOrder) {
+        // todo 鍒ゆ柇鏄惁浜х敓鎶ュ伐淇℃伅
+
+        // 鏌ヨ鍚堝苟鐨勭敓浜ц鍒�
+        List<ProductOrderPlan> productOrderPlans = productOrderPlanMapper.selectList(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId()));
+        if (productOrderPlans.isEmpty()) {
+            throw new RuntimeException("鍚堝苟鐨勭敓浜ц鍒掍笉瀛樺湪");
+        }
+        for (ProductOrderPlan productOrderPlan : productOrderPlans) {
+            ProductionPlan productionPlan = productionPlanMapper.selectById(productOrderPlan.getProductionPlanId());
+            productionPlan.setAssignedQuantity(productionPlan.getAssignedQuantity().subtract(productOrderPlan.getAssignedQuantity()));
+            productionPlanMapper.updateById(productionPlan);
+        }
+        // 鍒犻櫎鍏宠仈鍏崇郴
+        productOrderPlanMapper.delete(Wrappers.<ProductOrderPlan>lambdaQuery().in(ProductOrderPlan::getProductOrderId, productOrder.getId()));
+        // 鍒犻櫎璁㈠崟
+        productOrderMapper.deleteById(productOrder.getId());
+        // todo 鍒犻櫎璁㈠崟涓嬬殑宸ヨ壓璺嚎瀛愯〃
+        return null;
+    }
+
+    @Override
     public List<ProcessRoute> listProcessRoute(Long productModelId) {
         return productOrderMapper.listProcessRoute(productModelId);
     }

--
Gitblit v1.9.3