From 8ecad328df8465b3d81c15e37943f6e9d3adf86b Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期一, 23 十月 2023 16:32:33 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java |  157 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 127 insertions(+), 30 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 01873ba..42333be 100644
--- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
+++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -25,6 +25,8 @@
 import com.zy.core.model.protocol.*;
 import com.zy.core.properties.SlaveProperties;
 import com.zy.core.thread.*;
+import com.zy.system.entity.Config;
+import com.zy.system.service.ConfigService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -102,6 +104,10 @@
     private RedisUtil redisUtil;
     @Autowired
     private WrkMastLocMapper wrkMastLocMapper;
+    @Autowired
+    private BasLiftOptService basLiftOptService;
+    @Autowired
+    private ConfigService configService;
 
 
     /**
@@ -522,6 +528,7 @@
                             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暟鎹姸鎬佸け璐�");
@@ -844,6 +851,10 @@
             BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
             if (basDevp == null) {
                 return false;//鍑哄簱绔欑偣涓嶅瓨鍦�
+            }
+
+            if (!basDevp.getAutoing().equals("Y")) {
+                return false;//涓嶆槸鑷姩鐘舵��
             }
 
             if (!basDevp.getOutEnable().equals("Y")) {
@@ -1291,8 +1302,14 @@
                     && liftProtocol.getTaskNo() != 0
                     && !liftProtocol.getBusy()
             ) {
+                BasLiftOpt basLiftOpt = basLiftOptService.selectByDeviceWrk(liftProtocol.getTaskNo().toString());
+                int taskNo = liftProtocol.getTaskNo().intValue();
+                if (basLiftOpt != null) {
+                    taskNo = basLiftOpt.getWrkNo();
+                }
+
                 //灏嗕换鍔℃。鏍囪涓哄畬鎴�
-                WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue());
+                WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(taskNo);
                 if (wrkMast != null) {
                     switch (wrkMast.getWrkSts().intValue()) {
                         case 3://3.鎻愬崌鏈烘惉杩愪腑 ==> 4.鎻愬崌鏈烘惉杩愬畬鎴�
@@ -1307,15 +1324,18 @@
                             wrkMast.setWrkSts(25L);
                             if (wrkMast.getIoType() == 11) {//搴撲綅绉昏浆
                                 wrkMast.setWrkSts(4L);//4.鎻愬崌鏈烘惉杩愬畬鎴�
+                            }else {
+                                if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) {
+                                    //涓嶉渶瑕佺敤鍒版満姊拌噦锛岀洿鎺ヨ浆29.鍑哄簱瀹屾垚
+                                    wrkMast.setWrkSts(29L);
+                                    wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
+                                    wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
+                                }
                             }
+
                             if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                 //閲婃斁鎻愬崌鏈轰护鐗�
                                 liftProtocol.setToken(0);
-                            }
-
-                            if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) {
-                                //涓嶉渶瑕佺敤鍒版満姊拌噦锛岀洿鎺ヨ浆29.鍑哄簱瀹屾垚
-                                wrkMast.setWrkSts(29L);
                             }
 
                             break;
@@ -1484,7 +1504,7 @@
             }
 
             //鑾峰彇绌挎杞︽渶杩戜笖绌洪棽鐨勬彁鍗囨満杈撻�佺珯鐐�
-            LiftStaProtocol liftSta = shuttleDispatchUtils.getRecentLiftSta(shuttleThread.getSlave().getId());
+            LiftStaProtocol liftSta = shuttleDispatchUtils.getRecentLiftSta(shuttleThread.getSlave().getId(), Utils.getLev(wrkMast.getLocNo()));
             if (liftSta == null) {
                 return false;//娌℃湁鍙敤涓旂┖闂茬殑杈撻�佺珯鐐�
             }
@@ -1530,14 +1550,47 @@
     private boolean locToLocExecuteStep3(WrkMast wrkMast) {
         Date now = new Date();
         if (wrkMast.getWrkSts() == 23) {//23.灏忚溅鎼繍瀹屾垚
+            //婧愮珯
+            Integer sourceStaNo = wrkMast.getSourceStaNo();
+            //鐩爣绔�
+            Integer staNo = wrkMast.getStaNo();
+            if (sourceStaNo == null || staNo == null) {
+                return false;//婧愮珯鎴栫洰鏍囩珯涓虹┖
+            }
+
+            int liftNo = staNo / 100;//鑾峰彇鎻愬崌鏈哄彿
+
             //鑾峰彇鎻愬崌鏈虹嚎绋�
-            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, wrkMast.getLiftNo());
+            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
             if (liftThread == null) {
                 return false;
             }
             LiftProtocol liftProtocol = liftThread.getLiftProtocol();
             if (liftProtocol == null) {
                 return false;
+            }
+
+            //鑾峰彇婧愮珯瀵瑰簲鐨勮緭閫佺珯鐐�
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(liftNo, Utils.getLev(wrkMast.getSourceLocNo()));
+            if (liftStaProtocol == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
+            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && liftStaProtocol.getHasTray())) {
+                return false;//绔欑偣蹇呴』鑷姩銆佺┖闂层�佹湁鎵樼洏
+            }
+            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
+            if (shuttleThread == null) {
+                return false;
+            }
+            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 (!liftProtocol.isIdle()) {
@@ -1548,14 +1601,6 @@
             WrkMast wrkMast1 = wrkMastMapper.selectLiftWrkMast(liftProtocol.getLiftNo().intValue());
             if (wrkMast1 != null && wrkMast1.getWrkNo().intValue() != wrkMast.getWrkNo().intValue()) {
                 return false;
-            }
-
-            //婧愮珯
-            Integer sourceStaNo = wrkMast.getSourceStaNo();
-            //鐩爣绔�
-            Integer staNo = wrkMast.getStaNo();
-            if (sourceStaNo == null || staNo == null) {
-                return false;//婧愮珯鎴栫洰鏍囩珯涓虹┖
             }
 
             //鑾峰彇鎻愬崌鏈哄懡浠�
@@ -1592,13 +1637,17 @@
     private boolean locToLocExecuteStep4(WrkMast wrkMast) {
         if (wrkMast.getWrkSts() == 4) {//4.鎻愬崌鏈烘惉杩愬畬鎴�
             //鑾峰彇鐩爣绔欏搴旂殑杈撻�佺珯鐐�
-            BasDevp targetBasDevp = basDevpService.selectByLevAndLiftNo(Utils.getLev(wrkMast.getLocNo()), wrkMast.getLiftNo());
-            if (targetBasDevp == null) {
-                return false;//缂哄皯绔欑偣淇℃伅
+            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(wrkMast.getLiftNo(), Utils.getLev(wrkMast.getLocNo()));
+            if (liftStaProtocol == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+
+            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && liftStaProtocol.getHasTray())) {
+                return false;//绔欑偣蹇呴』鑷姩銆佺┖闂层�佹湁鎵樼洏
             }
 
             if (wrkMast.getShuttleNo() == null) {
-                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), targetBasDevp.getLocNo());//璋冨害灏忚溅鍒扮洰鏍囪緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftStaProtocol.getLocNo());//璋冨害灏忚溅鍒扮洰鏍囪緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
@@ -1616,14 +1665,14 @@
             }
 
             //鍒ゆ柇灏忚溅鏄惁鍒拌揪鐩爣杈撻�佺珯鐐�
-            if (!shuttleProtocol.getCurrentLocNo().equals(targetBasDevp.getLocNo())) {
+            if (!shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
                 //灏忚溅涓嶅湪鐩爣杈撻�佺珯鐐�
-                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒扮洰鏍囪緭閫佺珯鐐硅繘琛屽彇璐�
+                shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), liftStaProtocol.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒扮洰鏍囪緭閫佺珯鐐硅繘琛屽彇璐�
                 return false;
             }
 
             //灏忚溅宸叉姷杈剧洰鏍囪緭閫佺珯鐐癸紝灏嗚揣鐗╂惉杩愬埌鐩爣搴撲綅
-            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), targetBasDevp.getLocNo(), wrkMast.getLocNo());
+            NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), liftStaProtocol.getLocNo(), wrkMast.getLocNo());
             if (result == null) {//璺緞璁$畻澶辫触
                 return false;
             }
@@ -2001,8 +2050,6 @@
                         continue;//娌℃湁绌洪棽绔欑偣
                     }
 
-                    targetSta = (short) 317;
-
                     if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
                         //鍚慉GV鍙戣捣缁勬墭璇锋眰
                         try {
@@ -2020,6 +2067,7 @@
                                 //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
                                 wrkMast.setStaNo(targetSta.intValue());
                                 wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
+                                wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
                                 if (wrkMastMapper.updateById(wrkMast) > 0) {
                                     //鍚�300绔欏啓鍏ョ洰鏍囩珯
                                     staProtocol = staProtocol.clone();
@@ -2041,6 +2089,7 @@
 //                        //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
 //                        wrkMast.setStaNo(targetSta.intValue());
 //                        wrkMast.setShuttleNo(null);//閲婃斁灏忚溅
+//                        wrkMast.setLiftNo(null);//閲婃斁鎻愬崌鏈�
 //                        if (wrkMastMapper.updateById(wrkMast) > 0) {
 //                            //鍚�300绔欏啓鍏ョ洰鏍囩珯
 //                            staProtocol = staProtocol.clone();
@@ -2112,9 +2161,9 @@
                 continue;
             }
 
-            if (staProtocol309.isAutoing() && staProtocol309.isLoading()) {
+            if (staProtocol309.isAutoing() && staProtocol309.isLoading() && staProtocol309.isInEnable()) {
                 // 鑾峰彇鏉$爜鎵弿浠俊鎭�
-                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 11);//308绔欐潯鐮佸櫒
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 9);//308绔欐潯鐮佸櫒
                 if (barcodeThread == null) {
                     continue;
                 }
@@ -2122,10 +2171,13 @@
                 if(!Cools.isEmpty(barcode)) {
                     //閫氱煡AGV鍙栬揣
                     agvRestockCall("CS-301-001-01@3", barcode);
+                    log.info("閫氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
                 }
-            } else if (staProtocol312.isAutoing() && staProtocol312.isLoading()) {
+            }
+
+            if (staProtocol312.isAutoing() && staProtocol312.isLoading() && staProtocol312.isInEnable()) {
                 // 鑾峰彇鏉$爜鎵弿浠俊鎭�
-                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 12);//311绔欐潯鐮佸櫒
+                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 10);//311绔欐潯鐮佸櫒
                 if (barcodeThread == null) {
                     continue;
                 }
@@ -2133,6 +2185,7 @@
                 if(!Cools.isEmpty(barcode)) {
                     //閫氱煡AGV鍙栬揣
                     agvRestockCall("CS-302-001-01@3", barcode);
+                    log.info("閫氱煡AGV鍙栬揣锛屾潯鐮佸彿锛�" + barcode);
                 }
             }
         }
@@ -2179,7 +2232,7 @@
                     continue;
                 }
 
-                if (wrkMast.getWrkSts() != 25) {//25.鎻愬崌鏈烘惉杩愬畬鎴�
+                if (wrkMast.getWrkSts() != 29) {//29.鍑哄簱瀹屾垚
                     continue;
                 }
 
@@ -2189,6 +2242,7 @@
                     //瑕嗙洊宸ヤ綔妗g洰鏍囩珯
                     wrkMast.setStaNo(sourceStaNo);
                     wrkMast.setSourceStaNo(staNo);
+                    wrkMast.setMk("N");
                     if (wrkMastMapper.updateById(wrkMast) > 0) {
                         //鍚�300绔欏啓鍏ョ洰鏍囩珯
                         staProtocol = staProtocol.clone();
@@ -2500,7 +2554,16 @@
                 }
             } else if (wrkCharge.getWrkSts() == 52) {
                 //妫�娴嬪皬杞︽槸鍚︽弧鐢�
+
+                //鑾峰彇婊$數闃堝��
                 int maxPower = 95;
+                EntityWrapper<Config> wrapper = new EntityWrapper<>();
+                wrapper.eq("code", "chargeMaxValue");
+                Config config = configService.selectOne(wrapper);
+                if (config != null) {
+                    maxPower = Integer.parseInt(config.getValue());
+                }
+
                 if (shuttleProtocol.getPowerPercent() < maxPower) {
                     continue;
                 }
@@ -2794,6 +2857,27 @@
                 return false;
             }
 
+            //*************灏濊瘯閿佸畾鐩爣绔欒矾寰�***************
+            //鑾峰彇鐩爣绔�
+            LiftStaProtocol targetLiftSta = NyLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
+            if (targetLiftSta == null) {
+                return false;//鎵句笉鍒扮珯鐐�
+            }
+            NavigateNode targetNode = NavigatePositionConvert.locNoToNode(targetLiftSta.getLocNo());//鐩爣鑺傜偣
+            NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(wrkMast.getLocNo()));
+            List<NavigateNode> targetNodes = new ArrayList<>();
+            targetNodes.add(targetNode);
+            boolean checkPathIsAvailable = NavigateUtils.checkPathIsAvailable(targetNodes, shuttleProtocol.getShuttleNo().intValue(), Utils.getLev(wrkMast.getLocNo()), null);
+            if (!checkPathIsAvailable) {
+                return false;//妫�娴嬬洰鏍囩珯鐐硅矾寰勬槸鍚︽湭琚崰鐢�
+            }
+            //灏濊瘯閿佸畾鐩爣绔欒矾寰�
+            boolean result = navigateMapData.writeNavigateNodeToRedisMap(targetNodes, true);//鎵�浣跨敤鐨勮矾寰勮繘琛岄攣瀹氱鐢�
+            if (!result) {
+                return false;//璺緞閿佸畾澶辫触
+            }
+            //*************灏濊瘯閿佸畾鐩爣绔欒矾寰�***************
+
             //绔欑偣鑺傜偣
             NavigateNode staNode = NavigatePositionConvert.locNoToNode(sourceLiftSta.getLocNo());
 
@@ -2996,6 +3080,19 @@
             if (basLift.getPoint() == null) {
                 return false;//娌℃湁璁剧疆鎻愬崌鏈虹偣浣嶅潗鏍�
             }
+
+            //*************灏濊瘯瑙i攣鐩爣绔欒矾寰�***************
+            NavigateNode targetNode = NavigatePositionConvert.locNoToNode(liftSta.getLocNo());//鐩爣鑺傜偣
+            NavigateMapData navigateMapData = new NavigateMapData(Utils.getLev(wrkMast.getLocNo()));
+            List<NavigateNode> targetNodes = new ArrayList<>();
+            targetNodes.add(targetNode);
+            //灏濊瘯瑙i攣鐩爣绔欒矾寰�
+            boolean result = navigateMapData.writeNavigateNodeToRedisMap(targetNodes, false);//鎵�浣跨敤鐨勮矾寰勮繘琛岃В閿�
+            if (!result) {
+                return false;//璺緞瑙i攣澶辫触
+            }
+            //*************灏濊瘯瑙i攣鐩爣绔欒矾寰�***************
+
             NavigateNode liftNode = new NavigateNode(basLift.getPoint$().getX(), basLift.getPoint$().getY());
             liftNode.setZ(liftSta.getLev());
 

--
Gitblit v1.9.1