From ad5fef776eb9d66a0fcfc2ddf89698c5642e0eec Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期五, 06 三月 2026 08:36:24 +0800
Subject: [PATCH] 增加一个定时任务。如果拣货出库过程中,相同料箱号,存在(199 ,200)的任务 并且同时存在  101,196的任务 则101和196的任务会 自动变成199

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |  363 +++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 329 insertions(+), 34 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 476bf94..27c07f7 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
@@ -4,12 +4,14 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.cfg.CoercionAction;
 import com.fasterxml.jackson.databind.cfg.CoercionInputShape;
 import com.vincent.rsf.framework.common.Cools;
 import com.vincent.rsf.framework.common.DateUtils;
 import com.vincent.rsf.server.api.config.RemotesInfoProperties;
+import com.vincent.rsf.server.api.controller.erp.params.InOutResultReportParam;
 import com.vincent.rsf.server.api.controller.erp.params.TaskInParam;
 import com.vincent.rsf.server.api.entity.CommonResponse;
 import com.vincent.rsf.server.api.entity.constant.RcsConstant;
@@ -26,6 +28,7 @@
 import com.vincent.rsf.framework.exception.CoolException;
 import com.vincent.rsf.server.api.utils.LocUtils;
 import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams;
+import com.vincent.rsf.server.manager.entity.CloudWmsNotifyLog;
 import com.vincent.rsf.server.manager.entity.*;
 import com.vincent.rsf.server.manager.mapper.TaskMapper;
 import com.vincent.rsf.server.manager.service.*;
@@ -124,6 +127,10 @@
     private RestTemplate restTemplate;
     @Autowired
     private RemotesInfoProperties.RcsApi rcsApi;
+    @Autowired
+    private CloudWmsNotifyLogService cloudWmsNotifyLogService;
+    @Autowired
+    private WarehouseService warehouseService;
 
     @Override
     @Transactional(rollbackFor = Exception.class)
@@ -460,16 +467,18 @@
         if (success.compareAndSet(false, true)) {
             Long loginUserId = SystemAuthUtils.getLoginUserId();
             for (Task task : tasks) {
-                if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
-                    //1.鍏ュ簱
+                if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_IN.type)) {
+                    //1.鍏ュ簱銆�54.骞舵澘鍐嶅叆搴�
                     complateInstock(task, loginUserId);
                 } else if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)) {
-                    //53.鎷f枡鍐嶅叆搴�
-                    //57.鐩樼偣鍐嶅叆搴�
+                    //53.鎷f枡鍐嶅叆搴撱��57.鐩樼偣鍐嶅叆搴�
                     pickComplateInStock(task, loginUserId);
                 } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
-                    //绉诲簱
+                    //11.搴撴牸绉昏浇
                     moveInStock(task, loginUserId);
+                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
+                    //10.绌烘澘鍏ュ簱锛氫笌鏅�氬叆搴撳叡鐢ㄤ竴涓畬鎴愰�昏緫锛堣嫢鏈夌粍鎵樺垯鏇存柊缁勬墭/搴撲綅骞朵笂鎶ヤ簯浠擄級
+                    complateInstock(task, loginUserId);
                 }
             }
         }
@@ -722,7 +731,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void moveToDeep(Long loginUserId, String curLoc) throws Exception {
-        //娴呭簱浣嶏紝鍒ゆ柇娣卞搴旀繁搴撲綅鏄惁涓虹┖锛屽鏋滀负绌虹敓鎴愪竴涓Щ搴撲换鍔★紝灏嗘墭鐩橀�佸叆娣卞簱浣�
+        //娴呭簱浣嶏紝鍒ゆ柇娣卞搴旀繁搴撲綅鏄惁涓虹┖锛屽鏋滀负绌虹敓鎴愪竴涓Щ搴撲换鍔★紝灏嗘枡绠遍�佸叆娣卞簱浣�
         String deepLoc = LocUtils.getDeepLoc(curLoc);
         if (StringUtils.isBlank(deepLoc)) {
             throw new CoolException("鏁版嵁寮傚父锛岃鑱旂郴绠$悊鍛橈紒");
@@ -805,7 +814,11 @@
                 .set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
             throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
         }
-
+        // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氬簱鏍肩Щ杞藉畬鎴愬悗閫氱煡浜戜粨锛堜笌瀹氭椂浠诲姟闂幆涓�鑷达級
+        List<TaskItem> moveTaskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+        if (!moveTaskItems.isEmpty()) {
+            reportInOutResultToCloud(task, loc, moveTaskItems, null, true);
+        }
     }
 
 
@@ -904,7 +917,8 @@
         if (!taskService.updateById(task)) {
             throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
         }
-
+        // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氭嫞鏂欏啀鍏ュ簱/鐩樼偣鍐嶅叆搴撳畬鎴愬悗閫氱煡浜戜粨锛堜笌瀹氭椂浠诲姟闂幆涓�鑷达級
+        reportInOutResultToCloud(task, loc, taskItems, null, true);
     }
 
     /**
@@ -960,7 +974,7 @@
                         batchNo = task.getTaskCode();
                     }
                 }
-                log.info("浠诲姟宸蹭笅鍙戝埌RCS锛岄渶瑕佸彇娑圧CS浠诲姟 - 浠诲姟ID锛歿}锛屼换鍔$紪鍙凤細{}锛屼换鍔$姸鎬侊細{}锛屾墭鐩樼爜锛歿}", 
+                log.info("浠诲姟宸蹭笅鍙戝埌RCS锛岄渶瑕佸彇娑圧CS浠诲姟 - 浠诲姟ID锛歿}锛屼换鍔$紪鍙凤細{}锛屼换鍔$姸鎬侊細{}锛屾枡绠辩爜锛歿}", 
                         task.getId(), task.getTaskCode(), task.getTaskStatus(), task.getBarcode());
             }
         }
@@ -1369,6 +1383,15 @@
             });
             log.debug("[鎷f枡鍏ュ簱] 鍗冲皢鎵e噺搴撲綅 locId={}, locCode={}", loc.getId(), loc.getCode());
             subtractLocItemByTaskItems(loc, taskItems, SystemAuthUtils.getLoginUserId());
+            // 鏂欑宸插叏閮ㄧ敤瀹屽垯涓嶇敓鎴愭嫞璐у叆搴撳崟锛屼粎瀹岀粨鍑哄簱
+            double totalRemaining = taskItems.stream().mapToDouble(ti -> ti.getAnfme() != null && ti.getAnfme().compareTo(0.0) > 0 ? ti.getAnfme() : 0.0).sum();
+            if (totalRemaining <= 0.0) {
+                task.setTaskType(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type);
+                task.setTaskStatus(TaskStsType.UPDATED_OUT.id);
+                this.updateById(task);
+                locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, task.getId()));
+                return task;
+            }
         }
 
         tempLocs.forEach(working -> {
@@ -1464,6 +1487,137 @@
     }
 
     /**
+     * 鍚岀鐮佷笅澶氭潯 200 鎷f枡鍑哄簱涓�娆℃�у鐞嗭細鎸夌浉鍚岀墿鏂欏悎璁℃墸鍑忓簱浣嶃�佹洿鏂板嚭搴撳崟/搴撳瓨鏄庣粏銆佺敓鎴愪竴寮犳嫞鏂欏叆搴撳崟锛堟湁浣欓噺鏃讹級銆佹洿鏂板簱浣嶇姸鎬�
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void processPickOutBarcodeAll200(List<Task> all200Tasks) {
+        if (all200Tasks == null || all200Tasks.isEmpty()) {
+            return;
+        }
+        Task first = all200Tasks.get(0);
+        if (!TaskType.TASK_TYPE_PICK_AGAIN_OUT.type.equals(first.getTaskType()) || !TaskStsType.UPDATED_OUT.id.equals(first.getTaskStatus())) {
+            throw new CoolException("闈炴嫞鏂欏嚭搴�200浠诲姟锛屼笉鍙壒閲忓鐞�");
+        }
+        List<Long> taskIds = all200Tasks.stream().map(Task::getId).collect(Collectors.toList());
+        List<TaskItem> allItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, taskIds));
+        if (allItems.isEmpty()) {
+            throw new CoolException("浠诲姟鏄庣粏涓虹┖");
+        }
+        Long loginUserId = SystemAuthUtils.getLoginUserId();
+        if (loginUserId == null) {
+            loginUserId = 1L;
+        }
+        String orgLoc = first.getOrgLoc();
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, orgLoc));
+        if (loc == null) {
+            throw new CoolException("搴撲綅涓嶅瓨鍦細" + orgLoc);
+        }
+        // 鎸夌墿鏂�+鎵规+绁ㄥ彿姹囨�诲凡鎷f暟閲�
+        Map<String, List<TaskItem>> byKey = allItems.stream().collect(Collectors.groupingBy(ti ->
+                (ti.getMatnrId() != null ? ti.getMatnrId() : "") + "_" + (ti.getBatch() != null ? ti.getBatch() : "") + "_" + (ti.getFieldsIndex() != null ? ti.getFieldsIndex() : "")));
+        List<TaskItem> aggregatedForDeduct = new ArrayList<>();
+        Map<String, Double> remainderByKey = new LinkedHashMap<>();
+        for (Map.Entry<String, List<TaskItem>> e : byKey.entrySet()) {
+            List<TaskItem> group = e.getValue();
+            double totalQty = group.stream().mapToDouble(ti -> ti.getQty() != null && ti.getQty() > 0 ? ti.getQty() : (ti.getAnfme() != null ? ti.getAnfme() : 0)).sum();
+            TaskItem rep = group.get(0);
+            TaskItem forDeduct = new TaskItem();
+            forDeduct.setMatnrId(rep.getMatnrId()).setBatch(rep.getBatch()).setFieldsIndex(rep.getFieldsIndex()).setQty(totalQty);
+            aggregatedForDeduct.add(forDeduct);
+            LambdaQueryWrapper<LocItem> qw = new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId()).eq(LocItem::getMatnrId, rep.getMatnrId());
+            if (StringUtils.isNotBlank(rep.getBatch())) qw.eq(LocItem::getBatch, rep.getBatch());
+            else qw.and(w -> w.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, ""));
+            if (StringUtils.isNotBlank(rep.getFieldsIndex())) qw.eq(LocItem::getFieldsIndex, rep.getFieldsIndex());
+            else qw.and(w -> w.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, ""));
+            LocItem li = locItemService.getOne(qw);
+            double remainder = (li != null && li.getAnfme() != null ? li.getAnfme() : 0) - totalQty;
+            if (remainder > 0) {
+                remainderByKey.put(e.getKey(), remainder);
+            }
+        }
+        subtractLocItemByTaskItems(loc, aggregatedForDeduct, loginUserId);
+        // 鎸� source 鍒嗙粍鏇存柊鍑哄簱鍗曞苟鍐欏簱瀛樻祦姘�
+        Map<Long, List<TaskItem>> bySource = allItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
+        for (Map.Entry<Long, List<TaskItem>> e : bySource.entrySet()) {
+            Long key = e.getKey();
+            List<TaskItem> items = e.getValue();
+            if (first.getResource() != null && first.getResource().equals(TaskResouceType.TASK_RESOUCE_WAVE_TYPE.val)) {
+                WaveItem waveItem = waveItemService.getById(key);
+                if (waveItem != null) {
+                    try {
+                        saveOutStockItem(items, null, waveItem, null, loginUserId);
+                    } catch (Exception ex) {
+                        throw new CoolException(ex.getMessage());
+                    }
+                }
+            } else if (first.getResource() != null && first.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) {
+                WkOrderItem orderItem = asnOrderItemService.getById(key);
+                if (orderItem != null) {
+                    try {
+                        saveOutStockItem(items, orderItem, null, null, loginUserId);
+                    } catch (Exception ex) {
+                        throw new CoolException(ex.getMessage());
+                    }
+                }
+            }
+        }
+        // 鏈変綑閲忓垯鐢熸垚涓�寮犳嫞鏂欏叆搴撳崟
+        if (!remainderByKey.isEmpty()) {
+            Task pickInTask = new Task();
+            pickInTask.setTaskCode(SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_TASK_CODE, first));
+            pickInTask.setTaskType(TaskType.TASK_TYPE_PICK_IN.type);
+            pickInTask.setTaskStatus(TaskStsType.GENERATE_IN.id);
+            pickInTask.setBarcode(first.getBarcode());
+            pickInTask.setOrgLoc(orgLoc);
+            pickInTask.setTargLoc(orgLoc);
+            pickInTask.setOrgSite(first.getTargSite());
+            pickInTask.setTargSite(first.getTargSite());
+            pickInTask.setResource(first.getResource());
+            if (!this.save(pickInTask)) {
+                throw new CoolException("鎷f枡鍏ュ簱浠诲姟鍒涘缓澶辫触");
+            }
+            List<LocItemWorking> workings = new ArrayList<>();
+            for (Map.Entry<String, Double> re : remainderByKey.entrySet()) {
+                String k = re.getKey();
+                Double rem = re.getValue();
+                if (rem == null || rem <= 0) continue;
+                List<TaskItem> group = byKey.get(k);
+                if (group == null || group.isEmpty()) continue;
+                TaskItem rep = group.get(0);
+                TaskItem ti = new TaskItem();
+                ti.setTaskId(pickInTask.getId());
+                ti.setMatnrId(rep.getMatnrId()).setMaktx(rep.getMaktx()).setMatnrCode(rep.getMatnrCode());
+                ti.setBatch(rep.getBatch()).setFieldsIndex(rep.getFieldsIndex()).setUnit(rep.getUnit()).setSpec(rep.getSpec()).setModel(rep.getModel());
+                ti.setAnfme(rem).setQty(0.0);
+                taskItemService.save(ti);
+                LocItemWorking w = new LocItemWorking();
+                w.setTaskId(pickInTask.getId());
+                w.setLocId(loc.getId());
+                w.setLocCode(loc.getCode());
+                w.setMatnrId(rep.getMatnrId()).setMaktx(rep.getMaktx()).setMatnrCode(rep.getMatnrCode());
+                w.setBatch(rep.getBatch()).setFieldsIndex(rep.getFieldsIndex()).setUnit(rep.getUnit());
+                w.setAnfme(rem);
+                workings.add(w);
+            }
+            if (!workings.isEmpty()) {
+                locItemWorkingService.saveBatch(workings);
+            }
+            loc.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
+            locService.updateById(loc);
+        } else {
+            loc.setUseStatus(LocStsType.LOC_STS_TYPE_O.type);
+            loc.setBarcode(null);
+            loc.setUpdateBy(loginUserId);
+            loc.setUpdateTime(new Date());
+            locService.updateById(loc);
+        }
+        for (Long tid : taskIds) {
+            locItemWorkingService.remove(new LambdaQueryWrapper<LocItemWorking>().eq(LocItemWorking::getTaskId, tid));
+        }
+    }
+
+    /**
      * @author Ryan
      * @date 2025/5/20
      * @description: 瀹屾垚鍑哄簱浠诲姟锛屾洿鏂板嚭搴撳簱瀛樹俊鎭�
@@ -1479,7 +1633,35 @@
         if (Objects.isNull(loc)) {
             throw new CoolException("搴撲綅涓嶅瓨鍦紒锛�");
         }
-        
+
+        // 绌烘澘鍑哄簱锛氭棤浠诲姟鏄庣粏锛屼笉闇�瑕� PDA 鎷h揣纭锛孯CS 鍥炶皟鍚庣洿鎺ュ畬鎴愬簱浣嶆洿鏂板苟缃负 UPDATED_OUT
+        if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)) {
+            List<TaskItem> emptyItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+            if (emptyItems.isEmpty()) {
+                if (!LocStsType.LOC_STS_TYPE_R.type.equals(loc.getUseStatus())) {
+                    log.warn("绌烘澘鍑哄簱浠诲姟{}鐨勫簱浣峽}鐘舵�佷笉鏄疪.鍑哄簱棰勭害锛岃烦杩�", task.getId(), loc.getCode());
+                    return;
+                }
+                if (!locService.update(new LambdaUpdateWrapper<Loc>()
+                        .eq(Loc::getId, loc.getId())
+                        .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+                        .set(Loc::getBarcode, null)
+                        .set(Loc::getUpdateBy, loginUserId)
+                        .set(Loc::getUpdateTime, new Date()))) {
+                    throw new CoolException("绌烘澘鍑哄簱搴撲綅鐘舵�佹洿鏂板け璐ワ紒锛�");
+                }
+                if (!this.update(new LambdaUpdateWrapper<Task>()
+                        .eq(Task::getId, task.getId())
+                        .set(Task::getUpdateBy, loginUserId)
+                        .set(Task::getUpdateTime, new Date())
+                        .set(Task::getTaskStatus, TaskStsType.UPDATED_OUT.id))) {
+                    throw new CoolException("绌烘澘鍑哄簱浠诲姟鐘舵�佹洿鏂板け璐ワ紒锛�");
+                }
+                log.info("[绌烘澘鍑哄簱] 浠诲姟{} RCS鍥炶皟鍚庡凡鐩存帴瀹屾垚搴撲綅鏇存柊锛屾棤闇�PDA纭", task.getTaskCode());
+                return;
+            }
+        }
+
         List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
         if (taskItems.isEmpty()) {
             throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦紒锛�");
@@ -1557,11 +1739,11 @@
                     if (Objects.isNull(waveItem)) {
                         throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
                     }
-//                    try {
-//                        saveOutStockItem(maps.get(key), null, waveItem, null, loginUserId);
-//                    } catch (Exception e) {
-//                        throw new CoolException(e.getMessage());
-//                    }
+                    try {
+                        saveOutStockItem(maps.get(key), null, waveItem, null, loginUserId);
+                    } catch (Exception e) {
+                        throw new CoolException(e.getMessage());
+                    }
                 } else if (task.getResource().equals(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val)) {
                     WkOrderItem orderItem = asnOrderItemService.getById(key);
                     if (Objects.isNull(orderItem)) {
@@ -1596,15 +1778,8 @@
         
         // 鏍规嵁浠诲姟绫诲瀷鏇存柊搴撲綅鐘舵��
         if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
-            /**淇敼涓哄簱浣嶇姸鎬佷负S.棰勭害鍏ュ簱锛屼繚鐣欏師鏈夊簱浣�*/
-            if (!locService.update(new LambdaUpdateWrapper<Loc>()
-                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_S.type)
-                    .set(Loc::getBarcode, null)
-                    .set(Loc::getUpdateBy, loginUserId)
-                    .set(Loc::getUpdateTime, new Date())
-                    .eq(Loc::getId, loc.getId()))) {
-                throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
-            }
+            // 鎷f枡鍑哄簱/鐩樼偣鍑哄簱锛氬湪鏈敓鎴愭嫞鏂欏叆搴撳崟涔嬪墠淇濇寔 R.棰勭害鍑哄簱锛屽惁鍒欎笅鍙戜换鍔℃椂鏌ヤ笉鍒拌搴撲綅锛堝彧鏌� F+R锛夊鑷粹�滃簱瀛樹笉瓒斥��
+            // 绛� PDA 纭骞剁敓鎴愭嫞鏂欏叆搴撲换鍔℃椂锛屽啀鍦� pickOrCheckTask 涓皢鐩爣搴撲綅鏀逛负 S.棰勭害鍏ュ簱
         } else if (task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)) {
             // 鍏ㄧ増鍑哄簱锛氫笉鏇存柊搴撲綅鐘舵�佷负O锛岀瓑寰匬DA蹇�熸嫞璐х‘璁ゆ椂鍐嶆洿鏂�
             // 搴撲綅鐘舵�佷繚鎸佸師鏍凤紙R.鍑哄簱棰勭害鐘舵�侊級
@@ -1627,6 +1802,8 @@
                 .set(Task::getTaskStatus, TaskStsType.WAVE_SEED.id))) {
             throw new CoolException("搴撳瓨鐘舵�佹洿鏂板け璐ワ紒锛�");
         }
+        // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氬嚭搴撳畬鎴愬悗閫氱煡浜戜粨
+        reportInOutResultToCloud(task, loc, taskItems, null, false);
 
 //        if (task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)) {
 //            if (!this.update(new LambdaUpdateWrapper<Task>()
@@ -1687,8 +1864,35 @@
                 .setUpdateTime(new Date())
                 .setAnfme(sum);
         if (!Objects.isNull(waveItem)) {
-            //TODO 鐢熸垚娉㈡鏃堕渶瑕佸皢娉㈡鍙峰啓鍏ュ崟鎹紝閫氳繃鐗╂枡锛屾壒娆★紝鍔ㄦ�佸瓧娈电瓑鍞竴鍊煎弽鏌ュ崟鎹俊鎭�
+            // 娉㈡鍑哄簱锛氭洿鏂板嚭搴撳崟瀹屾垚鏁伴噺鍙婂嚭搴撳崟鏄庣粏鎵ц鏁伴噺
             stock.setSourceId(waveItem.getId()).setType(OrderType.ORDER_OUT.type);
+            Long orderId = waveItem.getOrderId();
+            if (orderId != null) {
+                WkOrder wkOrder = asnOrderService.getById(orderId);
+                if (wkOrder != null) {
+                    Double curQty = wkOrder.getQty() != null ? wkOrder.getQty() : 0.0;
+                    Double newQty = QuantityUtils.roundToScale(curQty + sum);
+                    wkOrder.setExceStatus(AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val).setQty(newQty);
+                    if (!asnOrderService.updateById(wkOrder)) {
+                        throw new CoolException("鍑哄簱鍗曞畬鎴愭暟閲忔洿鏂板け璐ワ紒锛�");
+                    }
+                }
+                // 鎸夊嚭搴撳崟鏄庣粏姹囨�绘湰娆′换鍔℃暟閲忥紝鏇存柊鍚勬槑缁� workQty
+                Map<Long, Double> sumByOrderItemId = taskItems.stream()
+                        .filter(ti -> ti.getOrderItemId() != null)
+                        .collect(Collectors.groupingBy(TaskItem::getOrderItemId,
+                                Collectors.summingDouble(ti -> ti.getAnfme() != null ? ti.getAnfme() : 0.0)));
+                for (Map.Entry<Long, Double> e : sumByOrderItemId.entrySet()) {
+                    WkOrderItem oi = outStockItemService.getById(e.getKey());
+                    if (oi != null) {
+                        Double wq = oi.getWorkQty() != null ? oi.getWorkQty() : 0.0;
+                        oi.setWorkQty(QuantityUtils.roundToScale(wq + e.getValue()));
+                        if (!outStockItemService.updateById(oi)) {
+                            throw new CoolException("鍑哄簱鍗曟槑缁嗘墽琛屾暟閲忔洿鏂板け璐ワ紒锛�");
+                        }
+                    }
+                }
+            }
         } else if (!Objects.isNull(orderItem) && StringUtils.isNotBlank(orderItem.getId() + "")) {
             WkOrder wkOrder = asnOrderService.getById(orderItem.getOrderId());
             Double qty = Math.round((wkOrder.getQty() + sum) * 1000000) / 1000000.0;
@@ -1780,9 +1984,30 @@
                     rcsApi != null ? rcsApi.getPort() : "null");
             return;
         }
-        
+        // 鍚屾枡绠卞彿瑙勫垯锛�101 浠诲姟鎵�鍦ㄦ枡绠卞彿涓嬭嫢宸插瓨鍦� 196/198/199/200 浠诲姟锛屽垯涓嶅悜 RCS 鍙戦�佽 101 浠诲姟锛�/api/open/bus/submit锛�
+        List<Integer> higherStatuses = Arrays.asList(TaskStsType.AWAIT.id, TaskStsType.COMPLETE_OUT.id, TaskStsType.WAVE_SEED.id, TaskStsType.UPDATED_OUT.id);
+        List<Task> higherTasks = this.list(new LambdaQueryWrapper<Task>()
+                .in(Task::getTaskStatus, higherStatuses)
+                .isNotNull(Task::getBarcode)
+                .ne(Task::getBarcode, ""));
+        Set<String> barcodesWithHigher = higherTasks.stream().map(Task::getBarcode).filter(StringUtils::isNotBlank).collect(Collectors.toSet());
+        List<Task> toSend = tasks.stream()
+                .filter(t -> {
+                    if (TaskStsType.GENERATE_OUT.id.equals(t.getTaskStatus()) && StringUtils.isNotBlank(t.getBarcode()) && barcodesWithHigher.contains(t.getBarcode())) {
+                        log.debug("鍚屾枡绠卞彿{}涓嬪凡瀛樺湪196/198/199/200浠诲姟锛岃烦杩�101浠诲姟涓嬪彂锛歵askId={}", t.getBarcode(), t.getId());
+                        return false;
+                    }
+                    return true;
+                })
+                .collect(Collectors.toList());
+        if (toSend.isEmpty()) {
+            log.debug("杩囨护鍚庢棤寰呬笅鍙戜换鍔�");
+            return;
+        }
+        tasks = toSend;
+
         String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
-        
+
         for (Task task : tasks) {
             WcsTaskParams taskParams = new WcsTaskParams();
             List<TaskItemParam> items = new ArrayList<>();
@@ -2213,7 +2438,7 @@
             List<TaskItem> items = orderMap.get(key);
             //淇濆瓨鍏ュ嚭搴撴槑缁�
             saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
-            //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵�侊紙鍙湁褰搒ource涓嶄负null鏃舵墠闇�瑕佺Щ闄ゆ敹璐у尯搴撳瓨锛�
+            // DirectWaitPakin 鍚敤鏃剁粍鎵樻潵鑷敹璐у尯锛屽叆搴撳畬鎴愬悗绉诲嚭鏀惰揣鍖哄簱瀛橈紱鏈惎鐢ㄦ椂 source 涓� null 涓嶆墽琛�
             if (Objects.nonNull(pakinItem.getSource())) {
                 removeReceiptStock(pakinItem, loginUserId);
             }
@@ -2240,6 +2465,8 @@
         if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
             throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
         }
+        // 9.1 鍏�/鍑哄簱缁撴灉涓婃姤锛氬叆搴撳畬鎴愬悗閫氱煡浜戜粨
+        reportInOutResultToCloud(task, loc, taskItems, pkinItemIds, true);
     }
 
     /**
@@ -2311,12 +2538,12 @@
                 locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getBatch).or().eq(LocItem::getBatch, ""));
             }
             
-            // 绁ㄥ彿鍖归厤锛氬鏋渢askItem鏈夌エ鍙凤紝鍒欏繀椤诲尮閰嶏紱濡傛灉taskItem娌℃湁绁ㄥ彿锛屽垯鏌ヨ绁ㄥ彿涓簄ull鎴栫┖瀛楃涓茬殑璁板綍
-            if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) {
-                locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex());
-            } else {
-                locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, ""));
-            }
+            // 绁ㄥ彿鏆備笉浣跨敤锛屼笉鎸夌エ鍙峰尮閰嶏紝鍙煡绁ㄥ彿涓� null 鎴栫┖鐨勫簱浣嶆槑缁�
+            // if (StringUtils.isNotBlank(taskItem.getFieldsIndex())) {
+            //     locItemWrapper.eq(LocItem::getFieldsIndex, taskItem.getFieldsIndex());
+            // } else {
+            locItemWrapper.and(wrapper -> wrapper.isNull(LocItem::getFieldsIndex).or().eq(LocItem::getFieldsIndex, ""));
+            // }
             
             LocItem locItem = locItemService.getOne(locItemWrapper);
             if (Objects.isNull(locItem)) {
@@ -2408,4 +2635,72 @@
             }
         }
     }
+
+    /**
+     * 9.1 鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙
+     * @param isInbound true 鍏ュ簱瀹屾垚锛宖alse 鍑哄簱瀹屾垚
+     * @param pkinItemIds 鍏ュ簱鏃剁粍鎵樻槑缁� ID 闆嗗悎锛岀敤浜庢煡 asnCode 浣滀负 orderNo锛涘嚭搴撴椂浼� null锛岀敤 taskItem.platOrderCode
+     */
+    private void reportInOutResultToCloud(Task task, Loc loc, List<TaskItem> taskItems, Set<Long> pkinItemIds, boolean isInbound) {
+        try {
+            String locId = isInbound ? task.getTargLoc() : task.getOrgLoc();
+            String wareHouseId = null;
+            if (loc.getWarehouseId() != null) {
+                Warehouse wh = warehouseService.getById(loc.getWarehouseId());
+                if (wh != null) {
+                    wareHouseId = wh.getCode();
+                }
+            }
+            if (wareHouseId == null) {
+                log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙璺宠繃锛氫粨搴撶紪鐮佷负绌猴紝taskId={}", task.getId());
+                return;
+            }
+            Map<Long, String> sourceToOrderNo = new HashMap<>();
+            if (isInbound && pkinItemIds != null && !pkinItemIds.isEmpty()) {
+                List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getId, pkinItemIds));
+                for (WaitPakinItem p : pakinItems) {
+                    if (p.getAsnCode() != null) {
+                        sourceToOrderNo.put(p.getId(), p.getAsnCode());
+                    }
+                }
+            }
+            ObjectMapper om = new ObjectMapper();
+            Date now = new Date();
+            for (TaskItem item : taskItems) {
+                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();
+                }
+                if (orderNo == null || item.getMatnrCode() == null) {
+                    continue;
+                }
+                InOutResultReportParam param = new InOutResultReportParam()
+                        .setOrderNo(orderNo)
+                        .setPlanNo(item.getPlatWorkCode())
+                        .setLineId(item.getPlatItemId())
+                        .setWareHouseId(wareHouseId)
+                        .setLocId(locId)
+                        .setMatNr(item.getMatnrCode())
+                        .setQty(item.getAnfme() != null ? String.valueOf(item.getAnfme()) : "0")
+                        .setBatch(item.getBatch());
+                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());
+                }
+            }
+        } catch (Exception e) {
+            log.warn("鍏�/鍑哄簱缁撴灉涓婃姤寰呭姙澶辫触锛宼askId={}锛宨sInbound={}锛歿}", task.getId(), isInbound, e.getMessage());
+        }
+    }
 }

--
Gitblit v1.9.1