From b0409a8bac61d91d6db8755b15d4e2b9c4e3973c Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 05 六月 2025 15:56:11 +0800
Subject: [PATCH] 出库单取消功能优化

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java |   42 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
index 0137b40..70e07a5 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
@@ -52,6 +52,10 @@
     private WaveService waveService;
     @Autowired
     private WaveItemService waveItemService;
+    @Autowired
+    private OutStockItemService outStockItemService;
+    @Autowired
+    private OutStockService outStockService;
 
 
     /**
@@ -102,14 +106,44 @@
         if (Objects.isNull(order)) {
             throw new CoolException("鍗曟嵁涓嶅瓨鍦紒锛�");
         }
-        if (!order.getExceStatus().equals(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val)) {
+        if (!order.getExceStatus().equals(AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val)) {
             throw new CoolException("褰撳墠鍗曟嵁鐘舵�佷负" + AsnExceStatus.getExceStatus(order.getExceStatus()) + "锛� 涓嶅彲鎵ц鍙栨秷鎿嶄綔锛侊紒");
         }
-        order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_TASK_CANCEL.val).setStatus(0);
 
-        if (!this.saveOrUpdate(order)) {
-            throw new CoolException("鍗曟嵁鍙栨秷澶辫触锛侊紒");
+        List<AsnOrderItem> orderItems = outStockItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, id));
+        if (!orderItems.isEmpty()) {
+            for (AsnOrderItem orderItem : orderItems) {
+                if (!Objects.isNull(orderItem.getPoDetlId())) {
+                    DeliveryItem deliveryItem = deliveryItemService.getById(orderItem.getPoDetlId());
+                    Double workQty = Math.round((deliveryItem.getWorkQty() - orderItem.getAnfme()) * 10000) / 10000.0;
+                    deliveryItem.setWorkQty(workQty.compareTo(0.0) >= 0 ? workQty : 0);
+                    if (!deliveryItemService.updateById(deliveryItem)) {
+                        throw new CoolException("DO鍗曟槑缁嗘洿鏂板け璐ワ紒锛�");
+                    }
+                }
+            }
         }
+
+        if (!Objects.isNull(order.getPoId())) {
+            Delivery delivery = deliveryService.getById(order.getPoId());
+            if (!Objects.isNull(delivery)) {
+                Double sum = orderItems.stream().mapToDouble(AsnOrderItem::getAnfme).sum();
+                Double workQty = Math.round((delivery.getWorkQty() - sum) * 10000) / 10000.0;
+                delivery.setWorkQty(workQty.compareTo(0.0) >= 0 ? workQty : 0).setExceStatus(POExceStatus.PO_EXCE_STATUS_UN_EXCE.val);
+                if (!deliveryService.updateById(delivery)) {
+                    throw new CoolException("DO鍗曟嵁淇敼澶辫触锛侊紒");
+                }
+            }
+        }
+        if (!this.remove(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, id))) {
+            throw new CoolException("涓诲崟鍒犻櫎澶辫触锛侊紒");
+        }
+        if (!outStockItemService.remove(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, id))) {
+            throw new CoolException("鍗曟嵁鏄庣粏鍒犻櫎澶辫触锛侊紒");
+        }
+//        if (!this.saveOrUpdate(order)) {
+//            throw new CoolException("鍗曟嵁鍙栨秷澶辫触锛侊紒");
+//        }
         return R.ok("鎿嶄綔鎴愬姛");
     }
 

--
Gitblit v1.9.1