From 87d66c61fc5047fb5708d609f4a5f1f868cd646c Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期四, 10 七月 2025 18:04:30 +0800
Subject: [PATCH] no message

---
 zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/services/Impl/WcsApiServiceImpl.java |  155 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 84 insertions(+), 71 deletions(-)

diff --git a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/services/Impl/WcsApiServiceImpl.java b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/services/Impl/WcsApiServiceImpl.java
index 5510bf4..f33da51 100644
--- a/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/services/Impl/WcsApiServiceImpl.java
+++ b/zy-asrs-wms/src/main/java/com/zy/asrs/wms/apis/wcs/services/Impl/WcsApiServiceImpl.java
@@ -33,6 +33,7 @@
 import javax.annotation.Resource;
 import java.util.*;
 import java.util.stream.Collectors;
+import java.util.stream.DoubleStream;
 
 @Slf4j
 @Service
@@ -79,20 +80,20 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public R containerArrivedNotify(ContainerArrivedParam arrivedParam, String taskType, Long hostId){
+    public R containerArrivedNotify(ContainerArrivedParam arrivedParam, String taskType, Long hostId) {
         Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, arrivedParam.getContainerCode()));
         if (task == null) {
             return R.error("浠诲姟涓嶅瓨鍦紒锛�");
         }
-        log.info("瀹瑰櫒鍒拌揪鎺ユ敹锛屼换鍔″彿锛歿}锛屽綋鍓嶇姸鎬侊細{}锛屼笂鎶ョ姸鎬侊細{}, 鎺ユ敹鍙傛暟锛歿}",task.getTaskNo(),task.getTaskSts$(),TaskStsType.WCS_CONTAINER_RECEIVE.desc, JSONObject.toJSONString(arrivedParam));
+        log.info("瀹瑰櫒鍒拌揪鎺ユ敹锛屼换鍔″彿锛歿}锛屽綋鍓嶇姸鎬侊細{}锛屼笂鎶ョ姸鎬侊細{}, 鎺ユ敹鍙傛暟锛歿}", task.getTaskNo(), task.getTaskSts$(), TaskStsType.WCS_CONTAINER_RECEIVE.desc, JSONObject.toJSONString(arrivedParam));
 
-        taskType = task.getTaskType() > 100 ? "outStock":"inStock";
+        taskType = task.getTaskType() > 100 ? "outStock" : "inStock";
 
         if (taskType.equals("inStock")) {
             if (task.getTaskSts() == 198) {
                 return R.error("鎾涓紒锛�");
             }
-            if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_IN.id ) {
+            if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_IN.id) {
                 //DONE 鏍规嵁ESS杩斿洖鐨勫鍣ㄧ紪鐮佷慨鏀逛换鍔℃。涓殑杈撻�佺嚎璧峰浣嶇疆鑺傜偣锛屽強浠诲姟妗e鍣ㄥ埌杈剧姸鎬�
                 taskService.update(new LambdaUpdateWrapper<Task>()
                         .set(Task::getTaskSts, TaskStsType.WCS_CONTAINER_RECEIVE.id)
@@ -100,39 +101,43 @@
                         .set(Task::getOriginSite, arrivedParam.getSlotCode())
                         .eq(Task::getBarcode, arrivedParam.getContainerCode()));
             } else {
-                  log.warn("{}娌℃湁涓嬪彂浠诲姟",task.getTaskNo());
-                  R.error(task.getTaskNo()+"娌℃湁涓嬪彂浠诲姟");
+                log.warn("{}娌℃湁涓嬪彂浠诲姟", task.getTaskNo());
+                R.error(task.getTaskNo() + "娌℃湁涓嬪彂浠诲姟");
             }
         } else {
             if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_ARRIVED.id
-            || task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TASK_DONE.id ) {
+                    || task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TASK_DONE.id) {
                 // 鍒拌揪鎷i�変綅锛屾帶鍒舵挱绉嶅浜伅
-                    List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>().eq(CacheSite::getBarcode, task.getBarcode()));
-                    if(cacheSites.size() == 0) {
-                        log.error("鏉$爜锛歿}锛屾湭鎵惧埌鎾澧欎寒鐏�",task.getBarcode());
-                        throw new CoolException("鏈壘鍒版挱绉嶅");
-                    }
-                    for (CacheSite cacheSite:cacheSites) {
-                        // 鑾峰彇浠诲姟鏄庣粏鏁伴噺
-                        List<TaskDetl> taskDetlByTaskId = taskDetlService.getTaskDetlByTaskId(task.getId());
-                        int sum = (int)taskDetlByTaskId.stream().mapToDouble(TaskDetl::getAnfme).sum();
-                        SlapLightControlParam slapLightControlParam = new SlapLightControlParam();
-                        slapLightControlParam
-                                .setControllerCode(cacheSite.getMemo())
-                                .setTagCode(cacheSite.getSiteNo())
-                                .setColor("GREEN")
-                                .setIndex(cacheSite.getIndex())
-                                .setMode("LIGHT")
-                                .setDisplay(sum + "");
-                        // 鍙戣捣浜伅璇锋眰
-                        log.info("浠诲姟{}鍒拌揪鎷i�変綅锛屾挱绉嶅浜伅涓嬪彂",task.getTaskNo(), JSONObject.toJSONString(slapLightControlParam));
-                        CommonReponse response = HttpEssUtils.post("鍒拌揪鎷i�変綅锛屾挱绉嶅浜伅", HttpEssUtils.PLT_SEND_COMMAND, slapLightControlParam);
-                        if (response.getCode().equals(0)) {
-                            log.info("浠诲姟{}鍒拌揪鎷i�変綅锛屾挱绉嶅{}浜伅鎴愬姛",task.getTaskNo(),cacheSite.getSiteNo());
-                        } else {
-                            log.info("浠诲姟{}鍒拌揪鎷i�変綅锛屾挱绉嶅{}浜伅澶辫触",task.getTaskNo(),cacheSite.getSiteNo());
-                        }
-                    }
+                CacheSite cacheSite = cacheSiteService.getOne(new LambdaQueryWrapper<CacheSite>()
+                        .eq(CacheSite::getChannel, task.getTargetSite())
+                        .isNull(CacheSite::getOrderId).orderByAsc(CacheSite::getId), false);
+//                List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
+//                            .eq(CacheSite::getBarcode, task.getBarcode()));
+                if (Objects.isNull(cacheSite)) {
+                    log.error("鏉$爜锛歿}锛屾湭鎵惧埌鎾澧欎寒鐏�", task.getBarcode());
+                    throw new CoolException("鏈壘鍒版挱绉嶅");
+                }
+
+                // 鑾峰彇浠诲姟鏄庣粏鏁伴噺
+                List<TaskDetl> taskDetlByTaskId = taskDetlService.getTaskDetlByTaskId(task.getId());
+                int sum = (int) taskDetlByTaskId.stream().mapToDouble(TaskDetl::getAnfme).sum();
+                SlapLightControlParam slapLightControlParam = new SlapLightControlParam();
+                slapLightControlParam
+                        .setControllerCode(cacheSite.getMemo())
+                        .setTagCode(cacheSite.getSiteNo())
+                        .setColor("GREEN")
+                        .setIndex(cacheSite.getIndex())
+                        .setMode("LIGHT")
+                        .setDisplay(sum + "");
+                // 鍙戣捣浜伅璇锋眰
+                log.info("浠诲姟{}鍒拌揪鎷i�変綅锛屾挱绉嶅浜伅涓嬪彂", task.getTaskNo(), JSONObject.toJSONString(slapLightControlParam));
+                CommonReponse response = HttpEssUtils.post("鍒拌揪鎷i�変綅锛屾挱绉嶅浜伅", HttpEssUtils.PLT_SEND_COMMAND, slapLightControlParam);
+                if (response.getCode().equals(0)) {
+                    log.info("浠诲姟{}鍒拌揪鎷i�変綅锛屾挱绉嶅{}浜伅鎴愬姛", task.getTaskNo(), cacheSite.getSiteNo());
+                } else {
+                    log.info("浠诲姟{}鍒拌揪鎷i�変綅锛屾挱绉嶅{}浜伅澶辫触", task.getTaskNo(), cacheSite.getSiteNo());
+                }
+
                 boolean update = taskService.update(new LambdaUpdateWrapper<Task>()
                         .set(Task::getTaskSts, TaskStsType.WAVE_SEED.id)
                         .set(Task::getOriginSite, arrivedParam.getSlotCode())
@@ -140,17 +145,16 @@
                 if (!update) {
                     throw new CoolException("瀹瑰櫒鍒拌揪浠诲姟鏇存柊澶辫触锛侊紒");
                 }
-
-            } else if(task.getTaskSts().equals(TaskStsType.UPDATED_OUT.id)) {
+            } else if (task.getTaskSts().equals(TaskStsType.UPDATED_OUT.id)) {
                 ConveyorStarParam conveyorStarParam = new ConveyorStarParam();
                 conveyorStarParam.setSlotCode(task.getOriginSite())
                         .setContainerCode(task.getBarcode())
                         .setDirection("200");
                 // 鍑哄簱瀹屾垚锛屾竻闄よ緭閫佺嚎鏉$爜锛屽彇涓嬬瀛�
-                    CommonReponse response = HttpEssUtils.post("娓呴櫎杈撻�佺嚎鏉$爜", HttpEssUtils.CONVEYOR_START, conveyorStarParam);
-                    if (response.getCode().equals(200)) {
-                        log.info("{}鍑哄簱瀹屾垚锛屾竻闄}杈撻�佺嚎鏉$爜{}鎴愬姛",task.getTaskNo(),task.getOriginSite(),task.getBarcode());
-                    }
+                CommonReponse response = HttpEssUtils.post("娓呴櫎杈撻�佺嚎鏉$爜", HttpEssUtils.CONVEYOR_START, conveyorStarParam);
+                if (response.getCode().equals(200)) {
+                    log.info("{}鍑哄簱瀹屾垚锛屾竻闄}杈撻�佺嚎鏉$爜{}鎴愬姛", task.getTaskNo(), task.getOriginSite(), task.getBarcode());
+                }
             }
         }
 
@@ -172,17 +176,17 @@
                 .eq(Task::getTaskNo, callbackParam.getTaskCode()));
         if (!Collections.isEmpty(list)) {
             list.forEach(task -> {
-                log.info("瀹瑰櫒鎵ц鐘舵�佷笂鎶ワ紝浠诲姟鍙凤細{}锛屽綋鍓嶇姸鎬侊細{}锛屼笂鎶ョ姸鎬侊細{}",task.getTaskNo(),task.getTaskSts$(),callbackParam.getEventType());
+                log.info("瀹瑰櫒鎵ц鐘舵�佷笂鎶ワ紝浠诲姟鍙凤細{}锛屽綋鍓嶇姸鎬侊細{}锛屼笂鎶ョ姸鎬侊細{}", task.getTaskNo(), task.getTaskSts$(), callbackParam.getEventType());
                 if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_ALLOCATED.event)) {
                     return;
                 }
                 // ESS鍙兘閰嶇疆涓�涓姸鎬佷笂鎶ユ帴鍙o紝鏍规嵁浠诲姟鍙峰垽鏂槸鍏ュ簱浠诲姟鎴栧嚭搴撲换鍔�
-                String taskType = task.getTaskType() > 100 ? "outStock":"inStock";
+                String taskType = task.getTaskType() > 100 ? "outStock" : "inStock";
                 TaskStsType taskStsType = null;
                 if (taskType.equals("inStock")) { //鍏ュ簱浠诲姟
                     if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_LOAD.event)) { //涓婃姤鍙栫鐘舵��
 //                        if (task.getTaskSts() == TaskStsType.WCS_CONVEYOR_START.id) {
-                            taskStsType = TaskStsType.WCS_TOTE_LOAD;
+                        taskStsType = TaskStsType.WCS_TOTE_LOAD;
 //                        } else {
 //                            String errMsg = "浠诲姟缂栧彿锛�" + task.getTaskNo() + "鐘舵�佷负涓嶅尮閰嶏紝" + "涓嶈兘鎵ц锛�" + TaskStsType.WCS_TOTE_LOAD.desc + "浠诲姟";
 //                            log.error(errMsg);
@@ -190,7 +194,7 @@
 //                        }
                     } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_UNLOAD.event)) { //涓婃姤鏀剧鐘舵��
 //                        if (task.getTaskSts() == TaskStsType.WCS_TOTE_LOAD.id) {
-                            taskStsType = TaskStsType.WCS_TOTE_UNLOAD;
+                        taskStsType = TaskStsType.WCS_TOTE_UNLOAD;
 //                        } else {
 //                            String errMsg = "浠诲姟缂栧彿锛�" + task.getTaskNo() + "鐘舵�佷负涓嶅尮閰嶏紝" + "涓嶈兘鎵ц锛�" + TaskStsType.WCS_TOTE_UNLOAD.desc + "浠诲姟";
 //                            log.error(errMsg);
@@ -198,7 +202,7 @@
 //                        }
                     } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_STATUS.event)) { //TODO 闇�纭涓婃姤浠诲姟涓紝浠诲姟瀹屾垚鏄摢涓簨浠讹紝鐩墠鏆傚畾task浜嬩欢
 //                        if (task.getTaskSts() == TaskStsType.WCS_TOTE_UNLOAD.id) {
-                            taskStsType = TaskStsType.WCS_PUTAWAY_SUCESS;
+                        taskStsType = TaskStsType.WCS_PUTAWAY_SUCESS;
 //                        } else {
 //                            String errMsg = "浠诲姟缂栧彿锛�" + task.getTaskNo() + "鐘舵�佷负涓嶅尮閰嶏紝" + "涓嶈兘鎵ц锛�" + TaskStsType.WCS_PUTAWAY_SUCESS.desc + "浠诲姟";
 //                            log.error(errMsg);
@@ -222,7 +226,7 @@
                 } else { //鍑哄簱浠诲姟
                     if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_LOAD.event)) { //涓婃姤鍙栫鐘舵��
 //                        if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT.id ) {
-                            taskStsType = TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD;
+                        taskStsType = TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD;
 //                        } else {
 //                            String errMsg = "浠诲姟缂栧彿锛�" + task.getTaskNo() + "鐘舵�佷负涓嶅尮閰嶏紝" + "涓嶈兘鎵ц锛�" + TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD.desc + "浠诲姟";
 //                            log.error(errMsg);
@@ -230,7 +234,7 @@
 //                        }
                     } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_TOTE_UNLOAD.event)) { //涓婃姤鏀剧鐘舵��
 //                        if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TOTE_LOAD.id) {
-                            taskStsType = TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD;
+                        taskStsType = TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD;
 //                        } else {
 //                            String errMsg = "浠诲姟缂栧彿锛�" + task.getTaskNo() + "鐘舵�佷负涓嶅尮閰嶏紝" + "涓嶈兘鎵ц锛�" + TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD.desc + "浠诲姟";
 //                            log.error(errMsg);
@@ -238,8 +242,8 @@
 //                        }
                     } else if (callbackParam.getEventType().equals(EssTaskStatus.TASK_EVENT_STATUS.event)) { //涓婃姤瀹屾垚鐘舵��
 //                        if (task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TOTE_UNLOAD.id || task.getTaskSts() == TaskStsType.WCS_EXECUTE_OUT_TASK_DONE.id) {
-                            //鍑哄簱浠诲姟瀹屾垚锛屼慨鏀圭姸鎬佷负瀹瑰櫒鍒拌揪锛屽畾鏃朵换鍔$敓鎴愭挱绉嶆尝娆�
-                            taskStsType = TaskStsType.WCS_EXECUTE_OUT_TASK_DONE;
+                        //鍑哄簱浠诲姟瀹屾垚锛屼慨鏀圭姸鎬佷负瀹瑰櫒鍒拌揪锛屽畾鏃朵换鍔$敓鎴愭挱绉嶆尝娆�
+                        taskStsType = TaskStsType.WCS_EXECUTE_OUT_TASK_DONE;
 //                        } else {
 //                            String errMsg = "浠诲姟缂栧彿锛�" + task.getTaskNo() + "鐘舵�佷负涓嶅尮閰嶏紝" + "涓嶈兘鎵ц锛�" + TaskStsType.WCS_EXECUTE_OUT_TASK_DONE.desc + "浠诲姟";
 //                            log.error(errMsg);
@@ -276,11 +280,11 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public synchronized R containerConveryor(String code) throws Exception{
+    public synchronized R containerConveryor(String code) throws Exception {
         Task task = taskService.getOne(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, code));
         if (Objects.isNull(task)) {
             throw new CoolException("瀹瑰櫒鐮佷换鍔′笉瀛樺湪锛侊紒");
-        } 
+        }
         try {
             ConveyorStarParam conveyorStarParam = new ConveyorStarParam();
             conveyorStarParam.setSlotCode(task.getOriginSite())
@@ -320,7 +324,7 @@
                 }
             }
         } catch (Exception ex) {
-            log.error("UNK",  ex);
+            log.error("UNK", ex);
         }
         return R.ok();
     }
@@ -352,16 +356,16 @@
         if (Objects.isNull(performs.stream().findFirst().get().getPlatformId())) {
             throw new CoolException("璇锋墦鍗版槑缁嗭紝骞剁粦瀹氱洰鏍囬泦璐у尯");
         }
-
         //* 1. 鍒ゆ柇褰撳墠瀹瑰櫒鏄惁杩樻湁鐗╂枡鏈嫞锛屾湭鎷e畬闂伅锛屾嫞瀹岄�氱煡瀹瑰櫒娴佸姩锛屽苟鐏伅
         SlapLightControlParam slapParam = new SlapLightControlParam();
         MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
+
         //鍒ゆ柇褰撳墠浠诲姟鏄惁杩樻湁鐗╂枡鏈嫞
         if (!checked(orderNo, taskNo)) {
             log.info("鏈畬鎴愰棯鐏姹傚湴鍧�锛歿}锛岃姹傚弬鏁帮細{}", SystemProperties.SLAP_LIGHT, JSONObject.toJSONString(slapParam));
             //璋冪敤涓夋柟鎺ュ彛,闂伅涓嶅仛鎿嶄綔
             // 璁剧疆璇锋眰鍙傛暟
-            throw new CoolException("褰撳墠浠诲姟鏈畬鎴愶紝涓嶈兘鎵ц姝ゆ搷浣滐紒锛�");
+//            throw new CoolException("褰撳墠浠诲姟鏈畬鎴愶紝涓嶈兘鎵ц姝ゆ搷浣滐紒锛�");
 //            params.add("params", JSONObject.toJSONString(slapParam));
         } else {
             //璋冪敤涓夋柟鎺ュ彛,鐏伅閫氱煡瀹瑰櫒娴佸姩锛� 浼犵伃鐏弬鏁�
@@ -376,21 +380,31 @@
 //            }).collect(Collectors.toList());
 
             //鍒ゆ柇鏁伴噺鏄惁涓庤鍗曟槑缁嗙殑闇�姹傞噺鐩稿悓锛岀浉鍚屽垯璁㈠崟瀹屾垚
-            //鎾瀹屾垚锛岄噴鏀剧粦瀹氱珯鐐�
-            List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
-                    .eq(!Objects.isNull(siteNo), CacheSite::getSiteNo, siteNo)
-                    .eq(CacheSite::getOrderNo, orderNo));
-            for (CacheSite cacheSite : cacheSites) {
-                if (!cacheSite.getSiteStatus().equals(CacheSiteStatusType.O.id)) {
-                    cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
-                    cacheSite.setOrderId(null);
-                    cacheSite.setBarcode(null);
-                    cacheSite.setOrderNo(null);
-                    cacheSite.setPlatformId(null);
-                    cacheSite.setPlatformNo(null);
-                    cacheSite.setUpdateTime(new Date());
-                    if (!cacheSiteService.updateById(cacheSite)) {
-                        throw new CoolException("鎾绔欑偣鏇存柊澶辫触");
+
+            List<WaveSeed> seeds = waveSeedService.list(new LambdaQueryWrapper<WaveSeed>().eq(WaveSeed::getOrderNo, orderNo));
+            if (Objects.isNull(seeds)) {
+                throw new CoolException("鏁版嵁閿欒锛氭挱绉嶆暟鎹笉瀛樺湪锛侊紒");
+            }
+
+            Double tolAnfme = seeds.stream().mapToDouble(WaveSeed::getAnfme).sum();
+            Double toDouble = seeds.stream().mapToDouble(WaveSeed::getWorkQty).sum();
+            if (toDouble.compareTo(tolAnfme) >= 0) {
+                //鎾瀹屾垚锛岄噴鏀剧粦瀹氱珯鐐�
+                List<CacheSite> cacheSites = cacheSiteService.list(new LambdaQueryWrapper<CacheSite>()
+                        .eq(!Objects.isNull(siteNo), CacheSite::getSiteNo, siteNo)
+                        .eq(CacheSite::getOrderNo, orderNo));
+                for (CacheSite cacheSite : cacheSites) {
+                    if (!cacheSite.getSiteStatus().equals(CacheSiteStatusType.O.id)) {
+                        cacheSite.setSiteStatus(CacheSiteStatusType.O.id);
+                        cacheSite.setOrderId(null);
+                        cacheSite.setBarcode(null);
+                        cacheSite.setOrderNo(null);
+                        cacheSite.setPlatformId(null);
+                        cacheSite.setPlatformNo(null);
+                        cacheSite.setUpdateTime(new Date());
+                        if (!cacheSiteService.updateById(cacheSite)) {
+                            throw new CoolException("鎾绔欑偣鏇存柊澶辫触");
+                        }
                     }
                 }
             }
@@ -405,10 +419,9 @@
         try {
             containerConveryor(task.getBarcode());
         } catch (Exception e) {
-            log.error("鎵ц寮傚父:UNK",  e);
+            log.error("鎵ц寮傚父:UNK", e);
             throw new CoolException(e.getMessage());
         }
-
         return R.ok();
     }
 
@@ -444,7 +457,7 @@
         //鍒ゆ柇浠诲姟闇�姹傛�婚噺鏄惁绛夋挱绉嶆�绘暟閲�
         if (taskNum == seedNum) {
             return true;
-        } else  {
+        } else {
             return false;
         }
     }

--
Gitblit v1.9.1