From 50393719d85fc30438456b0d0f065573a404fba5 Mon Sep 17 00:00:00 2001
From: cl <1442464845@qq.com>
Date: 星期五, 01 五月 2026 17:26:31 +0800
Subject: [PATCH] 增加一个单条上报的模式

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

diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
index d61e7ff..033f6b8 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java
@@ -27,6 +27,7 @@
 import com.vincent.rsf.framework.common.R;
 import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.server.api.utils.LocUtils;
+import com.vincent.rsf.server.manager.constant.CloudWmsInoutReportMode;
 import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams;
 import com.vincent.rsf.server.manager.entity.CloudWmsNotifyLog;
 import com.vincent.rsf.server.manager.entity.*;
@@ -55,9 +56,13 @@
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.support.TransactionSynchronization;
+import org.springframework.transaction.support.TransactionSynchronizationManager;
 import org.springframework.web.client.HttpStatusCodeException;
 import org.springframework.web.client.RestTemplate;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
@@ -175,7 +180,9 @@
                 throw new CoolException("浠诲姟淇濆瓨澶辫触锛侊紒");
             }
             if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
-                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
+                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
+                    .set(Loc::getBarcode, pakin.getBarcode())
+                    .set(Loc::getWeight, task.getWeight()))) {
                 throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
             }
             /**鑾峰彇缁勬嫋鏄庣粏**/
@@ -207,6 +214,7 @@
                     throw new CoolException("缁勬墭鏄庣粏淇墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�");
                 }
             });
+            syncAsnOrderItemBarcodeByPakin(waitPakinItems, pakin.getBarcode(), loginUserId);
         });
 
         if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
@@ -264,7 +272,8 @@
                     .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
                     .set(Loc::getUpdateBy, loginUserId)
                     .set(Loc::getUpdateTime, new Date())
-                    .set(Loc::getBarcode, pakin.getBarcode()))) {
+                    .set(Loc::getBarcode, pakin.getBarcode())
+                    .set(Loc::getWeight, task.getWeight()))) {
                 throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
             }
             /**鑾峰彇缁勬嫋鏄庣粏**/
@@ -296,6 +305,7 @@
                     throw new CoolException("缁勬墭鏄庣粏淇墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�");
                 }
             });
+            syncAsnOrderItemBarcodeByPakin(waitPakinItems, pakin.getBarcode(), loginUserId);
         });
 
         if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
@@ -406,7 +416,9 @@
 
 
             if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
-                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type).set(Loc::getBarcode, pakin.getBarcode()))) {
+                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
+                    .set(Loc::getBarcode, pakin.getBarcode())
+                    .set(Loc::getWeight, task.getWeight()))) {
                 throw new CoolException("搴撲綅棰勭害澶辫触锛侊紒");
             }
             /**鑾峰彇缁勬嫋鏄庣粏**/
@@ -446,6 +458,7 @@
                     throw new CoolException("缁勬墭鏄庣粏淇墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�");
                 }
             });
+            syncAsnOrderItemBarcodeByPakin(waitPakinItems, pakin.getBarcode(), loginUserId);
         });
 
         if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
@@ -456,6 +469,27 @@
             throw new CoolException("缁勬嫋鐘舵�佷慨鏀瑰け璐ワ紒锛�");
         }
         return R.ok("浠诲姟鐢熸垚瀹屾瘯锛�");
+    }
+
+    /** 缁勬墭鍚庡皢閫氱煡鍗曟槑缁嗘潯鐮佸洖鍐欎负鏂欑鐮� */
+    private void syncAsnOrderItemBarcodeByPakin(List<WaitPakinItem> waitPakinItems, String pakinBarcode, Long loginUserId) {
+        if (waitPakinItems == null || waitPakinItems.isEmpty() || StringUtils.isBlank(pakinBarcode)) {
+            return;
+        }
+        Set<Long> asnItemIds = waitPakinItems.stream()
+                .map(WaitPakinItem::getAsnItemId)
+                .filter(Objects::nonNull)
+                .collect(Collectors.toSet());
+        if (asnItemIds.isEmpty()) {
+            return;
+        }
+        if (!asnOrderItemService.update(new LambdaUpdateWrapper<WkOrderItem>()
+                .in(WkOrderItem::getId, asnItemIds)
+                .set(WkOrderItem::getBarcode, pakinBarcode)
+                .set(WkOrderItem::getUpdateBy, loginUserId)
+                .set(WkOrderItem::getUpdateTime, new Date()))) {
+            throw new CoolException("閫氱煡鍗曟槑缁嗘潯鐮佸洖鍐欏け璐ワ紒锛�");
+        }
     }
 
     /**
@@ -590,15 +624,44 @@
         if (StringUtils.isNotBlank(task.getTaskCode())) {
             rcsBusTaskNoticeService.notifyTaskStatus(task.getTaskCode(), task.getTaskStatus());
         }
+        final Long taskIdForFinish = task.getId();
+        if (TransactionSynchronizationManager.isSynchronizationActive()) {
+            TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
+                @Override
+                public void afterCommit() {
+                    taskService.runStockFinishAfterManualComplete(taskIdForFinish);
+                }
+            });
+        }
         return task;
     }
 
+    @Override
+    public void runStockFinishAfterManualComplete(Long taskId) {
+        if (taskId == null) {
+            return;
+        }
+        try {
+            Task t = taskService.getById(taskId);
+            if (t == null) {
+                return;
+            }
+            if (Objects.equals(t.getTaskStatus(), TaskStsType.COMPLETE_IN.id)) {
+                taskService.complateInTask(Collections.singletonList(t));
+            } else if (Objects.equals(t.getTaskStatus(), TaskStsType.COMPLETE_OUT.id)) {
+                taskService.completeTask(Collections.singletonList(t));
+            }
+        } catch (Exception e) {
+            log.warn("鎵嬪姩瀹岀粨鍚庣珛鍗冲簱瀛樻敹灏惧け璐ワ紝灏嗙敱瀹氭椂浠诲姟閲嶈瘯锛宼askId={}锛歿}", taskId, e.getMessage());
+        }
+    }
+
     /**
-     * 鍏ㄧ増鍑哄簱瀹岀粨锛氭墸闄ゅ簱浣嶆暟閲忥紝灏嗗簱浣嶇姸鎬佽涓虹┖
+     * 鍏ㄦ澘鍑哄簱瀹岀粨锛氭墸闄ゅ簱浣嶆暟閲忥紝灏嗗簱浣嶇姸鎬佽涓虹┖
      *
      * @param id 浠诲姟ID
      * @param loginUserId 鐧诲綍鐢ㄦ埛ID
-     * @param notifyRcsFromAdmin 绠$悊鍚庡彴鍏ㄧ増鍑哄簱瀹岀粨鎺ュ彛涓� true 鏃堕�氱煡 RCS锛涘畾鏃�/PDA 绛変负 false
+     * @param notifyRcsFromAdmin 绠$悊鍚庡彴鍏ㄦ澘鍑哄簱瀹岀粨鎺ュ彛涓� true 鏃堕�氱煡 RCS锛涘畾鏃�/PDA 绛変负 false
      * @return 浠诲姟瀵硅薄
      */
     @Override
@@ -612,9 +675,9 @@
             throw new CoolException("浠诲姟涓嶅瓨鍦紒锛�");
         }
 
-        // 妫�鏌ヤ换鍔$被鍨嬫槸鍚︿负鍏ㄧ増鍑哄簱
+        // 妫�鏌ヤ换鍔$被鍨嬫槸鍚︿负鍏ㄦ澘鍑哄簱
         if (!task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
-            throw new CoolException("褰撳墠浠诲姟涓嶆槸鍏ㄧ増鍑哄簱浠诲姟锛屾棤娉曟墽琛屾鎿嶄綔锛侊紒");
+            throw new CoolException("褰撳墠浠诲姟涓嶆槸鍏ㄦ澘鍑哄簱浠诲姟锛屾棤娉曟墽琛屾鎿嶄綔锛侊紒");
         }
 
         // 妫�鏌ヤ换鍔$姸鎬侊細蹇呴』鏄�199锛圵AVE_SEED锛夌姸鎬佹墠鑳芥墜鍔ㄥ畬缁�
@@ -643,6 +706,7 @@
         // 灏嗗簱浣嶇姸鎬佽涓虹┖锛圤鐘舵�侊級
         if (!locService.update(new LambdaUpdateWrapper<Loc>()
                 .set(Loc::getBarcode, null)
+                .set(Loc::getWeight, null)
                 .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                 .set(Loc::getUpdateBy, loginUserId)
                 .set(Loc::getUpdateTime, new Date())
@@ -802,6 +866,7 @@
         /**淇敼搴撲綅鐘舵�佷负F.鍦ㄥ簱*/
         if (!locService.update(new LambdaUpdateWrapper<Loc>()
                 .set(Loc::getBarcode, task.getBarcode())
+                .set(Loc::getWeight, task.getWeight())
                 .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)
                 .set(Loc::getUpdateBy, loginUserId)
                 .set(Loc::getUpdateTime, new Date())
@@ -811,6 +876,7 @@
 
         if (!locService.update(new LambdaUpdateWrapper<Loc>()
                 .set(Loc::getBarcode, null)
+                .set(Loc::getWeight, null)
                 .set(Loc::getUpdateBy, loginUserId)
                 .set(Loc::getUpdateTime, new Date())
                 .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
@@ -873,6 +939,7 @@
 //        }
         loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                 .setBarcode(task.getBarcode())
+                .setWeight(task.getWeight())
                 .setUpdateBy(loginUserId).setUpdateTime(new Date());
 
         if (!locService.updateById(loc)) {
@@ -1104,7 +1171,9 @@
                 }
                 if (!locService.update(new LambdaUpdateWrapper<Loc>()
                         .eq(Loc::getCode, task.getTargLoc())
-                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type))) {
+                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+                        .set(Loc::getBarcode, null)
+                        .set(Loc::getWeight, null))) {
                     throw new CoolException("绉诲簱鐩爣搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
                 }
 
@@ -1156,6 +1225,14 @@
                         .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type))) {
                     throw new CoolException("婧愬簱浣嶇姸鎬佷慨鏀瑰け璐ワ紒锛�");
                 }
+            } else if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)) {
+                // 绌烘澘鍑哄簱锛氬缓鍗曟椂 D鈫扲锛屽彇娑堟仮澶嶄负绌烘澘 D
+                if (!locService.update(new LambdaUpdateWrapper<Loc>()
+                        .eq(Loc::getCode, task.getOrgLoc())
+                        .eq(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_R.type)
+                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type))) {
+                    throw new CoolException("绌烘澘鍑哄簱婧愬簱浣嶆仮澶嶇┖鏉垮け璐ワ紒锛�");
+                }
             }
 
             if (!Objects.isNull(task.getWarehType()) && task.getWarehType().equals(WarehType.WAREHOUSE_TYPE_AGV.val)) {
@@ -1192,13 +1269,14 @@
                         }
                         loc.setUseStatus(LocStsType.LOC_STS_TYPE_F.type)
                                 .setBarcode(task.getBarcode())
+                                .setWeight(task.getWeight())
                                 .setUpdateBy(loginUserId)
                                 .setUpdateTime(new Date());
                         if (!locService.updateById(loc)) {
                             throw new CoolException("搴撲綅淇℃伅淇敼澶辫触锛侊紒");
                         }
                         //鍑哄簱
-                        if (item.getWkType().equals(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))) {
+                        if (Objects.equals(item.getWkType(), OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type)) {
                             //搴撳瓨鍑哄簱
                         } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_WAVE_TYPE.val)) {
                             WaveItem waveItem = waveItemService.getById(item.getSource());
@@ -1220,7 +1298,7 @@
                                 throw new CoolException("娉㈡鏇存柊澶辫触锛侊紒");
                             }
 
-                        } else if (item.getWkType().equals(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_OTHER.type))) {
+                        } else if (Objects.equals(item.getWkType(), OrderWorkType.ORDER_WORK_TYPE_OTHER.type)) {
                             //鍏跺畠鍑哄簱
 
                         } else {
@@ -1266,7 +1344,9 @@
                         Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTaskType() < TaskStsType.UPDATED_IN.id ? task.getTargLoc() : task.getOrgLoc()));
                         if (null != loc && (loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)
                                 || loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_R.type))) {
-                            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
+                            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type)
+                                    .setBarcode(null)
+                                    .setWeight(null);
                             if (!locService.updateById(loc)) {
                                 throw new CoolException("鏇存柊搴撲綅鐘舵�佸け璐ワ紒锛�");
                             }
@@ -1505,7 +1585,8 @@
                 throw new CoolException("涓存椂搴撳瓨鏇存柊澶辫触锛侊紒");
             }
         }
-        loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+        loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type)
+                .setWeight(task.getWeight());
         locService.updateById(loc1);
 //        if (!locService.updateById(loc1)) {
 //            throw new CoolException("搴撲綅棰勭害鍏ュ簱澶辫触锛侊紒");
@@ -1630,11 +1711,13 @@
             if (!workings.isEmpty()) {
                 locItemWorkingService.saveBatch(workings);
             }
-            loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+            loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type)
+                    .setWeight(first.getWeight());
             locService.updateById(loc);
         } else {
             loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
             loc.setBarcode(null);
+            loc.setWeight(null);
             loc.setUpdateBy(loginUserId);
             loc.setUpdateTime(new Date());
             locService.updateById(loc);
@@ -1673,6 +1756,7 @@
                         .eq(Loc::getId, loc.getId())
                         .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                         .set(Loc::getBarcode, null)
+                        .set(Loc::getWeight, null)
                         .set(Loc::getUpdateBy, loginUserId)
                         .set(Loc::getUpdateTime, new Date()))) {
                     throw new CoolException("绌烘澘鍑哄簱搴撲綅鐘舵�佹洿鏂板け璐ワ紒锛�");
@@ -1739,7 +1823,7 @@
             try {
                 // 鏍规嵁浠诲姟绫诲瀷鏇存柊搴撲綅鏄庣粏
                 if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
-                    // 鍏ㄧ増鍑哄簱锛氫笉鍒犻櫎搴撲綅鏄庣粏锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶅垹闄�
+                    // 鍏ㄦ澘鍑哄簱锛氫笉鍒犻櫎搴撲綅鏄庣粏锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶅垹闄�
                     // subtractLocItem(loc); // 宸茬Щ闄わ紝鏀逛负鍦╟ompleteFullOutStock涓垹闄�
                 } else if (!TaskType.TASK_TYPE_PICK_AGAIN_OUT.type.equals(task.getTaskType())) {
                     // 閮ㄥ垎鍑哄簱锛堝鐩樼偣鍑哄簱锛夛細鏍规嵁TaskItem鏁伴噺鎵e噺搴撲綅鏄庣粏锛涙嫞鏂欏嚭搴撳湪鐢熸垚鎷f枡鍏ュ簱鍗曟椂鎵e噺
@@ -1752,12 +1836,12 @@
         }
 
         //娣诲姞鍑哄叆搴撹褰曚俊鎭�
-        Map<Short, List<TaskItem>> listMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getWkType));
+        Map<String, List<TaskItem>> listMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getWkType));
         /***鑾峰彇搴撳瓨鍑哄簱鍊硷紝濡傛灉涓虹┖琛ㄧず姝e父鍗曟嵁鍑哄簱锛岄潪绌鸿〃鏄庢槸搴撳瓨鍑哄簱
          * 1. 搴撳瓨鍑哄簱娌℃湁鍗曟嵁淇℃伅锛屽崟鎹俊鎭粯璁や负绌�
          * 2. 鍗曟嵁搴撳瓨闇�閫氳繃娉㈡鏌ヨ鍘熷鍗曟嵁淇℃伅锛屽皢鍗曟嵁淇℃伅濉叆stock涓�
          * */
-        List<TaskItem> list = listMap.get(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type));
+        List<TaskItem> list = listMap.get(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type);
         if (Objects.isNull(list) || list.isEmpty()) {
             Map<Long, List<TaskItem>> maps = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
             maps.keySet().forEach(key -> {
@@ -1808,13 +1892,14 @@
             // 鎷f枡鍑哄簱/鐩樼偣鍑哄簱锛氬湪鏈敓鎴愭嫞鏂欏叆搴撳崟涔嬪墠淇濇寔 R.棰勭害鍑哄簱锛屽惁鍒欎笅鍙戜换鍔℃椂鏌ヤ笉鍒拌搴撲綅锛堝彧鏌� F+R锛夊鑷粹�滃簱瀛樹笉瓒斥��
             // 绛� PDA 纭骞剁敓鎴愭嫞鏂欏叆搴撲换鍔℃椂锛屽啀鍦� pickOrCheckTask 涓皢鐩爣搴撲綅鏀逛负 S.棰勭害鍏ュ簱
         } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
-            // 鍏ㄧ増鍑哄簱锛氫笉鏇存柊搴撲綅鐘舵�佷负O锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶆洿鏂�
+            // 鍏ㄦ澘鍑哄簱锛氫笉鏇存柊搴撲綅鐘舵�佷负O锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶆洿鏂�
             // 搴撲綅鐘舵�佷繚鎸佸師鏍凤紙R.鍑哄簱棰勭害鐘舵�侊級
         } else {
             /**淇敼涓哄簱浣嶇姸鎬佷负O.绌哄簱*/
             if (!locService.update(new LambdaUpdateWrapper<Loc>()
                     .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
                     .set(Loc::getBarcode, null)
+                    .set(Loc::getWeight, null)
                     .set(Loc::getUpdateBy, loginUserId)
                     .set(Loc::getUpdateTime, new Date())
                     .eq(Loc::getId, loc.getId()))) {
@@ -1928,13 +2013,13 @@
             if (!asnOrderService.updateById(wkOrder)) {
                 throw new CoolException("鍑哄簱鍗曟洿鏂板け璐ワ紒锛�");
             }
-            stock.setWkType(Short.parseShort(wkOrder.getWkType()))
+            stock.setWkType(wkOrder.getWkType())
                     .setType(OrderType.ORDER_OUT.type);
         } else if (!Objects.isNull(diffItem)) {
-            stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_CHECK.type))
+            stock.setWkType(OrderWorkType.ORDER_WORK_TYPE_STOCK_CHECK.type)
                     .setType(OrderType.ORDER_CHECK.type);
         } else {
-            stock.setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type))
+            stock.setWkType(OrderWorkType.ORDER_WORK_TYPE_STOCK_OUT.type)
                     .setMemo("搴撳瓨鍑哄簱锛屾棤鍗曟嵁淇℃伅锛侊紒")
                     .setType(OrderType.ORDER_OUT.type);
         }
@@ -2060,6 +2145,15 @@
                     log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
                     log.error("绔欑偣涓嶅瓨鍦紒锛佷换鍔$紪鐮侊細{}锛岀洰鏍囩珯鐐癸細{}", task.getTaskCode(), task.getTargSite());
                     continue;
+                }
+                // 鍑哄簱涓嬪彂鍓嶆牎楠岀珯鐐圭姸鎬佷笌鍑哄簱鑳藉姏
+                if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type) {
+                    if (!Integer.valueOf(1).equals(station.getStatus()) || !Integer.valueOf(1).equals(station.getOutAble())) {
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("绔欑偣涓嶅彲鍑哄簱涓嬪彂锛侊紒浠诲姟缂栫爜锛歿}锛岀洰鏍囩珯鐐癸細{}锛岀珯鐐圭姸鎬�(status)锛歿}锛岃兘鍑�(outAble)锛歿}",
+                                task.getTaskCode(), task.getTargSite(), station.getStatus(), station.getOutAble());
+                        continue;
+                    }
                 }
             }
 
@@ -2365,7 +2459,7 @@
     /**
      * @author Ryan
      * @date 2025/5/20
-     * @description: 鎵e噺搴撳瓨鏄庣粏锛堝叏鐗堝嚭搴擄細鍒犻櫎鎵�鏈夊簱浣嶆槑缁嗭級
+     * @description: 鎵e噺搴撳瓨鏄庣粏锛堝叏鏉垮嚭搴擄細鍒犻櫎鎵�鏈夊簱浣嶆槑缁嗭級
      * @version 1.0
      */
     @Transactional(rollbackFor = Exception.class)
@@ -2459,6 +2553,7 @@
         if (TaskType.TASK_TYPE_EMPITY_IN.type.equals(task.getTaskType())) {
             if (!locService.update(new LambdaUpdateWrapper<Loc>().eq(Loc::getCode, task.getTargLoc())
                     .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_D.type)
+                    .set(Loc::getWeight, task.getWeight())
                     .set(Loc::getUpdateBy, loginUserId)
                     .set(Loc::getUpdateTime, new Date()))) {
                 throw new CoolException("绌烘澘鍏ュ簱搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
@@ -2527,6 +2622,10 @@
             WkOrder o = asnOrderService.getById(e.getKey());
             if (o != null) {
                 Double newQty = QuantityUtils.roundToScale(QuantityUtils.add(o.getQty() != null ? o.getQty() : 0.0, e.getValue()));
+                Double planQty = QuantityUtils.roundToScale(o.getAnfme() != null ? o.getAnfme() : 0.0);
+                if (QuantityUtils.compare(newQty, planQty) > 0) {
+                    newQty = planQty;
+                }
                 o.setQty(newQty);
                 if (!asnOrderService.updateById(o)) {
                     throw new CoolException("鍏ュ簱鍗曞畬鎴愭暟閲忔洿鏂板け璐ワ紒锛�");
@@ -2537,6 +2636,10 @@
             WkOrderItem oi = asnOrderItemService.getById(e.getKey());
             if (oi != null) {
                 Double newQty = QuantityUtils.roundToScale(QuantityUtils.add(oi.getQty() != null ? oi.getQty() : 0.0, e.getValue()));
+                Double planQty = QuantityUtils.roundToScale(oi.getAnfme() != null ? oi.getAnfme() : 0.0);
+                if (QuantityUtils.compare(newQty, planQty) > 0) {
+                    newQty = planQty;
+                }
                 oi.setQty(newQty);
                 if (!asnOrderItemService.updateById(oi)) {
                     throw new CoolException("鍏ュ簱鍗曟槑缁嗗畬鎴愭暟閲忔洿鏂板け璐ワ紒锛�");
@@ -2545,7 +2648,10 @@
         }
 
         /**淇敼搴撲綅鐘舵�佷负F.鍦ㄥ簱*/
-        if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).eq(Loc::getCode, task.getTargLoc()))) {
+        if (!locService.update(new LambdaUpdateWrapper<Loc>()
+                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type)
+                .set(Loc::getWeight, task.getWeight())
+                .eq(Loc::getCode, task.getTargLoc()))) {
             throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
         }
         if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
@@ -2666,7 +2772,7 @@
      * @return
      */
     @Transactional(rollbackFor = Exception.class)
-    public synchronized void saveStockItems(List<TaskItem> items, Task task, Long id, String code, Short wkType, String type, Long loginUserId) {
+    public synchronized void saveStockItems(List<TaskItem> items, Task task, Long id, String code, String wkType, String type, Long loginUserId) {
         Stock stock = new Stock();
         String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_STOCK_CODE, null);
         if (StringUtils.isBlank(ruleCode)) {
@@ -2690,12 +2796,27 @@
         } else {
             stock.setLocCode(task.getOrgLoc());
         }
+        BigDecimal trayWeight = task.getWeight();
+        BigDecimal groupWeight = null;
+        if (trayWeight != null && sum > 0) {
+            List<TaskItem> allLines = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+            double totalQty = allLines.stream().mapToDouble(t -> t.getAnfme() != null ? t.getAnfme() : 0.0).sum();
+            if (totalQty > 0) {
+                groupWeight = trayWeight.multiply(BigDecimal.valueOf(sum)).divide(BigDecimal.valueOf(totalQty), 4, RoundingMode.HALF_UP);
+            } else {
+                groupWeight = trayWeight;
+            }
+            stock.setWeight(groupWeight);
+        }
         if (!stockService.save(stock)) {
             throw new CoolException("搴撳瓨淇濆瓨澶辫触锛侊紒");
         }
 
         List<StockItem> stockItems = new ArrayList<>();
-        for (TaskItem item : items) {
+        BigDecimal allocatedWeight = BigDecimal.ZERO;
+        BigDecimal sumBd = sum > 0 ? BigDecimal.valueOf(sum) : null;
+        for (int i = 0; i < items.size(); i++) {
+            TaskItem item = items.get(i);
             /**閫氳繃浠诲姟鏄庣粏涓殑taskId鏌ヨ,鑾峰彇TASK鐨勭洰鏍囧簱浣嶄俊鎭�*/
             StockItem stockItem = new StockItem();
             BeanUtils.copyProperties(item, stockItem);
@@ -2706,6 +2827,16 @@
                     .setUpdateBy(loginUserId)
                     .setId(null)
                     .setStockId(stock.getId());
+            if (groupWeight != null && sumBd != null) {
+                if (i == items.size() - 1) {
+                    stockItem.setWeight(groupWeight.subtract(allocatedWeight));
+                } else {
+                    double lineQty = item.getAnfme() != null ? item.getAnfme() : 0.0;
+                    BigDecimal lineW = groupWeight.multiply(BigDecimal.valueOf(lineQty)).divide(sumBd, 4, RoundingMode.HALF_UP);
+                    stockItem.setWeight(lineW);
+                    allocatedWeight = allocatedWeight.add(lineW);
+                }
+            }
             stockItems.add(stockItem);
         }
         if (!stockItemService.saveBatch(stockItems)) {
@@ -2750,9 +2881,63 @@
                     }
                 }
             }
+            // 鍏ュ簱缁勬墭鍦烘櫙鍏佽鎸� WaitPakinItem.asnCode 鍏滃簳璇嗗埆浜戜粨鏉ユ簮锛岄伩鍏� plat* 涓虹┖鏃惰璺宠繃
+            boolean hasCloudSource = taskItems.stream().anyMatch(this::hasCloudOrderRef)
+                    || (isInbound && !sourceToOrderNo.isEmpty());
+            if (!hasCloudSource) {
+                log.info("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙璺宠繃锛氭棤浜戜粨鏉ユ簮鍗曟嵁锛宼askId={}", task.getId());
+                return;
+            }
+            Set<Long> orderIdSet = taskItems.stream()
+                    .filter(Objects::nonNull)
+                    .map(TaskItem::getOrderId)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toSet());
+            Map<Long, WkOrder> orderById = new HashMap<>();
+            if (!orderIdSet.isEmpty()) {
+                for (WkOrder o : asnOrderService.listByIds(orderIdSet)) {
+                    if (o != null && o.getId() != null) {
+                        orderById.put(o.getId(), o);
+                    }
+                }
+            }
+            Set<String> orderCodeSet = new HashSet<>();
+            for (TaskItem ti : taskItems) {
+                if (ti == null) {
+                    continue;
+                }
+                String on = isInbound && ti.getSource() != null
+                        ? sourceToOrderNo.get(ti.getSource())
+                        : (ti.getPlatOrderCode() != null ? ti.getPlatOrderCode() : ti.getPlatWorkCode());
+                if (on == null && isInbound) {
+                    on = ti.getPlatOrderCode() != null ? ti.getPlatOrderCode() : ti.getPlatWorkCode();
+                }
+                if (StringUtils.isNotBlank(on)) {
+                    orderCodeSet.add(on);
+                }
+            }
+            Map<String, WkOrder> orderByCode = new HashMap<>();
+            if (!orderCodeSet.isEmpty()) {
+                for (WkOrder o : asnOrderService.list(new LambdaQueryWrapper<WkOrder>().in(WkOrder::getCode, orderCodeSet))) {
+                    if (o != null && StringUtils.isNotBlank(o.getCode())) {
+                        orderByCode.put(o.getCode(), o);
+                    }
+                }
+            }
             ObjectMapper om = new ObjectMapper();
             Date now = new Date();
+            Map<String, List<InOutResultReportParam>> byOrder = new LinkedHashMap<>();
             for (TaskItem item : taskItems) {
+                if (item == null) {
+                    continue;
+                }
+                boolean hasTaskItemCloudRef = hasCloudOrderRef(item);
+                boolean hasInboundAsnFallbackRef = isInbound
+                        && item.getSource() != null
+                        && StringUtils.isNotBlank(sourceToOrderNo.get(item.getSource()));
+                if (!hasTaskItemCloudRef && !hasInboundAsnFallbackRef) {
+                    continue;
+                }
                 String orderNo = isInbound ? sourceToOrderNo.get(item.getSource()) : (item.getPlatOrderCode() != null ? item.getPlatOrderCode() : item.getPlatWorkCode());
                 if (orderNo == null && isInbound) {
                     orderNo = item.getPlatOrderCode() != null ? item.getPlatOrderCode() : item.getPlatWorkCode();
@@ -2760,35 +2945,80 @@
                 if (orderNo == null || item.getMatnrCode() == null) {
                     continue;
                 }
+                WkOrder asnOrder = null;
+                if (item.getOrderId() != null) {
+                    asnOrder = orderById.get(item.getOrderId());
+                }
+                if (asnOrder == null) {
+                    asnOrder = orderByCode.get(orderNo);
+                }
                 InOutResultReportParam param = new InOutResultReportParam()
                         .setOrderNo(orderNo)
                         .setPlanNo(item.getPlatWorkCode())
+                        .setWkType(item.getWkType())
+                        .setUnitNo(item.getUnit())
                         .setLineId(item.getPlatItemId())
                         .setWareHouseId(wareHouseId)
+                        .setDocWarehouseNo(asnOrder != null ? asnOrder.getDocTaskWarehouseNo() : null)
+                        .setOrgNo(asnOrder != null ? asnOrder.getDocOrgNo() : null)
+                        .setInWarehouseNo(isInbound && asnOrder != null ? asnOrder.getDocInWarehouseNo() : null)
+                        .setOutWarehouseNo(!isInbound && asnOrder != null ? asnOrder.getDocOutWarehouseNo() : null)
                         .setLocId(locId)
                         .setMatNr(item.getMatnrCode())
                         .setQty(item.getAnfme() != null ? String.valueOf(item.getAnfme()) : "0")
                         .setBatch(item.getBatch())
                         .setInbound(isInbound)
                         .setBarcode(task.getBarcode());
-                try {
-                    String requestBody = om.writeValueAsString(param);
-                    CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog()
-                            .setReportType(cloudWmsNotifyLogService.getReportTypeInOutResult())
-                            .setRequestBody(requestBody)
-                            .setNotifyStatus(cloudWmsNotifyLogService.getNotifyStatusPending())
-                            .setRetryCount(0)
-                            .setBizRef("taskId=" + task.getId() + ",orderNo=" + orderNo)
-                            .setCreateTime(now)
-                            .setUpdateTime(now);
-                    cloudWmsNotifyLogService.fillFromConfig(notifyLog);
-                    cloudWmsNotifyLogService.save(notifyLog);
-                } catch (JsonProcessingException e) {
-                    log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙钀藉簱澶辫触锛堜笉褰卞搷涓绘祦绋嬶級锛宼askId={}锛宱rderNo={}锛歿}", task.getId(), orderNo, e.getMessage());
+                byOrder.computeIfAbsent(orderNo, k -> new ArrayList<>()).add(param);
+            }
+            String mode = resolveCloudWmsInoutReportMode();
+            boolean sendHold = CloudWmsInoutReportMode.MANUAL.equals(mode) || CloudWmsInoutReportMode.WAIT_ORDER.equals(mode);
+            for (Map.Entry<String, List<InOutResultReportParam>> e : byOrder.entrySet()) {
+                String orderNo = e.getKey();
+                for (InOutResultReportParam param : e.getValue()) {
+                    try {
+                        String requestBody = om.writeValueAsString(param);
+                        CloudWmsNotifyLog notifyLog = new CloudWmsNotifyLog()
+                                .setReportType(cloudWmsNotifyLogService.getReportTypeInOutResult())
+                                .setRequestBody(requestBody)
+                                .setRetryCount(0)
+                                .setBizRef("taskId=" + task.getId() + ",orderNo=" + orderNo)
+                                .setCreateTime(now)
+                                .setUpdateTime(now)
+                                .setSourceOrderNo(orderNo)
+                                .setInboundFlag(isInbound ? 1 : 0)
+                                .setWareHouseCode(wareHouseId)
+                                .setSendHold(sendHold ? 1 : 0)
+                                .setSending(0);
+                        cloudWmsNotifyLogService.fillFromConfig(notifyLog);
+                        cloudWmsNotifyLogService.save(notifyLog);
+                    } catch (JsonProcessingException ex) {
+                        log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙钀藉簱澶辫触锛堜笉褰卞搷涓绘祦绋嬶級锛宼askId={}锛宱rderNo={}锛歿}", task.getId(), orderNo, ex.getMessage());
+                    }
                 }
             }
         } catch (Exception e) {
             log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙澶辫触锛宼askId={}锛宨sInbound={}锛歿}", task.getId(), isInbound, e.getMessage());
         }
     }
+
+    private boolean hasCloudOrderRef(TaskItem item) {
+        if (item == null) {
+            return false;
+        }
+        return StringUtils.isNotBlank(item.getPlatOrderCode())
+                || StringUtils.isNotBlank(item.getPlatWorkCode());
+    }
+
+    /** sys_config CLOUD_WMS_INOUT_REPORT_MODE锛歩mmediate / wait_order / manual / single */
+    private String resolveCloudWmsInoutReportMode() {
+        try {
+            Config cfg = configService.getCachedOrLoad(GlobalConfigCode.CLOUD_WMS_INOUT_REPORT_MODE);
+            if (cfg != null && StringUtils.isNotBlank(cfg.getVal())) {
+                return cfg.getVal().trim().toLowerCase();
+            }
+        } catch (Exception ignored) {
+        }
+        return CloudWmsInoutReportMode.IMMEDIATE;
+    }
 }

--
Gitblit v1.9.1