From 82065a03737fa1370eb9f4f01ab5332933baf08a Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期四, 05 三月 2026 09:23:37 +0800
Subject: [PATCH] 云仓WMS+RCS+自动入库临时方法配置

---
 rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java |  114 ++++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 81 insertions(+), 33 deletions(-)

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
index ca580c6..6d8b18f 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/ReceiveMsgServiceImpl.java
@@ -26,7 +26,10 @@
 import com.vincent.rsf.server.manager.service.*;
 import com.vincent.rsf.server.manager.service.impl.MatnrServiceImpl;
 import com.vincent.rsf.server.system.constant.DictTypeCode;
+import com.vincent.rsf.server.system.constant.GlobalConfigCode;
 import com.vincent.rsf.server.system.constant.SerialRuleCode;
+import com.vincent.rsf.server.system.entity.Config;
+import com.vincent.rsf.server.system.service.ConfigService;
 import com.vincent.rsf.server.system.entity.DictData;
 import com.vincent.rsf.server.system.entity.DictType;
 import com.vincent.rsf.server.system.entity.Fields;
@@ -113,6 +116,8 @@
     private WaitPakinItemService waitPakinItemService;
     @Autowired
     private WarehouseAreasItemService warehouseAreasItemService;
+    @Autowired
+    private ConfigService configService;
 
 
     /**
@@ -461,22 +466,27 @@
                             .eq(WkOrder::getPoCode, syncOrder.getOrderInternalCode()));
                     if (!Objects.isNull(order)) {
                         // 浠呮湭鎵ц鐘舵�佸彲琚� order/add 淇敼锛堝叆搴撴湭鎵ц銆佸嚭搴撲换鍔″垵濮嬶級
-                        List<Short> editableStatus = Arrays.asList(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val, AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val);
+                        List<Short> editableStatus = Arrays.asList(AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val
+                                ,AsnExceStatus.ASN_EXCE_STATUS_UN_EXCE.val
+                                ,AsnExceStatus.ASN_EXCE_STATUS_RECEIPT_DONE.val
+                                , AsnExceStatus.OUT_STOCK_STATUS_TASK_INIT.val);
                         if (!editableStatus.contains(order.getExceStatus())) {
                             throw new CoolException("浠呮湭鎵ц鐘舵�佺殑鍗曟嵁鍙慨鏀癸紒锛�");
                         }
                         // 瀛樺湪鍒欎慨鏀癸紙1 鍜� 2 鍧囪蛋姝ゅ锛夛紝缁勬墭鏍¢獙鍦� mergeOrderWithPakin/updateOrderNoPakin 鍐�
                         long pakinCount = waitPakinItemService.count(new LambdaQueryWrapper<WaitPakinItem>()
-                                .eq(WaitPakinItem::getAsnId, order.getId()));
+                                .eq(WaitPakinItem::getAsnId, order.getId()).eq(WaitPakinItem::getDeleted, 0));
                         if (pakinCount > 0) {
-                            // 宸茬粍鎵橈細鎸� lineId锛坧latItemId锛夊悎骞讹紝鏍¢獙鏁伴噺涓庡垹闄�
                             mergeOrderWithPakin(order, syncOrder, resolvedOrderType, typeCode, loginUserId);
-                            // 鏀惰揣鍖哄凡鍋滅敤 // syncReceiptAreaByOrder(order.getId());
-                            return; // 鏈崟宸插鐞嗭紝璺宠繃涓嬫柟鈥滄柊寤轰富鍗�+鏄庣粏鈥�
+                            if (isDirectWaitPakin()) {
+                                syncReceiptAreaByOrder(order.getId());
+                            }
+                            return;
                         }
-                        // 鏈粍鎵橈細鍦ㄥ師鍗曚笂鏇存柊涓诲崟+鏄庣粏锛屼繚鐣� exceStatus/qty/workQty锛岄伩鍏嶅啀娆¤Е鍙戝畾鏃朵换鍔″鑷撮噸澶嶆敹璐�
                         updateOrderNoPakin(order, syncOrder, loginUserId);
-                        // 鏀惰揣鍖哄凡鍋滅敤 // syncReceiptAreaByOrder(order.getId());
+                        if (isDirectWaitPakin()) {
+                            syncReceiptAreaByOrder(order.getId());
+                        }
                         return;
                     } else if (Integer.valueOf(2).equals(syncOrder.getOperateType())) {
                         // 浠� operateType=2 鏃惰姹傚崟鎹繀椤诲瓨鍦�
@@ -551,7 +561,7 @@
             }
         }
         List<WkOrderItem> existingItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId()));
-        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getAsnId, order.getId()));
+        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getAsnId, order.getId()).eq(WaitPakinItem::getDeleted, 0));
         Map<Long, Double> palletizedByItemId = pakinItems.stream()
                 .collect(Collectors.groupingBy(WaitPakinItem::getAsnItemId, Collectors.summingDouble(w -> w.getAnfme() != null ? w.getAnfme() : 0.0)));
         palletizedByItemId.replaceAll((k, v) -> QuantityUtils.roundToScale(v));
@@ -567,6 +577,15 @@
                 .map(e -> StringUtils.isNotBlank(e.getPlatItemId()) ? e.getPlatItemId().trim() : null)
                 .filter(Objects::nonNull)
                 .collect(Collectors.toSet());
+
+        // 宸茬粍鎵樺崟鎹慨鏀瑰彧鑳藉鍔犳暟閲忎笉鑳藉噺灏戞暟閲忥細浜戜粨涓嬪彂鐨勬�绘暟閲忎笉寰楀皬浜庡凡缁勬墭鎬婚噺
+        double totalPalletized = QuantityUtils.roundToScale(pakinItems.stream().mapToDouble(w -> w.getAnfme() != null ? w.getAnfme() : 0.0).sum());
+        double incomingTotal = syncOrder.getOrderItems() == null ? 0.0 : syncOrder.getOrderItems().stream()
+                .mapToDouble(it -> it.getAnfme() != null ? it.getAnfme() : 0.0).sum();
+        incomingTotal = QuantityUtils.roundToScale(incomingTotal);
+        if (QuantityUtils.compare(incomingTotal, totalPalletized) < 0) {
+            throw new CoolException("宸茬粍鎵樺崟鎹慨鏀瑰彧鑳藉鍔犳暟閲忎笉鑳藉噺灏戞暟閲忥紙褰撳墠宸茬粍鎵樻�婚噺 " + totalPalletized + "锛屼笅鍙戞�婚噺 " + incomingTotal + "锛夛紒锛�");
+        }
 
         for (WkOrderItem existing : existingItems) {
             String lineId = StringUtils.isNotBlank(existing.getPlatItemId()) ? existing.getPlatItemId().trim() : null;
@@ -603,7 +622,16 @@
                 continue;
             }
             SyncOrdersItem inc = incomingByLineId.get(lineId);
-            existing.setAnfme(QuantityUtils.roundToScale(inc.getAnfme() != null ? inc.getAnfme() : existing.getAnfme()));
+            Double newAnfme = QuantityUtils.roundToScale(inc.getAnfme() != null ? inc.getAnfme() : existing.getAnfme());
+            existing.setAnfme(newAnfme);
+            if (inc.getQty() != null) {
+                existing.setQty(QuantityUtils.roundToScale(inc.getQty()));
+            } else {
+                Double curQty = existing.getQty() != null ? existing.getQty() : 0.0;
+                if (QuantityUtils.compare(curQty, 0.0) != 0) {
+                    existing.setQty(QuantityUtils.roundToScale(newAnfme));
+                }
+            }
             existing.setMaktx(inc.getMaktx());
             existing.setSpec(inc.getSpec());
             existing.setModel(inc.getModel());
@@ -635,6 +663,9 @@
         Double sum = QuantityUtils.roundToScale(asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId()))
                 .stream().mapToDouble(WkOrderItem::getAnfme).sum());
         order.setAnfme(sum);
+        List<WkOrderItem> afterItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId()));
+        double qtySum = afterItems.stream().mapToDouble(oi -> oi.getQty() != null ? oi.getQty() : 0.0).sum();
+        order.setQty(QuantityUtils.roundToScale(qtySum));
         asnOrderService.updateById(order);
     }
 
@@ -672,12 +703,23 @@
         for (WkOrderItem existing : existingItems) {
             String lineId = StringUtils.isNotBlank(existing.getPlatItemId()) ? existing.getPlatItemId().trim() : null;
             if (lineId == null || !incomingByLineId.containsKey(lineId)) {
-                // 鏀惰揣鍖哄凡鍋滅敤 // warehouseAreasItemService.remove(new LambdaQueryWrapper<WarehouseAreasItem>().eq(WarehouseAreasItem::getAsnItemId, existing.getId()));
+                if (isDirectWaitPakin()) {
+                    warehouseAreasItemService.remove(new LambdaQueryWrapper<WarehouseAreasItem>().eq(WarehouseAreasItem::getAsnItemId, existing.getId()));
+                }
                 asnOrderItemService.removeById(existing.getId());
                 continue;
             }
             SyncOrdersItem inc = incomingByLineId.get(lineId);
-            existing.setAnfme(QuantityUtils.roundToScale(inc.getAnfme() != null ? inc.getAnfme() : existing.getAnfme()));
+            Double newAnfme = QuantityUtils.roundToScale(inc.getAnfme() != null ? inc.getAnfme() : existing.getAnfme());
+            existing.setAnfme(newAnfme);
+            if (inc.getQty() != null) {
+                existing.setQty(QuantityUtils.roundToScale(inc.getQty()));
+            } else {
+                Double curQty = existing.getQty() != null ? existing.getQty() : 0.0;
+                if (QuantityUtils.compare(curQty, 0.0) != 0) {
+                    existing.setQty(QuantityUtils.roundToScale(newAnfme));
+                }
+            }
             existing.setMaktx(inc.getMaktx());
             existing.setSpec(inc.getSpec());
             existing.setModel(inc.getModel());
@@ -709,31 +751,37 @@
         Double sum = QuantityUtils.roundToScale(asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId()))
                 .stream().mapToDouble(WkOrderItem::getAnfme).sum());
         order.setAnfme(sum);
+        List<WkOrderItem> afterItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId()));
+        double qtySum = afterItems.stream().mapToDouble(oi -> oi.getQty() != null ? oi.getQty() : 0.0).sum();
+        order.setQty(QuantityUtils.roundToScale(qtySum));
         asnOrderService.updateById(order);
     }
 
-    /** 鏀惰揣鍖哄凡鍋滅敤锛屾柟娉曟暣浣撴敞閲�
-     * 璁㈠崟淇敼鍚庡悓姝ユ敹璐у尯锛氭寜 asnItemId 灏嗘敹璐у尯璁板綍鐨� anfme 鏇存柊涓鸿鍗曟槑缁嗙殑 anfme銆�
-     */
-//    private void syncReceiptAreaByOrder(Long orderId) {
-//        List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, orderId));
-//        if (orderItems.isEmpty()) {
-//            return;
-//        }
-//        List<WarehouseAreasItem> areaItems = warehouseAreasItemService.list(new LambdaQueryWrapper<WarehouseAreasItem>().eq(WarehouseAreasItem::getAsnId, orderId));
-//        Map<Long, Double> itemAnfme = orderItems.stream().collect(Collectors.toMap(WkOrderItem::getId, i -> i.getAnfme() != null ? i.getAnfme() : 0.0, (a, b) -> b));
-//        for (WarehouseAreasItem area : areaItems) {
-//            if (area.getAsnItemId() == null || !itemAnfme.containsKey(area.getAsnItemId())) {
-//                continue;
-//            }
-//            Double anfme = itemAnfme.get(area.getAsnItemId());
-//            if (area.getAnfme() != null && area.getAnfme().equals(anfme)) {
-//                continue;
-//            }
-//            area.setAnfme(anfme);
-//            warehouseAreasItemService.updateById(area);
-//        }
-//    }
+    /** DirectWaitPakin 鍚敤鏃讹細璁㈠崟淇敼鍚庡悓姝ユ敹璐у尯锛屾寜 asnItemId 灏嗘敹璐у尯璁板綍鐨� anfme 鏇存柊涓鸿鍗曟槑缁嗙殑 anfme銆� */
+    private void syncReceiptAreaByOrder(Long orderId) {
+        List<WkOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, orderId));
+        if (orderItems.isEmpty()) {
+            return;
+        }
+        List<WarehouseAreasItem> areaItems = warehouseAreasItemService.list(new LambdaQueryWrapper<WarehouseAreasItem>().eq(WarehouseAreasItem::getAsnId, orderId));
+        Map<Long, Double> itemAnfme = orderItems.stream().collect(Collectors.toMap(WkOrderItem::getId, i -> i.getAnfme() != null ? i.getAnfme() : 0.0, (a, b) -> b));
+        for (WarehouseAreasItem area : areaItems) {
+            if (area.getAsnItemId() == null || !itemAnfme.containsKey(area.getAsnItemId())) {
+                continue;
+            }
+            Double anfme = itemAnfme.get(area.getAsnItemId());
+            if (area.getAnfme() != null && area.getAnfme().equals(anfme)) {
+                continue;
+            }
+            area.setAnfme(anfme);
+            warehouseAreasItemService.updateById(area);
+        }
+    }
+
+    private boolean isDirectWaitPakin() {
+        Config config = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.DIRECT_WAIT_PAKIN));
+        return config != null && Boolean.parseBoolean(config.getVal());
+    }
 
     /**
      * @author Ryan

--
Gitblit v1.9.1