From dd91c85493463db1968e6e7a61c841d20f948cf6 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 14 十一月 2023 16:37:48 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  539 ++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 342 insertions(+), 197 deletions(-)

diff --git a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
index 1b43d5d..0859375 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -473,117 +473,155 @@
                         continue;
                     }
 
-                    try {
-                        // 璁块棶 WMS 鑾峰彇鍏ュ簱搴撲綅
-                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
-                        SearchLocParam param = new SearchLocParam();
-                        param.setWrkNo(wrkMast.getWrkNo());
-                        param.setIoType(wrkMast.getIoType());
-                        param.setSourceStaNo(pickSta.getStaNo());
-//                        param.setLocType1(locTypeDto.getLocType1());
-                        String response = new HttpHandler.Builder()
-                                .setUri(wmsUrl)
-                                .setPath("/rpc/pakin/loc/v1")
-                                .setJson(JSON.toJSONString(param))
-                                .build()
-                                .doPost();
-                        JSONObject jsonObject = JSON.parseObject(response);
-                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
-                        Integer code = jsonObject.getInteger("code");
-                        if (code.equals(200)) {
-                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+                    // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+                    if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
+                        throw new CoolException(wrkMast.getWrkNo() + "淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
+                    }
 
-//                            // 鑾峰彇鐩爣绔�
-//                            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
-//                                    .eq("type_no", wrkMast.getIoType() - 50)
-//                                    .eq("stn_no", pickSta.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
-//                                    .eq("crn_no", dto.getCrnNo()); // 鍫嗗灈鏈哄彿
-//                            StaDesc staDesc = staDescService.selectOne(wrapper);
-//                            if (Cools.isEmpty(staDesc)) {
-//                                News.error("鍏ュ簱璺緞涓嶅瓨鍦紒type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
-//                                continue;
-//                            }
-//                            // 鍫嗗灈鏈虹珯鐐�(鐩爣绔�)
-//                            Integer staNo = staDesc.getCrnStn();
+                    String sourceLocNo = wrkMast.getSourceLocNo().trim();
+                    LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//鑾峰彇鍥炲簱鎻愬崌鏈虹洰鏍囩珯
+                    if (liftStaProtocol == null) {
+                        continue;
+                    }
 
-                            // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
-//                        if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
-//                            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
-//                        }
-                            // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
-                            if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
-                                throw new CoolException(wrkMast.getWrkNo() + "淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
-                            }
-
-                            String sourceLocNo = wrkMast.getSourceLocNo().trim();
-                            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//鑾峰彇鍥炲簱鎻愬崌鏈虹洰鏍囩珯
-                            if (liftStaProtocol == null) {
-                                continue;
-                            }
-
-                            // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
-                            wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
-                            wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
-                            wrkMast.setSourceStaNo(pickSta.getStaNo()); // 婧愮珯
+                    // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
+                    wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
+                    wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
+                    wrkMast.setSourceStaNo(pickSta.getStaNo()); // 婧愮珯
 //                            wrkMast.setStaNo(dto.getStaNo()); // 鐩爣绔�
 //                            wrkMast.setCrnNo(dto.getCrnNo());
-                            wrkMast.setStaNo(liftStaProtocol.getStaNo());//鐩爣绔�
-                            wrkMast.setLocNo(sourceLocNo); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
-                            wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌�
-                            wrkMast.setLiftNo(null);// 鎻愬崌鏈烘竻绌�
-                            wrkMast.setModiTime(new Date());
-                            if (wrkMastMapper.updateById(wrkMast) == 0) {
-                                throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
-                            }
-                            if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
-                                throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
-                            }
-
-                            // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
-                            LocMast locMast = locMastService.selectById(sourceLocNo);
-                            locMast.setLocSts("Q");
-                            locMast.setModiTime(new Date());
-                            if (!locMastService.updateById(locMast)) {
-                                throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�");
-                            }
-
-//                            // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
-//                            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
-//                            staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
-//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-//                            if (!result) {
-//                                News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
-//                            }
-
-                            barcodeThread.setBarcode("");//娓呯悊鏉$爜
-
-                        } else if (code == 500){
-                            if (ledThread != null) {
-                                String errorMsg = jsonObject.getString("msg");
-                                if (!Cools.isEmpty(errorMsg)) {
-                                    MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
-                                }
-                            }
-                            News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
-                        } else {
-//                            staProtocol.setWorkNo((short) 32002);
-//                            staProtocol.setStaNo(pickSta.getBackSta().shortValue());
-//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
-//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
-
-                            // led 寮傚父鏄剧ず
-                            if (ledThread != null) {
-                                String errorMsg = jsonObject.getString("msg");
-//                                String errorMsg = barcode + "鎵樼洏璇嗗埆寮傚父锛岃鍏堣繘琛岀粍鎵橈紒";
-                                MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
-                            }
-                        }
-
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    wrkMast.setStaNo(liftStaProtocol.getStaNo());//鐩爣绔�
+                    wrkMast.setLocNo(sourceLocNo); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
+                    wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌�
+                    wrkMast.setLiftNo(null);// 鎻愬崌鏈烘竻绌�
+                    wrkMast.setModiTime(new Date());
+                    if (wrkMastMapper.updateById(wrkMast) == 0) {
+                        throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
                     }
+                    if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
+                        throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+                    }
+
+                    // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
+                    LocMast locMast = locMastService.selectById(sourceLocNo);
+                    locMast.setLocSts("Q");
+                    locMast.setModiTime(new Date());
+                    if (!locMastService.updateById(locMast)) {
+                        throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�");
+                    }
+                    barcodeThread.setBarcode("");//娓呯悊鏉$爜
+
+//                    try {
+//                        // 璁块棶 WMS 鑾峰彇鍏ュ簱搴撲綅
+//                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
+//                        SearchLocParam param = new SearchLocParam();
+//                        param.setWrkNo(wrkMast.getWrkNo());
+//                        param.setIoType(wrkMast.getIoType());
+//                        param.setSourceStaNo(pickSta.getStaNo());
+////                        param.setLocType1(locTypeDto.getLocType1());
+//                        String response = new HttpHandler.Builder()
+//                                .setUri(wmsUrl)
+//                                .setPath("/rpc/pakin/loc/v1")
+//                                .setJson(JSON.toJSONString(param))
+//                                .build()
+//                                .doPost();
+//                        JSONObject jsonObject = JSON.parseObject(response);
+//                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
+//                        Integer code = jsonObject.getInteger("code");
+//                        if (code.equals(200)) {
+//                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
+//
+////                            // 鑾峰彇鐩爣绔�
+////                            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
+////                                    .eq("type_no", wrkMast.getIoType() - 50)
+////                                    .eq("stn_no", pickSta.getStaNo()) // 浣滀笟绔欑偣 = 鎷f枡鍑哄簱鐨勭洰鏍囩珯
+////                                    .eq("crn_no", dto.getCrnNo()); // 鍫嗗灈鏈哄彿
+////                            StaDesc staDesc = staDescService.selectOne(wrapper);
+////                            if (Cools.isEmpty(staDesc)) {
+////                                News.error("鍏ュ簱璺緞涓嶅瓨鍦紒type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
+////                                continue;
+////                            }
+////                            // 鍫嗗灈鏈虹珯鐐�(鐩爣绔�)
+////                            Integer staNo = staDesc.getCrnStn();
+//
+//                            // 淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。
+////                        if (wrkMastMapper.saveWrkDetlLog(wrkMast.getWrkNo()) == 0) {
+////                            throw new CoolException("淇濆瓨宸ヤ綔鏄庣粏妗e巻鍙叉。澶辫触");
+////                        }
+//                            // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+//                            if (wrkMastMapper.saveWrkMastLog(wrkMast.getWrkNo()) == 0) {
+//                                throw new CoolException(wrkMast.getWrkNo() + "淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗eけ璐�");
+//                            }
+//
+//                            String sourceLocNo = wrkMast.getSourceLocNo().trim();
+//                            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(pickSta.getLiftNo(), Utils.getLev(sourceLocNo));//鑾峰彇鍥炲簱鎻愬崌鏈虹洰鏍囩珯
+//                            if (liftStaProtocol == null) {
+//                                continue;
+//                            }
+//
+//                            // 鏇存柊宸ヤ綔妗f暟鎹姸鎬�
+//                            wrkMast.setIoType(wrkMast.getIoType() - 50); // 鍏ュ嚭搴撶被鍨�: 103->53,104->54,107->57
+//                            wrkMast.setWrkSts(2L); // 宸ヤ綔鐘舵��: 2.璁惧涓婅蛋
+//                            wrkMast.setSourceStaNo(pickSta.getStaNo()); // 婧愮珯
+////                            wrkMast.setStaNo(dto.getStaNo()); // 鐩爣绔�
+////                            wrkMast.setCrnNo(dto.getCrnNo());
+//                            wrkMast.setStaNo(liftStaProtocol.getStaNo());//鐩爣绔�
+//                            wrkMast.setLocNo(sourceLocNo); // 鐩爣搴撲綅 = 鍑哄簱鏃剁殑婧愬簱浣�
+//                            wrkMast.setShuttleNo(null); // 绌挎杞︽竻绌�
+//                            wrkMast.setLiftNo(null);// 鎻愬崌鏈烘竻绌�
+//                            wrkMast.setModiTime(new Date());
+//                            if (wrkMastMapper.updateById(wrkMast) == 0) {
+//                                throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+//                            }
+//                            if (wrkMastMapper.setSteEmpty(wrkMast.getWrkNo()) == 0) {
+//                                throw new CoolException(wrkMast.getWrkNo() + "鏇存柊宸ヤ綔妗f暟鎹姸鎬佸け璐�");
+//                            }
+//
+//                            // 淇敼搴撲綅鐘舵�� Q.鎷f枡/鐩樼偣/骞舵澘鍐嶅叆搴�
+//                            LocMast locMast = locMastService.selectById(sourceLocNo);
+//                            locMast.setLocSts("Q");
+//                            locMast.setModiTime(new Date());
+//                            if (!locMastService.updateById(locMast)) {
+//                                throw new CoolException("淇敼搴撲綅鐘舵�佸け璐�");
+//                            }
+//
+////                            // 鏇存柊绔欑偣淇℃伅 涓� 涓嬪彂plc鍛戒护
+////                            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
+////                            staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
+////                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+////                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+////                            if (!result) {
+////                                News.error("鍙戝竷鍛戒护鑷宠緭閫佺嚎闃熷垪澶辫触锛侊紒锛� [plc缂栧彿锛歿}]", devp.getId());
+////                            }
+//
+//                            barcodeThread.setBarcode("");//娓呯悊鏉$爜
+//
+//                        } else if (code == 500){
+//                            if (ledThread != null) {
+//                                String errorMsg = jsonObject.getString("msg");
+//                                if (!Cools.isEmpty(errorMsg)) {
+//                                    MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
+//                                }
+//                            }
+//                            News.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
+//                        } else {
+////                            staProtocol.setWorkNo((short) 32002);
+////                            staProtocol.setStaNo(pickSta.getBackSta().shortValue());
+////                            devpThread.setPakMk(staProtocol.getSiteId(), false);
+////                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+//
+//                            // led 寮傚父鏄剧ず
+//                            if (ledThread != null) {
+//                                String errorMsg = jsonObject.getString("msg");
+////                                String errorMsg = barcode + "鎵樼洏璇嗗埆寮傚父锛岃鍏堣繘琛岀粍鎵橈紒";
+//                                MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, errorMsg));
+//                            }
+//                        }
+//
+//                    } catch (Exception e) {
+//                        e.printStackTrace();
+//                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+//                    }
 
                 }
             }
@@ -596,7 +634,7 @@
      */
     public synchronized void initRealtimeBasMap() {
         for (int i = 1; i <= 10; i++) {//鎬诲叡鍥涘眰妤�
-            Object data = redisUtil.get("realtimeBasMap_" + i);
+            Object data = redisUtil.get(RedisKeyType.MAP.key + i);
             if (data == null) {//redis鍦板浘鏁版嵁涓虹┖锛屼粠鏁版嵁搴撲腑鑾峰彇
                 BasMap basMap = basMapService.selectLatestMap(i);
                 if (basMap == null) {
@@ -618,7 +656,7 @@
                 }
 
                 //灏嗘暟鎹簱鍦板浘鏁版嵁瀛樺叆redis
-                redisUtil.set("realtimeBasMap_" + i, JSON.toJSONString(basMap));
+                redisUtil.set(RedisKeyType.MAP.key + i, JSON.toJSONString(basMap));
             }
         }
     }
@@ -629,7 +667,7 @@
     public synchronized void restartTaskFromRedis() {
         HashMap<Object, Object> map = redisUtil.getRedis();
         for (Object key : map.keySet()) {
-            if (key.toString().contains("lift_wrk_no_")) {//鎻愬崌鏈轰换鍔�
+            if (key.toString().contains(RedisKeyType.LIFT.key)) {//鎻愬崌鏈轰换鍔�
                 LiftRedisCommand redisCommand = JSON.parseObject(map.get(key).toString(), LiftRedisCommand.class);
                 if (redisCommand == null) {
                     continue;
@@ -652,7 +690,7 @@
                 liftProtocol.setTaskNo(redisCommand.getWrkNo());//灏嗘彁鍗囨満绾跨▼鍒嗛厤浠诲姟鍙�
                 liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//宸ヤ綔鐘舵��
 
-            }else if(key.toString().contains("shuttle_wrk_no_")){//鍥涘悜绌挎杞︿换鍔�
+            }else if(key.toString().contains(RedisKeyType.SHUTTLE.key)){//鍥涘悜绌挎杞︿换鍔�
                 ShuttleRedisCommand redisCommand = JSON.parseObject(map.get(key).toString(), ShuttleRedisCommand.class);
                 if (redisCommand == null) {
                     continue;
@@ -1175,7 +1213,7 @@
 
             //鑾峰彇鎻愬崌鏈哄懡浠�
             NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
-            if (wrkMast.getIoType() == 53) {
+            if (wrkMast.getIoType() == 53 || wrkMast.getIoType() == 57) {
                 //鎷f枡鍐嶅洖搴擄紝閲嶆柊鍒嗛厤璁惧宸ヤ綔鍙�
                 Random random = new Random();
                 int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙�
@@ -2033,10 +2071,10 @@
     }
 
     /**
-     * AGV琛ヨ揣 => 鏈烘鑷傛嫞鏂�
+     * AGV琛ヨ揣 => 鐢熸垚鍏ュ簱閫氱煡妗�
      */
-    public void agvRestockByRobot() {
-        //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
+    public void robotGenerateAgvTask() {
+//妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
         for (DevpSlave devp : slaveProperties.getDevp()) {
             // 鑾峰彇鍏ュ簱绔欎俊鎭�
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
@@ -2066,7 +2104,7 @@
                     } else if (staProtocol317.isAutoing() && !staProtocol317.isLoading()) {
                         //鑷姩銆佹棤鐗�
                         targetSta = (short) 317;
-                    }else {
+                    } else {
                         continue;//娌℃湁绌洪棽绔欑偣
                     }
 
@@ -2125,9 +2163,23 @@
                     }
                 }
             }
+        }
+    }
 
+    /**
+     * AGV琛ヨ揣 => 鏈烘鑷傛嫞鏂�
+     */
+    public void agvRestockByRobot() {
+        //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 鑾峰彇鍏ュ簱绔欎俊鎭�
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
             StaProtocol staProtocol303 = devpThread.getStation().get(303);
             StaProtocol staProtocol317 = devpThread.getStation().get(317);
+            if (staProtocol303 == null || staProtocol317 == null) {
+                continue;
+            }
+
             if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) {
                 //璋冨害鏈烘鑷�
                 //鏌ヨ鏄惁鏈夊伐浣滄。
@@ -2235,6 +2287,40 @@
         return false;
     }
 
+    /**
+     * AGV琛ヨ揣(鎮寕绾块�氱煡AGV鍙栬揣)
+     */
+    public void agvRestockIntoByHangingWire() {
+        //妫�娴�350鍜�351鎵爜鍣�
+        int[] barcodeStaNo = {11, 12};//11 => 350绔欐壂鐮佸櫒,12 => 351绔欐壂鐮佸櫒
+        for (int staNo : barcodeStaNo) {
+            // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+            BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, staNo);
+            if (barcodeThread == null) {
+                continue;
+            }
+            String barcode = barcodeThread.getBarcode();
+            if(!Cools.isEmpty(barcode)) {
+                if (barcode.contains("NoRead")) {
+                    continue;
+                }
+
+                String agvStaNo = null;
+                if (staNo == 11) {
+                    agvStaNo = "303-1";
+                }else {
+                    agvStaNo = "304-1";
+                }
+                //閫氱煡AGV鍙栬揣
+                boolean result = agvRestockCall(agvStaNo, barcode);
+                if (result) {
+                    barcodeThread.setBarcode("");
+                }
+                log.info(barcodeThread.getSlave().getId() + "鍙锋壂鐮佸櫒锛岄�氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
+            }
+        }
+    }
+
     // 300绔欐嫞鏂�
     public void pick300() {
         //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
@@ -2332,8 +2418,64 @@
                 ledCommand.setLocNo(wrkMast.getLocNo());
                 ledCommand.setStaNo(wrkMast.getStaNo());
                 if (wrkMast.getIoType() != 110 && wrkMast.getIoType() != 10) {
-                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
-                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme(),wrkDetl.getSpecs())));
+                    //for (WrkDetl wrkDetl : wrkDetls) {
+                    //    LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr()));
+                    //
+                    //    locDetls.forEach(locDetl1 -> {
+                    //        //宸ヤ綔妗d腑瀛樺湪璇ョ墿鏂欏垯璺宠繃
+                    //        String suppCode = "";
+                    //
+                    //        if (wrkDetl.getMatnr().equals(locDetl1.getMatnr())) {
+                    //            Double anfme = 0D;
+                    //            if (locDetl != null) {
+                    //                anfme = locDetl.getAnfme();
+                    //            }
+                    //            if (wrkDetl.getSuppCode() != null) {
+                    //                suppCode = wrkDetl.getSuppCode();
+                    //            }
+                    //            ledCommand.getMatDtos()
+                    //                    .add(new MatDto(wrkDetl.getMatnr()
+                    //                            , wrkDetl.getMaktx()
+                    //                            , wrkDetl.getAnfme()
+                    //                            , (wrkDetl.getAnfme()-anfme)
+                    //                            , wrkDetl.getSpecs()
+                    //                            , suppCode));
+                    //        } else {
+                    //            if (locDetl1.getSuppCode() != null) {
+                    //                suppCode = locDetl1.getSuppCode();
+                    //            }
+                    //            ledCommand.getMatDtos()
+                    //                    .add(new MatDto(locDetl1.getMatnr()
+                    //                            , locDetl1.getMaktx()
+                    //                            , 0D
+                    //                            , locDetl1.getAnfme()
+                    //                            , locDetl1.getSpecs()
+                    //                            , suppCode));
+                    //        }
+                    //    });
+                    //    //LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("zpallet", wrkDetl.getZpallet()).eq("matnr", wrkDetl.getMatnr()));
+                    //}
+                    List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", wrkMast.getSourceLocNo()));
+                    locDetls.forEach(locDetl -> {
+                        Wrapper<WrkDetl> wrapper = new EntityWrapper<WrkDetl>().eq("matnr", locDetl.getMatnr()).eq("wrk_no",wrkMast.getWrkNo());
+                        Utils.wapperSetCondition(wrapper,"batch",locDetl.getBatch());
+                        Utils.wapperSetCondition(wrapper,"three_code",locDetl.getThreeCode());
+                        Utils.wapperSetCondition(wrapper,"dead_time",locDetl.getDeadTime());
+                        WrkDetl detl = wrkDetlService.selectOne(wrapper);
+                        if (Cools.isEmpty(detl)) {
+                            String suppCode = "";
+                            if (locDetl.getSuppCode() != null) {
+                                suppCode = locDetl.getSuppCode();
+                            }
+                            ledCommand.getMatDtos().add(new MatDto(locDetl.getMatnr(), locDetl.getMaktx(), 0D, locDetl.getAnfme(), locDetl.getSpecs(), suppCode));
+                        } else {
+                            String suppCode = "";
+                            if (detl.getSuppCode() != null) {
+                                suppCode = detl.getSuppCode();
+                            }
+                            ledCommand.getMatDtos().add(new MatDto(detl.getMatnr(), detl.getMaktx(), detl.getAnfme(), (locDetl.getAnfme() - detl.getAnfme()), detl.getSpecs(), suppCode));
+                        }
+                    });
                 }
                 commands.add(ledCommand);
             }
@@ -2346,20 +2488,11 @@
             }
             // 鍛戒护涓嬪彂 -------------------------------------------------------------------------------
             if (!commands.isEmpty()) {
-                if (led.getId()>3){
-                    if (!MessageQueue.offer(SlaveType.Led, led.getId()-3, new Task(1, commands))) {
-                        log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId()-3, led.getIp(), led.getPort());
-                        continue;
-                    }else {
-                        ledThread.setLedMk(false);
-                    }
+                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
+                    log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    continue;
                 }else {
-                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
-                        log.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
-                        continue;
-                    }else {
-                        ledThread.setLedMk(false);
-                    }
+                    ledThread.setLedMk(false);
                 }
             }
 
@@ -2388,35 +2521,36 @@
      * 鍏朵粬  ===>> LED鏄剧ず鍣ㄥ浣嶏紝鏄剧ず榛樿淇℃伅
      */
     public void ledReset() {
-        for (LedSlave led : slaveProperties.getLed()) {
-
-            // 鑾峰彇杈撻�佺嚎plc绾跨▼
-            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
-            // 鍛戒护闆嗗悎
-            boolean reset = true;
-            for (Integer staNo : led.getStaArr()) {
-                // 鑾峰彇鍙夎溅绔欑偣
-                StaProtocol staProtocol = devpThread.getStation().get(staNo);
-                if (staProtocol == null) {
-                    continue;
-                }
-                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
-                    reset = false;
-                    break;
-                }
-            }
-            // 鑾峰彇led绾跨▼
-            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
-            // led鏄剧ず榛樿鍐呭
-            if (reset && !ledThread.isLedMk()) {
-                ledThread.setLedMk(true);
-                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
-                    News.error(" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
-                } else {
-
-                }
-            }
-        }
+//        for (LedSlave led : slaveProperties.getLed()) {
+//
+//            // 鑾峰彇杈撻�佺嚎plc绾跨▼
+//            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
+//            // 鍛戒护闆嗗悎
+//            boolean reset = true;
+//            for (Integer staNo : led.getStaArr()) {
+//                // 鑾峰彇鍙夎溅绔欑偣
+//                StaProtocol staProtocol = devpThread.getStation().get(staNo);
+//                if (staProtocol == null) {
+//                    continue;
+//                }
+//                if (staProtocol.getWorkNo() != 0 && staProtocol.isLoading()) {
+//                    reset = false;
+//                    break;
+//                }
+//            }
+//            // 鑾峰彇led绾跨▼
+//            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
+//            // led鏄剧ず榛樿鍐呭
+//            if (reset && !ledThread.isLedMk()) {
+//                ledThread.setLedMk(true);
+//                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
+//                    News.error(" - {}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+//                } else {
+//                    News.error("{}鍙稬ED鍛戒护涓嬪彂鎴愬姛锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+//                    ledThread.setLedMk(false);
+//                }
+//            }
+//        }
         for (LedSlave led : slaveProperties.getLed()) {
             // 鑾峰彇杈撻�佺嚎plc绾跨▼
             DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
@@ -2435,9 +2569,13 @@
             LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
             // led鏄剧ず榛樿鍐呭
             if (reset && !ledThread.isLedMk()) {
-                ledThread.setLedMk(true);
+                ledThread.setLedMk(false);
                 if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                     News.error("{}鍙稬ED鍛戒护涓嬪彂澶辫触锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                }else {
+//                    News.error("{}鍙稬ED鍛戒护涓嬪彂鎴愬姛锛侊紒锛乕ip锛歿}] [port锛歿}]", led.getId(), led.getIp(), led.getPort());
+                    MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()));
+                    ledThread.setLedMk(false);
                 }
             }
         }
@@ -3160,43 +3298,26 @@
                 return false;
             }
 
-            //璺ㄦゼ灞傜Щ鍔ㄤ换鍔�
-            if (Utils.getLev(wrkMast.getSourceLocNo()) != Utils.getLev(wrkMast.getLocNo())) {
-                //鑾峰彇鐩爣绔�
-                LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
-                if (liftSta == null) {
-                    return false;//鎵句笉鍒扮珯鐐�
-                }
-
-                //*************灏濊瘯瑙i攣鐩爣绔欒矾寰�***************
-                List<NavigateNode> targetNodes = NyLiftUtils.getLiftStaNodes(liftSta.getStaNo());
-                if (targetNodes == null) {
-                    return false;//鏈幏鍙栧埌鑺傜偣
-                }
-                //灏濊瘯瑙i攣鐩爣绔欒矾寰�
-                boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), targetNodes, false);//鎵�浣跨敤鐨勮矾寰勮繘琛岃В閿�
-                if (!result) {
-                    return false;//璺緞瑙i攣澶辫触
-                }
-                //*************灏濊瘯瑙i攣鐩爣绔欒矾寰�***************
-            }
-
-//            //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-//            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
-//            if (targetBasDevp == null) {
-//                return false;//缂哄皯绔欑偣淇℃伅
-//            }
+//            //璺ㄦゼ灞傜Щ鍔ㄤ换鍔�
+//            if (Utils.getLev(wrkMast.getSourceLocNo()) != Utils.getLev(wrkMast.getLocNo())) {
+//                //鑾峰彇鐩爣绔�
+//                LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+//                if (liftSta == null) {
+//                    return false;//鎵句笉鍒扮珯鐐�
+//                }
 //
-//            //鑾峰彇鎻愬崌鏈烘暟鎹�
-//            BasLift basLift = basLiftService.selectById(targetBasDevp.getLiftNo());
-//            if (basLift == null) {
-//                return false;//娌℃湁鎻愬崌鏈烘暟鎹�
+//                //*************灏濊瘯瑙i攣鐩爣绔欒矾寰�***************
+//                List<NavigateNode> targetNodes = NyLiftUtils.getLiftStaNodes(liftSta.getStaNo());
+//                if (targetNodes == null) {
+//                    return false;//鏈幏鍙栧埌鑺傜偣
+//                }
+//                //灏濊瘯瑙i攣鐩爣绔欒矾寰�
+//                boolean result = navigateMapUtils.writeNavigateNodeToRedisMap(Utils.getLev(wrkMast.getLocNo()), targetNodes, false);//鎵�浣跨敤鐨勮矾寰勮繘琛岃В閿�
+//                if (!result) {
+//                    return false;//璺緞瑙i攣澶辫触
+//                }
+//                //*************灏濊瘯瑙i攣鐩爣绔欒矾寰�***************
 //            }
-//            if (basLift.getPoint() == null) {
-//                return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
-//            }
-//            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
-//            liftNode.setZ(basLift.getPoint$().getZ());
 
             //灏忚溅宸茬粡鍦ㄧ洰鏍囧簱浣嶏紝鐩存帴璁ゅ畾灏忚溅绉诲姩浠诲姟瀹屾垚
             if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
@@ -3225,8 +3346,32 @@
                 return false;
             }
 
-            //鑾峰彇灏忚溅鍒扮洰鏍囧簱浣嶅懡浠�
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id);
+            NyShuttleOperaResult result = null;
+            //璺ㄦゼ灞傜Щ鍔ㄤ换鍔�
+            if (Utils.getLev(wrkMast.getSourceLocNo()) != Utils.getLev(wrkMast.getLocNo())) {
+                //闇�瑕佸皢鍓嶄袱涓妭鐐逛綔涓虹櫧鍚嶅崟鑺傜偣浼犲叆
+                //鑾峰彇鐩爣绔�
+                LiftStaProtocol liftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+                if (liftSta == null) {
+                    return false;//鎵句笉鍒扮珯鐐�
+                }
+
+                List<NavigateNode> targetNodes = NyLiftUtils.getLiftStaNodes(liftSta.getStaNo());
+                if (targetNodes == null) {
+                    return false;//鏈幏鍙栧埌鑺傜偣
+                }
+
+                //璁剧疆璁$畻鑺傜偣鐨勭櫧鍚嶅崟
+                ArrayList<int[]> whiteList = new ArrayList<>();//璁剧疆璁$畻鑺傜偣鐨勭櫧鍚嶅崟
+                for (NavigateNode node : targetNodes) {
+                    whiteList.add(new int[]{node.getX(), node.getY()});
+                }
+                result = NyShuttleOperaUtils.getStartToTargetCommandsByWhites(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id, whiteList);
+            }else {
+                //鑾峰彇灏忚溅鍒扮洰鏍囧簱浣嶅懡浠�
+                result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id);
+            }
+
             if (result == null) {
                 return false;//璺緞璁$畻澶辫触
             }

--
Gitblit v1.9.1