From e9543f18fbe81fb492df941fdc6fce59424f8f49 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期四, 05 二月 2026 08:39:36 +0800
Subject: [PATCH] RCS对接

---
 rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/TaskServiceImpl.java |  368 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 314 insertions(+), 54 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 939f23e..adcbecd 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
@@ -462,6 +462,9 @@
                 if (task.getTaskType().equals(TaskType.TASK_TYPE_IN.type)) {
                     //1.鍏ュ簱
                     complateInstock(task, loginUserId);
+                } else if (task.getTaskType().equals(TaskType.TASK_TYPE_EMPITY_IN.type)) {
+                    //10.绌烘墭鍏ュ簱
+                    complateEmpityInStock(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.鐩樼偣鍐嶅叆搴�
@@ -744,11 +747,14 @@
             }
             BeanUtils.copyProperties(locWorking, locItem);
             locItem.setWorkQty(0.0).setQty(0.0).setLocCode(loc.getCode()).setLocId(loc.getId()).setId(null).setUpdateBy(loginUserId).setUpdateTime(new Date());
-            items.add(locItem);
+            //鏁伴噺涓洪浂鐨勪笉鍏ュ簱
+            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();
@@ -774,16 +780,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) {
             //鍙栨秷绉诲簱浠诲姟
@@ -1017,17 +1139,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)) {
@@ -1096,26 +1219,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;
     }
 
@@ -1127,7 +1249,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("鍙傛暟涓嶈兘涓虹┖锛侊紒");
         }
@@ -1224,15 +1346,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>()
@@ -1388,13 +1521,28 @@
     public void pubTaskToWcs(List<Task> tasks) {
         WcsTaskParams taskParams = new WcsTaskParams();
         List<TaskItemParam> items = new ArrayList<>();
+        
+        // 璁剧疆鎵规缂栧彿锛堜娇鐢ㄧ涓�涓换鍔$殑barcode锛屽鏋滀负null鍒欎娇鐢ㄤ换鍔$紪鐮侊級
+        String batchNo = null;
+        if (!tasks.isEmpty()) {
+            Task firstTask = tasks.get(0);
+            batchNo = StringUtils.isNotBlank(firstTask.getBarcode()) 
+                    ? firstTask.getBarcode() 
+                    : firstTask.getTaskCode();
+        }
+        if (StringUtils.isBlank(batchNo)) {
+            // 濡傛灉鎵规缂栧彿浠嶄负绌猴紝鐢熸垚涓�涓粯璁ゅ��
+            batchNo = "BATCH_" + System.currentTimeMillis();
+        }
+
+        taskParams.setBatchNo(batchNo);
+        log.info("璁剧疆鎵规缂栧彿锛歿}", batchNo);
+        
         tasks.forEach(task -> {
             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()));
@@ -1460,28 +1608,50 @@
             }
             items.add(itemParam);
         });
-        taskParams.setTaskList(items);
+        taskParams.setTasks(items);
         /**浠诲姟涓嬪彂鎺ュ彛*/
         String pubTakUrl = rcsApi.getHost() + ":" + rcsApi.getPort() + RcsConstant.pubTask;
         /**RCS鍩虹閰嶇疆閾炬帴*/
-        log.info("浠诲姟涓嬪彂锛岃姹傚湴鍧�锛� {}锛� 璇锋眰鍙傛暟锛� {}", pubTakUrl, JSONObject.toJSONString(taskParams));
+        log.info("========== 寮�濮嬩笅鍙戜换鍔″埌RCS ==========");
+        log.info("RCS璇锋眰鍦板潃锛歿}", pubTakUrl);
+        log.info("鎵规缂栧彿锛歿}", batchNo);
+        log.info("浠诲姟鏁伴噺锛歿}", tasks.size());
+        log.info("浠诲姟鍒楄〃璇︽儏锛�");
+        tasks.forEach(task -> {
+            log.info("  - 浠诲姟缂栫爜锛歿}锛屼换鍔$被鍨嬶細{}锛屾簮搴撲綅锛歿}锛岀洰鏍囧簱浣嶏細{}锛屾簮绔欑偣锛歿}锛岀洰鏍囩珯鐐癸細{}", 
+                    task.getTaskCode(), task.getTaskType(), task.getOrgLoc(), 
+                    task.getTargLoc(), task.getOrgSite(), task.getTargSite());
+        });
+        log.info("璇锋眰鍙傛暟锛歿}", 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);
+        long startTime = System.currentTimeMillis();
         ResponseEntity<String> exchange = restTemplate.exchange(pubTakUrl, HttpMethod.POST, httpEntity, String.class);
-        log.info("浠诲姟涓嬪彂鍚庯紝鍝嶅簲缁撴灉锛� {}", exchange);
+        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());
         if (Objects.isNull(exchange.getBody())) {
-            throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
+            log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+            log.error("RCS鍝嶅簲浣撲负绌猴紝鏃犳硶瑙f瀽鍝嶅簲缁撴灉");
+            log.error("璇锋眰鍦板潃锛歿}", pubTakUrl);
+            log.error("璇锋眰鍙傛暟锛歿}", JSONObject.toJSONString(taskParams));
+            throw new CoolException("浠诲姟涓嬪彂澶辫触锛孯CS鍝嶅簲浣撲负绌猴紒锛�");
         } 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浠诲姟涓嬪彂鎴愬姛锛屽紑濮嬫洿鏂颁换鍔$姸鎬�");
                     tasks.forEach(task -> {
-
+                        log.info("鏇存柊浠诲姟鐘舵�� - 浠诲姟缂栫爜锛歿}锛屼换鍔$被鍨嬶細{}", task.getTaskCode(), task.getTaskType());
                         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)
@@ -1494,10 +1664,12 @@
                                 throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
                             }
 
+                            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.info("鍏ュ簱浠诲姟鐘舵�佹洿鏂版垚鍔� - 浠诲姟缂栫爜锛歿}", task.getTaskCode());
                             /**鎺掗櫎绉诲簱鍔熻兘*/
                             if (!task.getTaskType().equals(TaskType.TASK_TYPE_LOC_MOVE.type)) {
                                 /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍑哄簱棰勭害*/
@@ -1518,10 +1690,12 @@
                                 throw new CoolException("绔欑偣涓嶅瓨鍦紒锛�");
                             }
 
+                            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.info("鍑哄簱浠诲姟鐘舵�佹洿鏂版垚鍔� - 浠诲姟缂栫爜锛歿}", task.getTaskCode());
                             /**濡傛灉鏄櫘閫氱珯鐐癸紝淇敼绔欑偣鐘舵�佷负鍏ュ簱棰勭害*/
                             if (curSta.getType().equals(StationTypeEnum.STATION_TYPE_NORMAL.type)) {
                                 curSta.setUseStatus(LocStsType.LOC_STS_TYPE_S.type);
@@ -1531,15 +1705,27 @@
                             }
                         }
                     });
+                    log.info("========== RCS浠诲姟涓嬪彂瀹屾垚锛屽叡{}涓换鍔$姸鎬佸凡鏇存柊 ==========", tasks.size());
                 } else {
-                    log.error(JSONObject.toJSONString(result));
+                    log.error("========== RCS浠诲姟涓嬪彂澶辫触 ==========");
+                    log.error("RCS杩斿洖閿欒 - code锛歿}锛宮sg锛歿}锛宒ata锛歿}", 
+                            result.getCode(), result.getMsg(), result.getData());
+                    log.error("澶辫触鐨勪换鍔″垪琛細");
+                    tasks.forEach(task -> {
+                        log.error("  - 浠诲姟缂栫爜锛歿}锛屼换鍔$被鍨嬶細{}", task.getTaskCode(), task.getTaskType());
+                    });
 //                    throw new CoolException("浠诲姟涓嬪彂澶辫触锛侊紒");
                 }
             } catch (JsonProcessingException e) {
-                throw new CoolException(e.getMessage());
+                log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
+                log.error("瑙f瀽RCS鍝嶅簲澶辫触锛屽搷搴斾綋锛歿}", exchange.getBody(), e);
+                throw new CoolException("瑙f瀽RCS鍝嶅簲澶辫触锛�" + e.getMessage());
+            } catch (Exception e) {
+                log.error("========== RCS浠诲姟涓嬪彂寮傚父 ==========");
+                log.error("浠诲姟涓嬪彂杩囩▼涓彂鐢熷紓甯�", e);
+                throw e;
             }
         }
-
     }/**
 
 
@@ -1623,6 +1809,80 @@
     }
 
     /**
+     * 绌烘墭鍏ュ簱瀹屾垚
+     *
+     * @param task
+     * @param loginUserId
+     */
+    @Transactional(rollbackFor = Exception.class)
+    public synchronized void complateEmpityInStock(Task task, Long loginUserId) {
+        if (Objects.isNull(task)) {
+            return;
+        }
+
+        Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, task.getTargLoc()));
+        if (Objects.isNull(loc)) {
+            throw new CoolException("鐩爣搴撲綅涓嶅瓨鍦紒");
+        }
+
+        if (!loc.getUseStatus().equals(LocStsType.LOC_STS_TYPE_S.type)) {
+            throw new CoolException("褰撳墠搴撲綅鐘舵�佷笉澶勪簬S.鍏ュ簱棰勭害锛屼笉鍙墽琛屽叆搴撴搷浣滐紒");
+        }
+
+        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
+        if (taskItems.isEmpty()) {
+            throw new CoolException("浠诲姟鏄庣粏涓嶅瓨鍦紒锛�");
+        }
+
+        //鏇存柊搴撲綅鏄庣粏
+        saveLocItem(taskItems, task.getId(), loginUserId);
+
+        //绌烘墭鍏ュ簱涓嶆牎楠岀粍鎵樹俊鎭紝鐩存帴澶勭悊浠诲姟鏄庣粏
+        //濡傛灉鏈変换鍔℃槑缁嗗叧鑱斾簡缁勬墭锛屼篃闇�瑕佷繚瀛樺叆鍑哄簱鏄庣粏鍜岀Щ鍑烘敹璐у尯搴撳瓨
+        Map<Long, List<TaskItem>> orderMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getSource));
+        orderMap.keySet().forEach(key -> {
+            // 濡傛灉source涓嶄负绌猴紝璇存槑鏈夊叧鑱旂殑缁勬墭鏄庣粏锛岄渶瑕佸鐞�
+            if (key != null && key > 0) {
+                WaitPakinItem pakinItem = waitPakinItemService.getById(key);
+                if (!Objects.isNull(pakinItem)) {
+                    List<TaskItem> items = orderMap.get(key);
+                    //淇濆瓨鍏ュ嚭搴撴槑缁�
+                    saveStockItems(items, task, pakinItem.getId(), pakinItem.getAsnCode(), pakinItem.getWkType(), pakinItem.getType(), loginUserId);
+                    //绉诲嚭鏀惰揣鍖哄簱瀛橈紝 淇敼缁勬墭鐘舵��
+                    removeReceiptStock(pakinItem, loginUserId);
+                }
+            }
+        });
+
+        // 澶勭悊缁勬墭鐘舵�侊紙濡傛灉鏈夌粍鎵樺叧鑱旓級
+        Set<Long> pkinItemIds = taskItems.stream()
+                .map(TaskItem::getSource)
+                .filter(source -> source != null && source > 0)
+                .collect(Collectors.toSet());
+        
+        if (!pkinItemIds.isEmpty()) {
+            List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().in(WaitPakinItem::getId, pkinItemIds));
+            if (!pakinItems.isEmpty()) {
+                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("搴撲綅鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+        }
+        if (!this.update(new LambdaUpdateWrapper<Task>().eq(Task::getId, task.getId()).set(Task::getTaskStatus, TaskStsType.UPDATED_IN.id))) {
+            throw new CoolException("浠诲姟鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+        }
+    }
+
+    /**
      * @param
      * @param loginUserId
      * @return

--
Gitblit v1.9.1