From 03e68b2be24ea024eae645c47da1d4cb1773302a Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 13 十月 2023 19:47:13 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  296 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 227 insertions(+), 69 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 15852c4..5b6cae4 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -698,38 +698,6 @@
                 continue;
             }
         }
-
-
-
-
-        // 鏍规嵁杈撻�佺嚎plc閬嶅巻
-        for (DevpSlave devp : slaveProperties.getDevp()) {
-            // 閬嶅巻鍏ュ簱绔�
-            for (DevpSlave.StaRack staRack : devp.getRackInStn()) {
-                // 鑾峰彇鍏ュ簱绔欎俊鎭�
-                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
-                StaProtocol staProtocol = devpThread.getStation().get(staRack.getStaNo());
-                if (staProtocol == null) {
-                    continue;
-                } else {
-                    staProtocol = staProtocol.clone();
-                }
-                Short workNo = staProtocol.getWorkNo();
-                BasDevp basDevp = basDevpService.selectById(staProtocol.getSiteId());
-                if (basDevp == null) {
-                    continue;//绔欑偣淇℃伅涓嶅瓨鍦�
-                }
-
-                // 鍒ゆ柇鏄惁婊¤冻鍏ュ簱鏉′欢锛岃嚜鍔ㄣ�佹湁鐗┿�佸洓鍚戠┛姊溅鍙彇淇″彿
-                if (!(staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isShuttleTakeEnable())) {
-                    continue;
-                }
-
-
-
-            }
-        }
-
     }
 
 //    /**
@@ -1176,6 +1144,12 @@
 
             //鑾峰彇鎻愬崌鏈哄懡浠�
             NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_TRAY.id, startSta, targetSta, wrkMast.getWrkNo());
+            if (wrkMast.getIoType() == 53) {
+                //鎷f枡鍐嶅洖搴擄紝閲嶆柊鍒嗛厤璁惧宸ヤ綔鍙�
+                Random random = new Random();
+                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙�
+                liftCommand.setTaskNo((short) deviceWrk);
+            }
             ArrayList<NyLiftCommand> commands = new ArrayList<>();
             commands.add(liftCommand);
 
@@ -1216,16 +1190,27 @@
                 return false;
             }
 
-            //璋冨害灏忚溅閬胯
-            boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
-            if (!result) {
-                return false;
-            }
-
             //鑾峰彇鍑哄簱绔欑偣(鐩爣绔�)
             BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
             if (basDevp == null) {
                 return false;//鍑哄簱绔欑偣涓嶅瓨鍦�
+            }
+
+            //鑾峰彇婧愮珯瀵瑰簲鐨勭墰鐪兼彁鍗囨満绔欑偣缂栧彿(璧风偣缂栧彿)
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(basDevp.getLiftNo(), Utils.getLev(wrkMast.getSourceLocNo()));
+            if (liftStaProtocol == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+            Integer startSta = liftStaProtocol.getStaNo();
+
+            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
+            if (shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
+                //灏忚溅杩樺湪杈撻�佺珯鐐�
+                //璋冨害灏忚溅閬胯
+                boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
+                if (!result) {
+                    return false;
+                }
             }
 
             if (!basDevp.getOutEnable().equals("Y")) {
@@ -1240,6 +1225,7 @@
             if (liftProtocol == null) {
                 return false;
             }
+
             if (!liftProtocol.isIdle()) {
                 return false;
             }
@@ -1252,13 +1238,6 @@
             if (liftWrkMast != null) {
                 return false;//褰撳墠鎻愬崌鏈哄瓨鍦ㄦ湭瀹屾垚浠诲姟锛岀瓑寰呬笅涓�娆¤疆璇�
             }
-
-            //鑾峰彇婧愮珯瀵瑰簲鐨勭墰鐪兼彁鍗囨満绔欑偣缂栧彿(璧风偣缂栧彿)
-            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(liftThread.getSlave().getId(), Utils.getLev(wrkMast.getSourceLocNo()));
-            if (liftStaProtocol == null) {
-                return false;//鎵句笉鍒扮珯鐐�
-            }
-            Integer startSta = liftStaProtocol.getStaNo();
 
             //鑾风洰鏍囩珯婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
             BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
@@ -1403,7 +1382,7 @@
                     continue;
                 }
 
-                boolean step4 = this.locToLocExecuteStep4(wrkMast);//璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鍑哄簱鍙�
+                boolean step4 = this.locToLocExecuteStep4(wrkMast);//璋冨害杞﹁締鍙栬揣骞惰繍閫佸埌鐩爣搴撲綅
                 if (!step4) {
                     continue;
                 }
@@ -2025,8 +2004,43 @@
                     targetSta = (short) 317;
 
                     if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
+                        //鍚慉GV鍙戣捣缁勬墭璇锋眰
+//                        try {
+//                            HashMap<String, Object> param = new HashMap<>();
+//                            param.put("wrkNo", wrkMast.getWrkNo());
+//                            String response = new HttpHandler.Builder()
+//                                    .setUri(wmsUrl)
+//                                    .setPath("/openAGV")
+//                                    .setJson(JSON.toJSONString(param))
+//                                    .build()
+//                                    .doPost();
+//                            JSONObject jsonObject = JSON.parseObject(response);
+//                            Integer code = jsonObject.getInteger("code");
+//                            if (code.equals(200)) {//AGV缁勬墭鎴愬姛
+//                                //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
+//                                wrkMast.setStaNo(targetSta.intValue());
+//                                wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
+//                                if (wrkMastMapper.updateById(wrkMast) > 0) {
+//                                    //鍚�300绔欏啓鍏ョ洰鏍囩珯
+//                                    staProtocol = staProtocol.clone();
+//                                    staProtocol.setStaNo(targetSta);//绉诲姩鍒扮洰鏍囩珯
+//                                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+//                                    try {
+//                                        Thread.sleep(500);
+//                                    } catch (Exception e) {
+//                                        e.printStackTrace();
+//                                    }
+//                                    continue;
+//                                }
+//                            }
+//                        } catch (Exception e) {
+//                            e.printStackTrace();
+//                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+//                        }
+
                         //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
                         wrkMast.setStaNo(targetSta.intValue());
+                        wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
                         if (wrkMastMapper.updateById(wrkMast) > 0) {
                             //鍚�300绔欏啓鍏ョ洰鏍囩珯
                             staProtocol = staProtocol.clone();
@@ -2047,30 +2061,146 @@
             StaProtocol staProtocol317 = devpThread.getStation().get(317);
             if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) {
                 //璋冨害鏈烘鑷�
-//                //鏌ヨ鏄惁鏈夊伐浣滄。
-//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
-//                if (wrkMast == null) {
-//                    continue;
-//                }
-//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
-//                if (wrkDetl == null) {
-//                    continue;
-//                }
-//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "303");
-                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "303");
+                //鏌ヨ鏄惁鏈夊伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
+                if (wrkMast == null) {
+                    continue;
+                }
+                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
+                if (wrkDetls.isEmpty()) {
+                    continue;
+                }
+
+                if (wrkMast.getInvWh() == null) {
+                    wrkMast.setInvWh("Y");//鏍囪宸茬粡涓嬪彂鏈烘鑷備换鍔�
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
+                    }
+                }
             }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
                 //璋冨害鏈烘鑷�
-//                //鏌ヨ鏄惁鏈夊伐浣滄。
-//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
-//                if (wrkMast == null) {
-//                    continue;
-//                }
-//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
-//                if (wrkDetl == null) {
-//                    continue;
-//                }
-//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "317");
-                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "317");
+                //鏌ヨ鏄惁鏈夊伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
+                if (wrkMast == null) {
+                    continue;
+                }
+                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
+                if (wrkDetls.isEmpty()) {
+                    continue;
+                }
+                if (wrkMast.getInvWh() == null) {
+                    wrkMast.setInvWh("Y");//鏍囪宸茬粡涓嬪彂鏈烘鑷備换鍔�
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317");
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * AGV琛ヨ揣(閫氱煡AGV鍙栬揣)
+     */
+    public void agvRestockInto() {
+        //妫�娴�309鍜�312绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗�
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 鑾峰彇鍏ュ簱绔欎俊鎭�
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            StaProtocol staProtocol309 = devpThread.getStation().get(309);
+            StaProtocol staProtocol312 = devpThread.getStation().get(312);
+            if (staProtocol309 == null || staProtocol312 == null) {
+                continue;
+            }
+
+            if (staProtocol309.isAutoing() && staProtocol309.isLoading()) {
+                // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 11);//308绔欐潯鐮佸櫒
+                if (barcodeThread == null) {
+                    continue;
+                }
+                String barcode = barcodeThread.getBarcode();
+                if(!Cools.isEmpty(barcode)) {
+                    //閫氱煡AGV鍙栬揣
+                    agvRestockCall("CS-301-001-01@3", barcode);
+                }
+            } else if (staProtocol312.isAutoing() && staProtocol312.isLoading()) {
+                // 鑾峰彇鏉$爜鎵弿浠俊鎭�
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 12);//311绔欐潯鐮佸櫒
+                if (barcodeThread == null) {
+                    continue;
+                }
+                String barcode = barcodeThread.getBarcode();
+                if(!Cools.isEmpty(barcode)) {
+                    //閫氱煡AGV鍙栬揣
+                    agvRestockCall("CS-302-001-01@3", barcode);
+                }
+            }
+        }
+    }
+
+    //閫氱煡AGV鍙栬揣
+    private boolean agvRestockCall(String staNo, String barcode) {
+        try {
+            HashMap<String, Object> param = new HashMap<>();
+            param.put("staNo", staNo);
+            param.put("barcode", barcode);
+            String response = new HttpHandler.Builder()
+                    .setUri(wmsUrl)
+                    .setPath("/callAGV")
+                    .setJson(JSON.toJSONString(param))
+                    .build()
+                    .doPost();
+            JSONObject jsonObject = JSON.parseObject(response);
+            Integer code = jsonObject.getInteger("code");
+            if (code.equals(200)) {//鍛煎彨AGV
+                return true;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
+        return false;
+    }
+
+    // 300绔欐嫞鏂�
+    public void pick300() {
+        //妫�娴�300绔欐槸鍚﹁嚜鍔ㄣ�佹湁鐗┿�佸伐浣滃彿
+        for (DevpSlave devp : slaveProperties.getDevp()) {
+            // 鑾峰彇鍏ュ簱绔欎俊鎭�
+            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
+            StaProtocol staProtocol = devpThread.getStation().get(300);
+            if (staProtocol == null) {
+                continue;
+            }
+            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
+                //鏌ヨ鏄惁鏈夊伐浣滄。
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
+                if (wrkMast == null) {
+                    continue;
+                }
+
+                if (wrkMast.getWrkSts() != 25) {//25.鎻愬崌鏈烘惉杩愬畬鎴�
+                    continue;
+                }
+
+                if (wrkMast.getMk() == null) {
+                    Integer sourceStaNo = wrkMast.getSourceStaNo();//婧愮珯
+                    Integer staNo = wrkMast.getStaNo();//鐩爣绔�
+                    //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
+                    wrkMast.setStaNo(sourceStaNo);
+                    wrkMast.setSourceStaNo(staNo);
+                    if (wrkMastMapper.updateById(wrkMast) > 0) {
+                        //鍚�300绔欏啓鍏ョ洰鏍囩珯
+                        staProtocol = staProtocol.clone();
+                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());//绉诲姩鍒扮洰鏍囩珯
+                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
+                        try {
+                            Thread.sleep(500);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                }
             }
         }
     }
@@ -2626,7 +2756,8 @@
                 NyLiftCommand liftCommand = NyLiftUtils.getLiftCommand(liftProtocol.getLiftNo().intValue(), NyLiftTaskModelType.MOVE_CAR.id, sourceLiftSta.getStaNo(), sourceLiftSta.getStaNo(), wrkMast.getWrkNo());
 
                 Random random = new Random();
-                liftCommand.setTaskNo((short) Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999))));//鏇存崲闅忔満浠诲姟鍙�
+                int deviceWrk = Math.abs((liftCommand.getTaskNo().intValue() + random.nextInt(9999)));//鑾峰彇璁惧宸ヤ綔鍙�
+                liftCommand.setTaskNo((short) deviceWrk);//鏇存崲闅忔満浠诲姟鍙�
 
                 ArrayList<NyLiftCommand> commands = new ArrayList<>();
                 commands.add(liftCommand);
@@ -2948,6 +3079,33 @@
 //            NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
 //            liftNode.setZ(basLift.getPoint$().getZ());
 
+            //灏忚溅宸茬粡鍦ㄧ洰鏍囧簱浣嶏紝鐩存帴璁ゅ畾灏忚溅绉诲姩浠诲姟瀹屾垚
+            if (shuttleProtocol.getCurrentLocNo().equals(wrkMast.getLocNo())) {
+                if (shuttleProtocol.getToken().equals(wrkMast.getWrkNo())) {
+                    //閲婃斁灏忚溅浠ょ墝
+                    shuttleProtocol.setToken(0);
+                }
+                wrkMast.setWrkSts(111L);//111.灏忚溅绉诲姩瀹屾垚
+                wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
+                wrkMast.setModiTime(now);
+                wrkMastMapper.updateById(wrkMast);
+
+                shuttleProtocol.setShuttleNo((short) 0);//閲婃斁灏忚溅
+                shuttleProtocol.setToken(0);//閲婃斁灏忚溅
+
+                if (wrkMast.getWrkSts() == 111) {
+                    // 淇濆瓨宸ヤ綔涓绘。鍘嗗彶妗�
+                    if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {
+                        log.info("淇濆瓨宸ヤ綔鍘嗗彶妗workNo={0}]澶辫触", wrkMast.getWrkNo());
+                    }
+                    // 鍒犻櫎宸ヤ綔涓绘。
+                    if (!wrkMastService.deleteById(wrkMast)) {
+                        log.info("鍒犻櫎宸ヤ綔涓绘。[workNo={0}]澶辫触", wrkMast.getWrkNo());
+                    }
+                }
+                return false;
+            }
+
             //鑾峰彇灏忚溅鍒扮洰鏍囧簱浣嶅懡浠�
             NyShuttleOperaResult result = NyShuttleOperaUtils.getStartToTargetCommands(shuttleThread.getSlave().getId(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getLocNo(), NavigationMapType.NORMAL.id);
             if (result == null) {

--
Gitblit v1.9.1