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 |  578 +++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 435 insertions(+), 143 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 8d152ad..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
@@ -19,6 +19,7 @@
 import com.vincent.rsf.server.api.service.WcsService;
 import com.vincent.rsf.server.common.constant.Constants;
 import com.vincent.rsf.server.manager.controller.params.LocToTaskParams;
+import com.vincent.rsf.server.manager.controller.params.PakinItem;
 import com.vincent.rsf.server.manager.enums.*;
 import com.vincent.rsf.framework.common.R;
 import com.vincent.rsf.framework.exception.CoolException;
@@ -453,25 +454,21 @@
      * @throws Exception
      */
     @Override
-    public void complateInTask(List<Task> tasks) throws Exception {
+    public void complateInTask(List<Task> tasks) {
         AtomicBoolean success = new AtomicBoolean(false);
         if (success.compareAndSet(false, true)) {
             Long loginUserId = SystemAuthUtils.getLoginUserId();
             for (Task task : tasks) {
-                try {
-                    if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
-                        //1.鍏ュ簱
-                        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.鐩樼偣鍐嶅叆搴�
-                        pickComplateInStock(task, loginUserId);
-                    } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
-                        //绉诲簱
-                        moveInStock(task, loginUserId);
-                    }
-                } catch (Exception ex) {
-                    log.error(ex.getMessage(), ex);
+                if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
+                    //1.鍏ュ簱
+                    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.鐩樼偣鍐嶅叆搴�
+                    pickComplateInStock(task, loginUserId);
+                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
+                    //绉诲簱
+                    moveInStock(task, loginUserId);
                 }
             }
         }
@@ -707,7 +704,7 @@
      * @param loginUserId
      */
     @Transactional(rollbackFor = Exception.class)
-    public void pickComplateInStock(Task task, Long loginUserId) throws Exception {
+    public void pickComplateInStock(Task task, Long loginUserId) {
         if (Objects.isNull(task)) {
             return;
         }
@@ -746,12 +743,15 @@
                 locWorking.setAnfme(taskItem.getAnfme());
             }
             BeanUtils.copyProperties(locWorking, locItem);
-            locItem.setWorkQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
-            items.add(locItem);
+            locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
+            //鏁伴噺涓洪浂鐨勪笉鍏ュ簱
+            if (locItem.getAnfme().compareTo(0.0) > 0) {
+                items.add(locItem);
+            }
         }
 
         if (!locItemService.saveBatch(items)) {
-            throw new CoolException("浣滀笟搴撳瓨鍥炲啓澶辫触锛侊紒");
+//            throw new CoolException("浣滀笟搴撳瓨鍥炲啓澶辫触锛侊紒");
         }
 
         TaskItem taskItem = taskItems.stream().findFirst().get();
@@ -777,16 +777,132 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public R removeTask(Long[] ids, Long loginUserId) {
-        List<Integer> longs = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id);
+        // 鍏堟煡璇㈡墍鏈変换鍔★紙涓嶉檺鍒剁姸鎬侊級锛岀敤浜庢鏌CS浠诲姟
         List<Integer> list = Arrays.asList(TaskType.TASK_TYPE_IN.type, TaskType.TASK_TYPE_OUT.type, TaskType.TASK_TYPE_PICK_AGAIN_OUT.type,
                 TaskType.TASK_TYPE_CHECK_OUT.type, TaskType.TASK_TYPE_EMPITY_IN.type, TaskType.TASK_TYPE_LOC_MOVE.type,
                 TaskType.TASK_TYPE_EMPITY_OUT.type, TaskType.TASK_TYPE_MERGE_OUT.type);
+        List<Task> allTasks = this.list(new LambdaQueryWrapper<Task>()
+                .in(Task::getTaskType, list)
+                .in(Task::getId, (Object[]) ids));
+        
+        if (allTasks.isEmpty()) {
+            throw new CoolException("浠诲姟涓嶅瓨鍦紒锛�");
+        }
+        
+        // 鏀堕泦闇�瑕佸彇娑堢殑RCS浠诲姟缂栧彿鍜屾壒娆$紪鍙凤紙涓嶉檺鍒剁姸鎬侊紝鍙宸蹭笅鍙戝埌RCS灏遍渶瑕佸彇娑堬級
+        List<String> rcsTaskCodes = new ArrayList<>();
+        String batchNo = null;
+        for (Task task : allTasks) {
+            // 鍒ゆ柇浠诲姟鏄惁宸蹭笅鍙戝埌RCS
+            // 鍏ュ簱浠诲姟锛氱姸鎬� >= WCS_EXECUTE_IN(2) 琛ㄧず宸蹭笅鍙�
+            // 鍑哄簱浠诲姟锛氱姸鎬� >= WCS_EXECUTE_OUT(102) 琛ㄧず宸蹭笅鍙�
+            boolean isRcsTask = false;
+            if (task.getTaskType() < 100) {
+                // 鍏ュ簱浠诲姟
+                if (task.getTaskStatus() >= TaskStsType.WCS_EXECUTE_IN.id) {
+                    isRcsTask = true;
+                }
+            } else {
+                // 鍑哄簱浠诲姟
+                if (task.getTaskStatus() >= TaskStsType.WCS_EXECUTE_OUT.id) {
+                    isRcsTask = true;
+                }
+            }
+            
+            if (isRcsTask && StringUtils.isNotBlank(task.getTaskCode())) {
+                rcsTaskCodes.add(task.getTaskCode());
+                // 鑾峰彇鎵规缂栧彿锛屼紭鍏堜娇鐢ㄤ换鍔$殑barcode锛屽鏋滄病鏈夊垯浣跨敤浠诲姟缂栧彿
+                if (StringUtils.isBlank(batchNo)) {
+                    if (StringUtils.isNotBlank(task.getBarcode())) {
+                        batchNo = task.getBarcode();
+                    } else if (StringUtils.isNotBlank(task.getTaskCode())) {
+                        // 濡傛灉浠诲姟娌℃湁barcode锛屼娇鐢ㄤ换鍔$紪鍙蜂綔涓烘壒娆$紪鍙�
+                        batchNo = task.getTaskCode();
+                    }
+                }
+                log.info("浠诲姟宸蹭笅鍙戝埌RCS锛岄渶瑕佸彇娑圧CS浠诲姟 - 浠诲姟ID锛歿}锛屼换鍔$紪鍙凤細{}锛屼换鍔$姸鎬侊細{}锛屾墭鐩樼爜锛歿}", 
+                        task.getId(), task.getTaskCode(), task.getTaskStatus(), task.getBarcode());
+            }
+        }
+        
+        // 濡傛灉鏈変换鍔″凡涓嬪彂鍒癛CS锛屽厛璋冪敤RCS鍙栨秷鎺ュ彛
+        boolean rcsCancelSuccess = false;
+        if (!rcsTaskCodes.isEmpty()) {
+            try {
+                log.info("========== 寮�濮嬪彇娑圧CS浠诲姟 ==========");
+                log.info("闇�瑕佸彇娑堢殑RCS浠诲姟缂栧彿锛歿}", rcsTaskCodes);
+                String rcsUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.cancelTask;
+                log.info("RCS鍙栨秷浠诲姟璇锋眰鍦板潃锛歿}", rcsUrl);
+                
+                // 濡傛灉娌℃湁鎵规缂栧彿锛屼娇鐢ㄧ涓�涓换鍔$紪鍙蜂綔涓烘壒娆$紪鍙�
+                if (StringUtils.isBlank(batchNo) && !rcsTaskCodes.isEmpty()) {
+                    batchNo = rcsTaskCodes.get(0);
+                }
+                
+                Map<String, Object> cancelParams = new HashMap<>();
+                cancelParams.put("tasks", rcsTaskCodes);
+                if (StringUtils.isNotBlank(batchNo)) {
+                    cancelParams.put("batchNo", batchNo);
+                }
+                
+                log.info("RCS鍙栨秷浠诲姟璇锋眰鍙傛暟锛歿}", JSONObject.toJSONString(cancelParams));
+                
+                HttpHeaders headers = new HttpHeaders();
+                headers.add("Content-Type", "application/json");
+                headers.add("api-version", "v2.0");
+                HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(cancelParams, headers);
+                
+                long startTime = System.currentTimeMillis();
+                ResponseEntity<String> exchange = restTemplate.exchange(rcsUrl, HttpMethod.POST, httpEntity, String.class);
+                long endTime = System.currentTimeMillis();
+                
+                log.info("RCS鍙栨秷浠诲姟鍝嶅簲鑰楁椂锛歿}ms", (endTime - startTime));
+                log.info("RCS鍙栨秷浠诲姟鍝嶅簲鐘舵�佺爜锛歿}", exchange.getStatusCode());
+                log.info("RCS鍙栨秷浠诲姟鍝嶅簲浣擄細{}", exchange.getBody());
+                
+                if (Objects.isNull(exchange.getBody())) {
+                    log.error("RCS鍙栨秷浠诲姟澶辫触锛氬搷搴斾綋涓虹┖");
+                    throw new CoolException("RCS鍙栨秷浠诲姟澶辫触锛氬搷搴斾綋涓虹┖");
+                }
+                
+                ObjectMapper objectMapper = new ObjectMapper();
+                objectMapper.coercionConfigDefaults()
+                        .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                
+                if (result.getCode() == 200) {
+                    log.info("========== RCS浠诲姟鍙栨秷鎴愬姛 ==========");
+                    log.info("鎴愬姛鍙栨秷鐨凴CS浠诲姟缂栧彿锛歿}", rcsTaskCodes);
+                    rcsCancelSuccess = true;
+                } else {
+                    log.error("RCS鍙栨秷浠诲姟澶辫触锛歿}", result.getMsg());
+                    throw new CoolException("RCS鍙栨秷浠诲姟澶辫触锛�" + result.getMsg());
+                }
+            } catch (JsonProcessingException e) {
+                log.error("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛歿}", e.getMessage(), e);
+                throw new CoolException("RCS鍙栨秷浠诲姟鍝嶅簲瑙f瀽澶辫触锛�" + e.getMessage());
+            } catch (Exception e) {
+                log.error("RCS鍙栨秷浠诲姟寮傚父锛歿}", e.getMessage(), e);
+                throw new CoolException("RCS鍙栨秷浠诲姟寮傚父锛�" + e.getMessage());
+            }
+        }
+        
+        // 鏌ヨ绗﹀悎鍙栨秷鏉′欢鐨勪换鍔★紙鐘舵�佷负1銆�101銆�199锛�
+        List<Integer> allowedStatuses = Arrays.asList(TaskStsType.GENERATE_IN.id, TaskStsType.GENERATE_OUT.id, TaskStsType.WAVE_SEED.id);
         List<Task> tasks = this.list(new LambdaQueryWrapper<Task>()
                 .in(Task::getTaskType, list)
-                .in(Task::getId, ids)
-                .in(Task::getTaskStatus, longs));
-        if (tasks.isEmpty()) {
+                .in(Task::getId, (Object[]) ids)
+                .in(Task::getTaskStatus, allowedStatuses));
+        
+        // 濡傛灉绗﹀悎鍙栨秷鏉′欢鐨勪换鍔′负绌猴紝浣哛CS鍙栨秷鎴愬姛锛屽厑璁哥户缁紙鍙兘鏄换鍔$姸鎬佸凡鍙樻洿锛�
+        if (tasks.isEmpty() && !rcsCancelSuccess) {
             throw new CoolException("浠诲姟宸插鎵ц鐘舵�佷笉鍙彇娑堬紒锛�");
+        }
+        
+        // 濡傛灉绗﹀悎鍙栨秷鏉′欢鐨勪换鍔′负绌猴紝浣哛CS鍙栨秷鎴愬姛锛岃褰曟棩蹇楀苟杩斿洖
+        if (tasks.isEmpty() && rcsCancelSuccess) {
+            log.warn("WMS鍐呴儴浠诲姟鐘舵�佷笉绗﹀悎鍙栨秷鏉′欢锛屼絾RCS浠诲姟宸叉垚鍔熷彇娑� - 浠诲姟ID锛歿}", Arrays.toString(ids));
+            return R.ok("RCS浠诲姟宸插彇娑堬紝WMS鍐呴儴浠诲姟鐘舵�佸凡鍙樻洿");
         }
         for (Task task : tasks) {
             //鍙栨秷绉诲簱浠诲姟
@@ -1020,17 +1136,18 @@
                 .setBarcode(task.getBarcode())
                 .setTaskStatus(TaskStsType.GENERATE_IN.id);
 
-        TaskInParam param = new TaskInParam();
-        param.setSourceStaNo(task.getTargSite())
-                .setIoType(type)
-                .setLocType1(Integer.parseInt(loc.getType()));
+//        TaskInParam param = new TaskInParam();
+//        param.setSourceStaNo(task.getTargSite())
+//                .setIoType(type)
+//                .setLocType1(Integer.parseInt(loc.getType()));
         //鑾峰彇鏂板簱浣�
-        InTaskMsgDto locInfo = wcsService.getLocNo(param);
+//        InTaskMsgDto locInfo = wcsService.getLocNo(param);
 
-        if (Objects.isNull(locInfo)) {
-            throw new CoolException("鑾峰彇搴撲綅澶辫触锛侊紒");
-        }
-        task.setTargLoc(locInfo.getLocNo())
+//        if (Objects.isNull(locInfo)) {
+//            throw new CoolException("鑾峰彇搴撲綅澶辫触锛侊紒");
+//        }
+        //甯屾棩涓婃姤鐗╂湁鎯呭喌锛屼笉闇�瑕佽幏鍙栨柊搴撲綅
+        task.setTargLoc(task.getOrgLoc())
                 .setOrgSite(task.getTargSite());
 
         if (!this.updateById(task)) {
@@ -1075,7 +1192,6 @@
             TaskItem taskItem = taskItems.stream().findFirst().get();
             taskItem.setMatnrId(working.getMatnrId())
                     .setMaktx(working.getMaktx())
-                    .setMatnrId(working.getMatnrId())
                     .setMatnrCode(working.getMatnrCode())
                     .setSpec(working.getSpec())
                     .setAnfme(working.getAnfme())
@@ -1100,26 +1216,25 @@
         List<LocItemWorking> workings = new ArrayList<>();
         List<TaskItem> items = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
         items.forEach(taskItem -> {
-            if (taskItem.getAnfme() > 0) {
-                LocItemWorking itemWorking = new LocItemWorking();
-                BeanUtils.copyProperties(taskItem, itemWorking);
-                itemWorking.setTaskId(task.getId())
-                        .setQty(0.0)
-                        .setLocId(loc1.getId())
-                        .setLocCode(loc1.getCode());
-                workings.add(itemWorking);
-            }
+            LocItemWorking itemWorking = new LocItemWorking();
+            BeanUtils.copyProperties(taskItem, itemWorking);
+            itemWorking.setTaskId(task.getId())
+                    .setQty(0.0)
+                    .setLocId(loc1.getId())
+                    .setLocCode(loc1.getCode());
+            workings.add(itemWorking);
         });
 
-        if (!locItemWorkingService.saveBatch(workings)) {
-            throw new CoolException("涓存椂搴撳瓨鏇存柊澶辫触锛侊紒");
+        if (!workings.isEmpty()) {
+            if (!locItemWorkingService.saveBatch(workings)) {
+                throw new CoolException("涓存椂搴撳瓨鏇存柊澶辫触锛侊紒");
+            }
         }
-
         loc1.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
-
-        if (!locService.updateById(loc1)) {
-            throw new CoolException("搴撲綅棰勭害鍏ュ簱澶辫触锛侊紒");
-        }
+        locService.updateById(loc1);
+//        if (!locService.updateById(loc1)) {
+//            throw new CoolException("搴撲綅棰勭害鍏ュ簱澶辫触锛侊紒");
+//        }
         return task;
     }
 
@@ -1131,7 +1246,7 @@
      */
     @Synchronized
     @Transactional(rollbackFor = Exception.class)
-    public void complateOutStock(Task task, Long loginUserId) throws Exception {
+    public void complateOutStock(Task task, Long loginUserId) {
         if (Objects.isNull(task)) {
             throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
@@ -1228,15 +1343,26 @@
                 throw new CoolException(e.getMessage());
             }
         }
-
-        /**淇敼涓哄簱浣嶇姸鎬佷负O.绌哄簱*/
-        if (!locService.update(new LambdaUpdateWrapper<Loc>()
-                .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
-                .set(Loc::getBarcode, null)
-                .set(Loc::getUpdateBy, loginUserId)
-                .set(Loc::getUpdateTime, new Date())
-                .eq(Loc::getId, loc.getId()))) {
-            throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+        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("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+            }
+        } else {
+            /**淇敼涓哄簱浣嶇姸鎬佷负O.绌哄簱*/
+            if (!locService.update(new LambdaUpdateWrapper<Loc>()
+                    .set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_O.type)
+                    .set(Loc::getBarcode, null)
+                    .set(Loc::getUpdateBy, loginUserId)
+                    .set(Loc::getUpdateTime, new Date())
+                    .eq(Loc::getId, loc.getId()))) {
+                throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+            }
         }
 
         if (!this.update(new LambdaUpdateWrapper<Task>()
@@ -1390,20 +1516,34 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void pubTaskToWcs(List<Task> tasks) {
-        WcsTaskParams taskParams = new WcsTaskParams();
-        List<TaskItemParam> items = new ArrayList<>();
-        tasks.forEach(task -> {
+        /**浠诲姟涓嬪彂鎺ュ彛*/
+        String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
+        
+        for (Task task : tasks) {
+            WcsTaskParams taskParams = new WcsTaskParams();
+            List<TaskItemParam> items = new ArrayList<>();
+            
+            // 璁剧疆鎵规缂栧彿锛堜娇鐢ㄥ綋鍓嶄换鍔$殑浠诲姟缂栫爜锛�
+            String batchNo = task.getTaskCode();
+            if (StringUtils.isBlank(batchNo)) {
+                // 濡傛灉浠诲姟缂栧彿涓虹┖锛岀敓鎴愪竴涓粯璁ゅ��
+                batchNo = "BATCH_" + System.currentTimeMillis();
+            }
+            taskParams.setBatchNo(batchNo);
+            log.info("浠诲姟鎵规缂栧彿锛歿}", batchNo);
+            
+            // 鏋勫缓褰撳墠浠诲姟鐨勫弬鏁�
             TaskItemParam itemParam = new TaskItemParam();
-            //浠诲姟绫诲瀷锛屼换鍔$紪鐮�
-            itemParam.setTaskType(RcsTaskType.getTypeDesc(task.getTaskType()))
-                    .setSeqNum(task.getTaskCode());
-            //涓诲弬鏁�
-            taskParams.setBatch(task.getBarcode());
+            //浠诲姟缂栫爜锛堝搴攕eqNum锛�
+            itemParam.setTaskNo(task.getTaskCode());
+            itemParam.setPriority(1);
             BasStation station = null;
             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;
                 }
             }
 
@@ -1412,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;
                     }
                 }
             }
@@ -1440,52 +1584,170 @@
                     || 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;
                     }
                 }
-                if (station.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
-                    if (!station.getUseStatus().equals(LocStsType.LOC_STS_TYPE_O.type)) {
-                        throw new CoolException("鐩爣绔欑偣涓嶆槸O.绌洪棽鐘舵�侊紒锛�");
+                // 绔欑偣闂寸Щ搴撻渶瑕佽幏鍙栫洰鏍囩珯鐐�
+                BasStation targetStation = basStationService.getOne(new LambdaQueryWrapper<BasStation>().eq(BasStation::getStationName, task.getTargSite()));
+                if (Objects.isNull(targetStation)) {
+                    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)) {
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("鐩爣绔欑偣涓嶆槸O.绌洪棽鐘舵�侊紒锛佷换鍔$紪鐮侊細{}锛岀珯鐐癸細{}锛屽綋鍓嶇姸鎬侊細{}", task.getTaskCode(), targetStation.getStationName(), targetStation.getUseStatus());
+                        continue;
                     }
                 }
             }
-            items.add(itemParam);
-        });
-        taskParams.setTaskList(items);
-        /**浠诲姟涓嬪彂鎺ュ彛*/
-        String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
-        /**RCS鍩虹閰嶇疆閾炬帴*/
-        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl, JSONObject.toJSONString(taskParams));
-        HttpHeaders headers = new HttpHeaders();
-        headers.add("Content-Type", "application/json");
-        headers.add("api-version", "v2.0");
-        HttpEntity httpEntity = new HttpEntity(taskParams, headers);
-        ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class);
-        log.info("浠诲姟涓嬪彂鍚庯紝鍝嶅簲缁撴灉锛� {}", exchange);
-        if (Objects.isNull(exchange.getBody())) {
-            throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
-        } else {
-            try {
-                ObjectMapper objectMapper = new ObjectMapper();
-                objectMapper.coercionConfigDefaults()
-                        .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
-                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
-                if (result.getCode() == 200) {
-                    tasks.forEach(task -> {
+            
+            // 瀵逛簬闈炲嚭搴撲换鍔★紝娣诲姞鍗曚釜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);
+            
+            // 璁板綍褰撳墠浠诲姟淇℃伅
+            log.info("  RCS- 浠诲姟缂栫爜锛歿}锛屼换鍔$被鍨嬶細{}锛屾簮搴撲綅锛歿}锛岀洰鏍囧簱浣嶏細{}锛屾簮绔欑偣锛歿}锛岀洰鏍囩珯鐐癸細{}",
+                    task.getTaskCode(), task.getTaskType(), task.getOrgLoc(), 
+                    task.getTargLoc(), task.getOrgSite(), task.getTargSite());
+            log.info("RCS-璇锋眰鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
+            
+            // 鍙戦�佸綋鍓嶄换鍔�
+            HttpHeaders headers = new HttpHeaders();
+            headers.add("Content-Type", "application/json");
+            headers.add("api-version", "v2.0");
+            HttpEntity httpEntity = new HttpEntity(taskParams, headers);
 
+            /**RCS鍩虹閰嶇疆閾炬帴*/
+            log.info("========== 寮�濮嬩笅鍙戜换鍔″埌RCS ==========");
+            log.info("璇锋眰RCS-鍦板潃锛歿}", pubTakUrl);
+            log.info("璇锋眰RCS-鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
+            long startTime = System.currentTimeMillis();
+            ResponseEntity<String> exchange = null;
+            try {
+                exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class);
+                long endTime = System.currentTimeMillis();
+                log.info("RCS鍝嶅簲鑰楁椂锛歿}ms", (endTime - startTime));
+                log.info("RCS鍝嶅簲鐘舵�佺爜锛歿}", exchange.getStatusCode());
+                log.info("RCS鍝嶅簲澶达細{}", exchange.getHeaders());
+                log.info("RCS鍝嶅簲浣擄細{}", exchange.getBody());
+            } catch (org.springframework.web.client.ResourceAccessException e) {
+                long endTime = System.currentTimeMillis();
+                log.error("========== RCS浠诲姟涓嬪彂璧勬簮璁块棶寮傚父 ==========");
+                log.error("璇锋眰RCS-璧勬簮璁块棶寮傚父锛堝彲鑳藉寘鍚繛鎺ヨ秴鏃讹級锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}", (endTime - startTime), task.getTaskCode(), e);
+                log.error("璇锋眰RCS-璇锋眰鍦板潃锛歿}", pubTakUrl);
+                log.error("璇锋眰RCS-璇锋眰鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
+                // 妫�鏌ユ槸鍚︽槸杩炴帴瓒呮椂寮傚父
+                Throwable cause = e.getCause();
+                String errorMsg = e.getMessage();
+                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")))) {
+                    log.error("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+                } else {
+                    log.error("RCS璧勬簮璁块棶寮傚父锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+                }
+                continue;
+            } catch (Exception e) {
+                long endTime = System.currentTimeMillis();
+                log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
+                log.error("璇锋眰RCS-寮傚父锛岃�楁椂锛歿}ms锛屼换鍔$紪鐮侊細{}", (endTime - startTime), task.getTaskCode(), e);
+                log.error("璇锋眰RCS-鍦板潃锛歿}", pubTakUrl);
+                log.error("璇锋眰RCS-鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
+                String errorMsg = e.getMessage();
+                // 妫�鏌ユ槸鍚︽槸杩炴帴瓒呮椂鐩稿叧鐨勫紓甯�
+                if (errorMsg != null && (errorMsg.contains("Connection timed out") || errorMsg.contains("timed out") || errorMsg.contains("timeout"))) {
+                    log.error("RCS杩炴帴瓒呮椂锛屼换鍔′笅鍙戝け璐ワ紒浠诲姟缂栫爜锛歿}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+                } else {
+                    log.error("RCS浠诲姟涓嬪彂寮傚父锛佷换鍔$紪鐮侊細{}锛岄敊璇俊鎭細{}", task.getTaskCode(), errorMsg);
+                }
+                continue;
+            }
+            
+            if (Objects.isNull(exchange) || Objects.isNull(exchange.getBody())) {
+                log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                log.error("璇锋眰RCS-RCS鍝嶅簲浣撲负绌猴紝鏃犳硶瑙f瀽鍝嶅簲缁撴灉");
+                log.error("璇锋眰RCS-鍦板潃锛歿}", pubTakUrl);
+                log.error("璇锋眰RCS-鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
+                log.error("璇锋眰RCS-澶辫触鐨勪换鍔$紪鐮侊細{}", task.getTaskCode());
+                log.error("浠诲姟涓嬪彂澶辫触锛孯CS鍝嶅簲浣撲负绌猴紒锛佷换鍔$紪鐮侊細{}", task.getTaskCode());
+                continue;
+            } else {
+                try {
+                    ObjectMapper objectMapper = new ObjectMapper();
+                    objectMapper.coercionConfigDefaults()
+                            .setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+                    CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                    log.info("RCS鍝嶅簲瑙f瀽缁撴灉 - code锛歿}锛宮sg锛歿}锛宒ata锛歿}",
+                            result.getCode(), result.getMsg(), result.getData());
+                    if (result.getCode() == 200) {
+                        log.info("RCS浠诲姟涓嬪彂鎴愬姛锛屽紑濮嬫洿鏂颁换鍔$姸鎬� - 浠诲姟缂栫爜锛歿}", task.getTaskCode());
                         if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_PICK_IN.type)
                                 || task.getTaskType().equals(TaskType.TASK_TYPE_CHECK_IN.type)
@@ -1495,20 +1757,28 @@
 
                             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());
                             /**鎺掗櫎绉诲簱鍔熻兘*/
                             if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                                 /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍑哄簱棰勭害*/
                                 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;
                                     }
                                 }
                             }
@@ -1519,31 +1789,51 @@
                                 || 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;
                                 }
                             }
                         }
-                    });
-                } else {
-                    log.error(JSONObject.toJSONString(result));
-//                    throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+                    } else {
+                        log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                        log.error("RCS杩斿洖閿欒 - code锛歿}锛宮sg锛歿}锛宒ata锛歿}", 
+                                result.getCode(), result.getMsg(), result.getData());
+                        log.error("澶辫触鐨勪换鍔$紪鐮侊細{}锛屼换鍔$被鍨嬶細{}", task.getTaskCode(), task.getTaskType());
+                        log.error("浠诲姟涓嬪彂澶辫触锛侊紒浠诲姟缂栫爜锛歿}", task.getTaskCode());
+                        continue;
+                    }
+                } catch (JsonProcessingException e) {
+                    log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
+                    log.error("瑙f瀽RCS鍝嶅簲澶辫触锛屽搷搴斾綋锛歿}锛屼换鍔$紪鐮侊細{}", exchange.getBody(), task.getTaskCode(), e);
+                    log.error("瑙f瀽RCS鍝嶅簲澶辫触锛歿}锛屼换鍔$紪鐮侊細{}", e.getMessage(), task.getTaskCode());
+                    continue;
+                } catch (Exception e) {
+                    log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
+                    log.error("浠诲姟涓嬪彂杩囩▼涓彂鐢熷紓甯革紝浠诲姟缂栫爜锛歿}", task.getTaskCode(), e);
+                    log.error("浠诲姟涓嬪彂寮傚父锛歿}锛屼换鍔$紪鐮侊細{}", e.getMessage(), task.getTaskCode());
+                    continue;
                 }
-            } catch (JsonProcessingException e) {
-                throw new CoolException(e.getMessage());
             }
         }
-
+        log.info("========== RCS浠诲姟涓嬪彂瀹屾垚锛屽叡{}涓换鍔″凡澶勭悊 ==========", tasks.size());
     }/**
 
 
@@ -1585,12 +1875,9 @@
         if (taskItems.isEmpty()) {
             throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦紒锛�");
         }
-        try {
-            //鏇存柊搴撲綅鏄庣粏
-            saveLocItem(taskItems, task.getId(), loginUserId);
-        } catch (Exception e) {
-            throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
-        }
+
+        //鏇存柊搴撲綅鏄庣粏
+        saveLocItem(taskItems, task.getId(), loginUserId);
 
         /**瀵逛换鍔℃槑缁嗘寜缁勬嫋鏄庣粏杩涜鍒嗙粍*/
         Map<Long, List<TaskItem>> orderMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
@@ -1600,16 +1887,26 @@
                 throw new CoolException("鏁版嵁閿欒锛氱粍鎷栨暟鎹笉瀛樺湪锛岃鑱旂郴绠$悊鍛橈紒锛�");
             }
             List<TaskItem> items = orderMap.get(key);
-            try {
-                //淇濆瓨搴撳瓨鏄庣粏
-                saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
-                //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵��
-                removeReceiptStock(pakinItem, loginUserId);
-            } catch (Exception e) {
-                logger.error("<UNK>", e);
-                throw new CoolException(e.getMessage());
-            }
+            //淇濆瓨鍏ュ嚭搴撴槑缁�
+            saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
+            //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵��
+            removeReceiptStock(pakinItem, loginUserId);
         });
+
+        Set<Long> pkinItemIds = taskItems.stream().map(TaskItem::getSource).collect(Collectors.toSet());
+        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getId, pkinItemIds));
+        if (pakinItems.isEmpty()) {
+            throw new CoolException("缁勬墭鏄庣粏涓嶅瓨鍦紒锛�");
+        }
+        Set<Long> pakinIds = pakinItems.stream().map(WaitPakinItem::getPakinId).collect(Collectors.toSet());
+
+        if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
+                .set(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_TASK_DONE.val)
+                .set(WaitPakin::getUpdateBy, loginUserId)
+                .in(WaitPakin::getId, pakinIds))) {
+            throw new CoolException("缁勬嫋鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+        }
+
         /**淇敼搴撲綅鐘舵�佷负F.鍦ㄥ簱*/
         if (!locService.update(new LambdaUpdateWrapper<Loc>().set(Loc::getUseStatus, LocStsType.LOC_STS_TYPE_F.type).eq(Loc::getCode, task.getTargLoc()))) {
             throw new CoolException("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
@@ -1637,13 +1934,6 @@
         Double workQty = Math.round((itemServiceOne.getWorkQty() - pakinItem.getAnfme()) * 1000000) / 1000000.0;
         Double qty = Math.round((itemServiceOne.getQty() + pakinItem.getAnfme()) * 1000000) / 1000000.0;
         itemServiceOne.setWorkQty(workQty).setQty(qty);
-
-        if (!waitPakinService.update(new LambdaUpdateWrapper<WaitPakin>()
-                .set(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_TASK_DONE.val)
-                .set(WaitPakin::getUpdateBy, loginUserId)
-                .eq(WaitPakin::getId, pakinItem.getPakinId()))) {
-            throw new CoolException("缁勬嫋鐘舵�佷慨鏀瑰け璐ワ紒锛�");
-        }
 
         if (qty.compareTo(itemServiceOne.getAnfme()) == 0.00) {
             if (!warehouseAreasItemService.removeById(itemServiceOne.getId())) {
@@ -1682,8 +1972,8 @@
             LocItem locItem = locItemService.getOne(new LambdaQueryWrapper<LocItem>()
                     .eq(LocItem::getMatnrId, taskItem.getMatnrId())
                     .eq(LocItem::getLocId, loc.getId())
-                    .eq(StringUtils.isNoneBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
-                    .eq(StringUtils.isNoneBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
+                    .eq(StringUtils.isNotBlank(taskItem.getBatch()), LocItem::getBatch, taskItem.getBatch())
+                    .eq(StringUtils.isNotBlank(taskItem.getFieldsIndex()), LocItem::getFieldsIndex, taskItem.getFieldsIndex()));
             if (Objects.isNull(locItem)) {
                 BeanUtils.copyProperties(taskItem, item);
                 item.setLocCode(loc.getCode())
@@ -1696,11 +1986,13 @@
                     throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
                 }
             } else {
-                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 1000000) / 1000000.0)
-                        .setUpdateTime(new Date());
-                if (!locItemService.saveOrUpdate(locItem)) {
-                    throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
-                }
+                logger.error("褰撳墠绁ㄥ彿:"  + locItem.getFieldsIndex()  + " 宸插湪搴撳唴锛岃妫�鏌ュ悗鍐嶆搷浣滐紒锛�");
+//                throw new CoolException("褰撳墠绁ㄥ彿宸插湪搴撳唴锛岃妫�鏌ュ悗鍐嶆搷浣滐紒锛�");
+//                locItem.setAnfme(Math.round((locItem.getAnfme() + taskItem.getAnfme()) * 1000000) / 1000000.0)
+//                        .setUpdateTime(new Date());
+//                if (!locItemService.saveOrUpdate(locItem)) {
+//                    throw new CoolException("搴撲綅鏄庣粏鏇存柊澶辫触锛侊紒");
+//                }
             }
         });
 

--
Gitblit v1.9.1