From 7114476c50f620866d81de90b96dbffb38d0d648 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期五, 06 二月 2026 13:24:50 +0800
Subject: [PATCH] 出库逻辑微调

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |  134 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 109 insertions(+), 25 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 610b525..5599cb5 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
@@ -1541,7 +1541,9 @@
             if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                 station = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
                 if (Objects.isNull(station)) {
-                    throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+                    log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                    log.error("绔欑偣涓嶅瓨鍦紒锛佷换鍔$紪鐮侊細{}锛岀洰鏍囩珯鐐癸細{}", task.getTaskCode(), task.getTargSite());
+                    continue;
                 }
             }
 
@@ -1550,12 +1552,16 @@
                 if (task.getTaskType() <= TaskType.TASK_TYPE_CHECK_IN.type && !task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                     station.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
                     if (!basStationService.updateById(station)) {
-                        throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛佷换鍔$紪鐮侊細{}锛岀珯鐐癸細{}", task.getTaskCode(), station.getStationName());
+                        continue;
                     }
                 } else if (task.getTaskType() >= TaskType.TASK_TYPE_OUT.type) {
                     station.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
                     if (!basStationService.updateById(station)) {
-                        throw new CoolException("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛�");
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("绔欑偣鐘舵�佹洿鏂板け璐ワ紒锛佷换鍔$紪鐮侊細{}锛岀珯鐐癸細{}", task.getTaskCode(), station.getStationName());
+                        continue;
                     }
                 }
             }
@@ -1578,34 +1584,92 @@
                     || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
                     || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
                     || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type)) {
-                /**鍑哄簱鍙傛暟*/
-                itemParam.setOriLoc(task.getOrgLoc())
-                        .setDestSta(task.getTargSite());
+                /**鍑哄簱鍙傛暟 - 闇�瑕佹牴鎹换鍔℃槑缁嗕腑鐨勫涓簱浣嶈繘琛岀粍瑁�*/
+                // 鏌ヨ浠诲姟鏄庣粏
+                List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+                if (!taskItems.isEmpty()) {
+                    // 閫氳繃TaskItem鐨剆ource瀛楁鏌ヨLocItem锛岃幏鍙栧簱浣嶄俊鎭�
+                    Set<String> locCodes = new HashSet<>();
+                    Map<String, LocItem> locItemMap = new HashMap<>();
+                    
+                    for (TaskItem taskItem : taskItems) {
+                        if (taskItem.getSource() != null) {
+                            // source瀛楁瀵瑰簲LocItem鐨刬d
+                            LocItem locItem = locItemService.getById(taskItem.getSource());
+                            if (locItem != null && StringUtils.isNotBlank(locItem.getLocCode())) {
+                                locCodes.add(locItem.getLocCode());
+                                locItemMap.put(locItem.getLocCode(), locItem);
+                            }
+                        }
+                    }
+                    
+                    // 濡傛灉閫氳繃source娌℃湁鎵惧埌搴撲綅锛屼娇鐢═ask鐨刼rgLoc浣滀负榛樿鍊�
+                    if (locCodes.isEmpty() && StringUtils.isNotBlank(task.getOrgLoc())) {
+                        locCodes.add(task.getOrgLoc());
+                    }
+                    
+                    // 涓烘瘡涓笉鍚岀殑搴撲綅鍒涘缓涓�涓猅askItemParam
+                    for (String locCode : locCodes) {
+                        TaskItemParam outItemParam = new TaskItemParam();
+                        outItemParam.setTaskNo(task.getTaskCode());
+                        outItemParam.setPriority(1);
+                        outItemParam.setOriLoc(locCode);
+                        outItemParam.setDestSta(task.getTargSite());
+                        if (task.getBarcode() != null) {
+                            outItemParam.setZpallet(task.getBarcode());
+                        }
+                        items.add(outItemParam);
+                    }
+                    
+                    log.info("鍑哄簱浠诲姟鍖呭惈{}涓簱浣嶏細{}", locCodes.size(), locCodes);
+                } else {
+                    // 濡傛灉娌℃湁浠诲姟鏄庣粏锛屼娇鐢═ask鐨刼rgLoc
+                    itemParam.setOriLoc(task.getOrgLoc())
+                            .setDestSta(task.getTargSite());
+                    items.add(itemParam);
+                }
             } else {
                 /**绔欑偣闂寸Щ搴撳弬鏁�*/
                 itemParam.setOriSta(task.getOrgSite()).setDestSta(task.getTargSite());
 
                 BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
                 if (Objects.isNull(curSta)) {
-                    throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+                    log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                    log.error("绔欑偣涓嶅瓨鍦紒锛佷换鍔$紪鐮侊細{}锛屾簮绔欑偣锛歿}", task.getTaskCode(), task.getOrgSite());
+                    continue;
                 }
                 if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                     if (!curSta.getUseStatus().equals(LocStsType.LOC_STS_TYPE_F.type)) {
-                        throw new CoolException("褰撳墠绔欑偣涓嶆槸F.鍦ㄥ簱鐘舵�侊紒锛�");
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("褰撳墠绔欑偣涓嶆槸F.鍦ㄥ簱鐘舵�侊紒锛佷换鍔$紪鐮侊細{}锛岀珯鐐癸細{}锛屽綋鍓嶇姸鎬侊細{}", task.getTaskCode(), curSta.getStationName(), curSta.getUseStatus());
+                        continue;
                     }
                 }
                 // 绔欑偣闂寸Щ搴撻渶瑕佽幏鍙栫洰鏍囩珯鐐�
                 BasStation targetStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
                 if (Objects.isNull(targetStation)) {
-                    throw new CoolException("鐩爣绔欑偣涓嶅瓨鍦紒锛�");
+                    log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                    log.error("鐩爣绔欑偣涓嶅瓨鍦紒锛佷换鍔$紪鐮侊細{}锛岀洰鏍囩珯鐐癸細{}", task.getTaskCode(), task.getTargSite());
+                    continue;
                 }
                 if (targetStation.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                     if (!targetStation.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
-                        throw new CoolException("鐩爣绔欑偣涓嶆槸O.绌洪棽鐘舵�侊紒锛�");
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("鐩爣绔欑偣涓嶆槸O.绌洪棽鐘舵�侊紒锛佷换鍔$紪鐮侊細{}锛岀珯鐐癸細{}锛屽綋鍓嶇姸鎬侊細{}", task.getTaskCode(), targetStation.getStationName(), targetStation.getUseStatus());
+                        continue;
                     }
                 }
             }
-            items.add(itemParam);
+            
+            // 瀵逛簬闈炲嚭搴撲换鍔★紝娣诲姞鍗曚釜itemParam
+            if (!(task.getTaskType().equals(TaskType.TASK_TYPE_OUT.type)
+                    || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
+                    || task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_OUT.type)
+                    || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_OUT.type)
+                    || task.getTaskType().equals(TaskType.TASK_TYPE_MERGE_OUT.type))) {
+                items.add(itemParam);
+            }
+            
             taskParams.setTasks(items);
             
             // 璁板綍褰撳墠浠诲姟淇℃伅
@@ -1645,9 +1709,11 @@
                 if (cause instanceof java.net.SocketTimeoutException || 
                     (cause instanceof java.net.ConnectException && cause.getMessage() != null && cause.getMessage().contains("timed out")) ||
                     (errorMsg != null && (errorMsg.contains("Connection timed out") || errorMsg.contains("timed out") || errorMsg.contains("timeout")))) {
-                    throw new CoolException("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛�" + task.getTaskCode() + "锛岄敊璇俊鎭細" + errorMsg);
+                    log.error("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+                } else {
+                    log.error("RCS璧勬簮璁块棶寮傚父锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
                 }
-                throw new CoolException("RCS璧勬簮璁块棶寮傚父锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛�" + task.getTaskCode() + "锛岄敊璇俊鎭細" + errorMsg);
+                continue;
             } catch (Exception e) {
                 long endTime = System.currentTimeMillis();
                 log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
@@ -1657,9 +1723,11 @@
                 String errorMsg = e.getMessage();
                 // 妫�鏌ユ槸鍚︽槸杩炴帴瓒呮椂鐩稿叧鐨勫紓甯�
                 if (errorMsg != null && (errorMsg.contains("Connection timed out") || errorMsg.contains("timed out") || errorMsg.contains("timeout"))) {
-                    throw new CoolException("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛�" + task.getTaskCode() + "锛岄敊璇俊鎭細" + errorMsg);
+                    log.error("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+                } else {
+                    log.error("RCS浠诲姟涓嬪彂寮傚父锛佷换鍔$紪鐮侊細{}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
                 }
-                throw new CoolException("RCS浠诲姟涓嬪彂寮傚父锛佷换鍔$紪鐮侊細" + task.getTaskCode() + "锛岄敊璇俊鎭細" + errorMsg);
+                continue;
             }
             
             if (Objects.isNull(exchange) || Objects.isNull(exchange.getBody())) {
@@ -1668,7 +1736,8 @@
                 log.error("璇锋眰RCS-鍦板潃锛歿}", pubTakUrl);
                 log.error("璇锋眰RCS-鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
                 log.error("璇锋眰RCS-澶辫触鐨勪换鍔$紪鐮侊細{}", task.getTaskCode());
-                throw new CoolException("浠诲姟涓嬪彂澶辫触锛孯CS鍝嶅簲浣撲负绌猴紒锛佷换鍔$紪鐮侊細" + task.getTaskCode());
+                log.error("浠诲姟涓嬪彂澶辫触锛孯CS鍝嶅簲浣撲负绌猴紒锛佷换鍔$紪鐮侊細{}", task.getTaskCode());
+                continue;
             } else {
                 try {
                     ObjectMapper objectMapper = new ObjectMapper();
@@ -1688,13 +1757,17 @@
 
                             BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getOrgSite()));
                             if (Objects.isNull(curSta)) {
-                                throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+                                log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                                log.error("绔欑偣涓嶅瓨鍦紒锛佷换鍔$紪鐮侊細{}锛屾簮绔欑偣锛歿}", task.getTaskCode(), task.getOrgSite());
+                                continue;
                             }
 
                             log.info("鏇存柊鍏ュ簱浠诲姟鐘舵�� - 浠诲姟缂栫爜锛歿}锛屾柊鐘舵�侊細{}", task.getTaskCode(), TaskStsType.WCS_EXECUTE_IN.id);
                             if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
                                     .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_IN.id))) {
-                                throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+                                log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                                log.error("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛佷换鍔$紪鐮侊細{}", task.getTaskCode());
+                                continue;
                             }
                             log.info("鍏ュ簱浠诲姟鐘舵�佹洿鏂版垚鍔� - 浠诲姟缂栫爜锛歿}", task.getTaskCode());
                             /**鎺掗櫎绉诲簱鍔熻兘*/
@@ -1703,7 +1776,9 @@
                                 if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                                     curSta.setUseStatus(LocStsType.LOC_STS_TYPE_R.type);
                                     if (!basStationService.updateById(curSta)) {
-                                        throw new CoolException("绔欑偣棰勭害澶辫触锛侊紒");
+                                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                                        log.error("绔欑偣棰勭害澶辫触锛侊紒浠诲姟缂栫爜锛歿}锛岀珯鐐癸細{}", task.getTaskCode(), curSta.getStationName());
+                                        continue;
                                     }
                                 }
                             }
@@ -1714,20 +1789,26 @@
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)) {
                             BasStation curSta = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
                             if (Objects.isNull(curSta)) {
-                                throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
+                                log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                                log.error("绔欑偣涓嶅瓨鍦紒锛佷换鍔$紪鐮侊細{}锛岀洰鏍囩珯鐐癸細{}", task.getTaskCode(), task.getTargSite());
+                                continue;
                             }
 
                             log.info("鏇存柊鍑哄簱浠诲姟鐘舵�� - 浠诲姟缂栫爜锛歿}锛屾柊鐘舵�侊細{}", task.getTaskCode(), TaskStsType.WCS_EXECUTE_OUT.id);
                             if (!taskService.update(new LambdaUpdateWrapper<Task>().eq(Task::getTaskCode, task.getTaskCode())
                                     .set(Task::getTaskStatus, TaskStsType.WCS_EXECUTE_OUT.id))) {
-                                throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+                                log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                                log.error("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛佷换鍔$紪鐮侊細{}", task.getTaskCode());
+                                continue;
                             }
                             log.info("鍑哄簱浠诲姟鐘舵�佹洿鏂版垚鍔� - 浠诲姟缂栫爜锛歿}", task.getTaskCode());
                             /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍏ュ簱棰勭害*/
                             if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                                 curSta.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
                                 if (!basStationService.updateById(curSta)) {
-                                    throw new CoolException("绔欑偣棰勭害澶辫触锛侊紒");
+                                    log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                                    log.error("绔欑偣棰勭害澶辫触锛侊紒浠诲姟缂栫爜锛歿}锛岀珯鐐癸細{}", task.getTaskCode(), curSta.getStationName());
+                                    continue;
                                 }
                             }
                         }
@@ -1736,16 +1817,19 @@
                         log.error("RCS杩斿洖閿欒 - code锛歿}锛宮sg锛歿}锛宒ata锛歿}", 
                                 result.getCode(), result.getMsg(), result.getData());
                         log.error("澶辫触鐨勪换鍔$紪鐮侊細{}锛屼换鍔$被鍨嬶細{}", task.getTaskCode(), task.getTaskType());
-                        throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒浠诲姟缂栫爜锛�" + task.getTaskCode());
+                        log.error("浠诲姟涓嬪彂澶辫触锛侊紒浠诲姟缂栫爜锛歿}", task.getTaskCode());
+                        continue;
                     }
                 } catch (JsonProcessingException e) {
                     log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
                     log.error("瑙f瀽RCS鍝嶅簲澶辫触锛屽搷搴斾綋锛歿}锛屼换鍔$紪鐮侊細{}", exchange.getBody(), task.getTaskCode(), e);
-                    throw new CoolException("瑙f瀽RCS鍝嶅簲澶辫触锛�" + e.getMessage() + "锛屼换鍔$紪鐮侊細" + task.getTaskCode());
+                    log.error("瑙f瀽RCS鍝嶅簲澶辫触锛歿}锛屼换鍔$紪鐮侊細{}", e.getMessage(), task.getTaskCode());
+                    continue;
                 } catch (Exception e) {
                     log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
                     log.error("浠诲姟涓嬪彂杩囩▼涓彂鐢熷紓甯革紝浠诲姟缂栫爜锛歿}", task.getTaskCode(), e);
-                    throw e;
+                    log.error("浠诲姟涓嬪彂寮傚父锛歿}锛屼换鍔$紪鐮侊細{}", e.getMessage(), task.getTaskCode());
+                    continue;
                 }
             }
         }

--
Gitblit v1.9.1