From 79faeb50583ce89fb741c76986e41a3666f91c11 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期三, 02 八月 2023 13:02:22 +0800 Subject: [PATCH] 搜索是否有其他任务占用了提升机 --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 311 ++++++++++++++++++--------------------------------- 1 files changed, 110 insertions(+), 201 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 398e5e0..8d4bafe 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -635,11 +635,11 @@ } Short shuttleNo = redisCommand.getShuttleNo(); - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue()); + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo.intValue()); if (shuttleThread == null) { continue; } - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } @@ -648,7 +648,7 @@ } //鍥涘悜绌挎杞﹀浜庣┖闂茬姸鎬侊紝杩涜浠诲姟鐨勬仮澶� - shuttleProtocol.setTaskNo(redisCommand.getWrkNo());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙� + shuttleProtocol.setTaskNo(redisCommand.getWrkNo().intValue());//灏嗗洓鍚戠┛姊溅绾跨▼鍒嗛厤浠诲姟鍙� shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.WORKING);//宸ヤ綔鐘舵�� } } @@ -710,11 +710,11 @@ } //鑾峰彇鍥涘悜绌挎杞︾嚎绋� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } @@ -782,11 +782,11 @@ } //鑾峰彇鍥涘悜绌挎杞︾嚎绋� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); if (shuttleThread == null) { return false; } - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { return false; } @@ -831,132 +831,6 @@ return false; } return true; - } - - /** - * 鎼滅储绌洪棽涓旀渶杩戠殑鍥涘悜绌挎杞�(浠ュ伐浣滄。鐩爣搴撲綅涓哄熀鐐硅绠楁渶杩戜笖绌洪棽鐨勮溅) - */ - public HashMap<String,Object> searchIdleShuttle(WrkMast wrkMast) { - HashMap<String, Object> map = new HashMap<>(); - String locNo = wrkMast.getIoType() < 101 ? wrkMast.getLocNo() : wrkMast.getSourceLocNo();//搴撲綅鍙� - LocMast locMast = locMastService.queryByLoc(locNo);//鎵惧埌搴撲綅璁板綍 - int lev = Utils.getLev(locNo);//褰撳墠宸ヤ綔妗e簱浣嶅眰楂� - ShuttleThread recentShuttle = null;//褰撳墠璺濈鏈�杩戠殑鍥涘悜绌挎杞︾嚎绋� - - ArrayList<ShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅 - ArrayList<ShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅 - - //鍒ゆ柇鍏朵粬绌洪棽绌挎杞︽槸鍚︾浠诲姟鏈�杩� - String distLocNo = null;//鐩爣鍦扮偣锛屽叆搴�=銆嬫彁鍗囨満鍙o紝鍑哄簱=銆嬭揣鐗╁簱浣嶅彿 - if (wrkMast.getIoType() < 101 && wrkMast.getIoType() != 11) { - //鍏ュ簱 - distLocNo = Utils.levToOutInStaLocNo(lev); - }else if(wrkMast.getIoType() >= 101){ - //鍑哄簱 - distLocNo = locNo; - } else if (wrkMast.getIoType() == 11) { - //搴撲綅绉昏浆 - distLocNo = wrkMast.getSourceLocNo(); - } - - //鍒ゆ柇褰撳墠浠诲姟鎵�鍦ㄦゼ灞傛槸鍚︽湁鍏朵粬浠诲姟宸茬粡鍒嗛厤浜嗗皬杞︼紝濡傛湁鍒欑洿鎺ョ敤璇ュ皬杞�(涓�灞傛ゼ浠呭垎閰嶄竴鍙拌溅) - List<WrkMast> wrkMasts = wrkMastService.selectShuttleWrkByLev(lev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚﹀凡鏈夊垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欏垎閰嶈繖杈嗚溅 - if (wrkMasts.size() > 0) { - //瀛樺湪鍏朵粬浠诲姟锛屽垎閰嶈繖杈嗚溅 - WrkMast wrkMast1 = wrkMasts.get(0); - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast1.getShuttleNo()); - - map.put("sameLay", true);//鍚屽眰 - map.put("result", shuttleThread); - return map; - } - - for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { - //鑾峰彇鍥涘悜绌挎杞︾嚎绋� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); - if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { - continue; - } - if (!shuttleProtocol.isIdle()) { - continue; - } - - String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿 - if (shuttleLocNo == null) { - continue; - } - - if (shuttleLocNo.equals(distLocNo)) { - //杞﹁締褰撳墠浣嶇疆宸茬粡鏄洰鏍囧簱浣嶏紝鏃犻渶璁$畻 - map.put("sameLay", true);//鍚屽眰 - map.put("result", shuttleThread); - return map; - } - - int shuttleLocNoLey = Utils.getLev(shuttleLocNo);//搴撲綅鍙峰搴斿眰楂� - if (lev == shuttleLocNoLey) { - //宸ヤ綔妗fゼ灞傜浉鍚岀殑绌挎杞� - sameLev.add(shuttleThread); - }else { - //宸ヤ綔妗d笉鍚屾ゼ灞傜殑绌挎杞� - diffLev.add(shuttleThread); - } - - } - - Integer recentAllDistance = 9999999; - if (sameLev.size() > 0) { - //鍚屼竴妤煎眰鏈夌┖闂茬┛姊溅锛屽垯鍙湪宸ヤ綔妗fゼ灞傚鎵� - //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞� - for (ShuttleThread shuttleThread : sameLev) { - //褰撳墠绌挎杞﹀簱浣嶅彿 - String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); - //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈 - List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, distLocNo, NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), Utils.getLev(currentLocNo)));//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘 - if (currentShuttlePath == null) { - continue; - } - Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - if (currentAllDistance < recentAllDistance) { - //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅 - recentShuttle = shuttleThread; - } - } - - map.put("sameLay", true);//鍚屽眰 - map.put("result", recentShuttle); - }else { - //鍚屼竴妤煎眰锛屾病鏈夌┖闂茬┛姊溅锛屽彧鑳戒粠鍏朵粬妤煎眰璋冨害 - //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞� - for (ShuttleThread shuttleThread : diffLev) { - - //褰撳墠绌挎杞﹀簱浣嶅彿 - String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); - int currentLev = Utils.getLev(currentLocNo); - List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞� - if (wrkMasts1.size() > 0) { - //瀛樺湪鍏朵粬浠诲姟锛岃烦杩囪繖杈嗚溅 - continue; - } - - //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄彛璺濈 - List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘 - if (currentShuttlePath == null) { - continue; - } - - Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - if (currentAllDistance < recentAllDistance) { - //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅 - recentShuttle = shuttleThread; - } - } - - map.put("sameLay", false);//涓嶅悓灞� - map.put("result", recentShuttle); - } - return map; } /** @@ -1253,8 +1127,7 @@ //鏌ヨ搴撲綅绉昏浆宸ヤ綔妗� List<WrkMast> wrkMasts1 = wrkMastMapper.selectLocToLocWrkMast(); for (WrkMast wrkMast : wrkMasts1) { - - boolean step1 = this.locToLocExecuteStep1(wrkMast);//缁戝畾灏忚溅 + boolean step1 = this.locToLocExecuteStep1(wrkMast);//搴撲綅绉昏浆 if (!step1) { continue; } @@ -1263,22 +1136,58 @@ } /** - * 缁戝畾灏忚溅骞惰皟搴﹁溅 + * 搴撲綅绉昏浆 * 濡傞渶涓绘柟娉曟墽琛宑ontinue锛岃杩斿洖false * ps:杩斿洖鍊紅rue骞朵笉浠h〃璇ユ柟娉曟墽琛屾垚鍔燂紝杩斿洖鍊间粎鍋氭爣璁扮敤浜庝富鏂规硶鏄惁鎵цcontinue */ private boolean locToLocExecuteStep1(WrkMast wrkMast) { - if (wrkMast.getShuttleNo() == null) {//缁欏簱浣嶇Щ杞粦瀹氱┛姊溅鍙� - //瀵绘壘鏈�杩戜笖绌洪棽鐨勫洓鍚戠┛姊溅 - HashMap<String,Object> searchIdleShuttle = this.searchIdleShuttle(wrkMast); - ShuttleThread shuttleThread = (ShuttleThread) searchIdleShuttle.get("result"); - if (shuttleThread == null) { - //娌℃湁鎵惧埌绌洪棽绌挎杞� - return false; - } - wrkMast.setShuttleNo(shuttleThread.getSlave().getId());//缁欏伐浣滄。鍒嗛厤鍥涘悜绌挎杞﹀彿 - wrkMastMapper.updateById(wrkMast); + if (wrkMast.getShuttleNo() == null) { + shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣 + return false; } + + //鑾峰彇鍥涘悜绌挎杞︾嚎绋� + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo()); + if (shuttleThread == null) { + return false; + } + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + if (shuttleProtocol == null) { + return false; + } + if (!shuttleProtocol.isIdle()) { + return false; + } + + //鍒ゆ柇灏忚溅鏄惁鍒拌揪婧愬簱浣� + if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) { + //灏忚溅涓嶅湪婧愬簱浣嶄綅缃� + shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒版簮搴撲綅杩涜鍙栬揣 + return false; + } + + //灏忚溅宸叉姷杈炬簮搴撲綅锛岃繘琛屾惉杩愯揣鐗� + NyShuttleOperaResult result = NyShuttleOperaUtils.getShuttleTransportCommands(wrkMast.getShuttleNo(), wrkMast.getWrkNo(), shuttleProtocol.getCurrentLocNo(), wrkMast.getSourceLocNo(), wrkMast.getLocNo()); + if (result == null) {//璺緞璁$畻澶辫触 + return false; + } + + //鍒涘缓鍒嗛厤鍛戒护 + ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); + assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿 + assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());//浠诲姟鍙� + assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue());//鍏ュ簱妯″紡 + assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆) + assignCommand.setCommands(result.getCommands());//杩愯鍛戒护 + assignCommand.setNodes(result.getNodes());//璺緞鑺傜偣 + + wrkMast.setWrkSts(5L);//1.鐢熸垚鍏ュ簱浠诲姟 => 5.灏忚溅鎼繍涓� + wrkMast.setModiTime(new Date()); + if (wrkMastMapper.updateById(wrkMast) > 0) { + //涓嬪彂浠诲姟 + MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); + } + return true; } @@ -1299,27 +1208,27 @@ private void recShuttleErr() { Date now = new Date(); for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) { - // 鑾峰彇鍫嗗灈鏈轰俊鎭� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId()); + // 鑾峰彇鍥涘悜绌挎杞︿俊鎭� + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId()); if (shuttleThread == null) { continue; } - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } if (shuttleProtocol.getTaskNo() != 0) { //鏈変换鍔� - BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo().intValue()); + BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo()); // 鏈夊紓甯� if (latest == null) { - if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) { + if (shuttleProtocol.getErrState() != null && shuttleProtocol.getErrState() == 1) { WrkMast wrkMast = wrkMastMapper.selectById(shuttleProtocol.getTaskNo()); if (wrkMast == null) { continue; } - BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue()); + BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getErrCode().get(0)); String errName = basShuttleErr==null? "鏈煡寮傚父":basShuttleErr.getErrName(); BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog( null, // 缂栧彿 @@ -1335,7 +1244,7 @@ wrkMast.getSourceStaNo(), // 婧愮珯 wrkMast.getSourceLocNo(), // 婧愬簱浣� wrkMast.getBarcode(), // 鏉$爜 - (int) shuttleProtocol.getStatusErrorCode(), // 寮傚父鐮� + shuttleProtocol.getErrCode().get(0), // 寮傚父鐮� errName, // 寮傚父 1, // 寮傚父鎯呭喌 now, // 娣诲姞鏃堕棿 @@ -1350,7 +1259,7 @@ } } else { // 寮傚父淇 - if (shuttleProtocol.getStatusErrorCode() == null || shuttleProtocol.getStatusErrorCode() == 0) { + if (shuttleProtocol.getErrState() == null || shuttleProtocol.getErrState() == 0) { latest.setEndTime(now); latest.setUpdateTime(now); latest.setStatus(2); @@ -1360,53 +1269,53 @@ } } }else { - //鏃犱换鍔� - BasShuttleErrLog latest = basShuttleErrLogService.findLatest(shuttleSlave.getId()); - // 鏈夊紓甯� - if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) { - // 璁板綍鏂板紓甯� - if (latest == null || (latest.getErrCode() != shuttleProtocol.getStatusErrorCode().intValue())) { - BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue()); - String errName = basShuttleErr==null? "鏈煡寮傚父":basShuttleErr.getErrName(); - BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog( - null, // 缂栧彿 - null, // 宸ヤ綔鍙� - now, // 鍙戠敓鏃堕棿 - null, // 缁撴潫鏃堕棿 - null, // 宸ヤ綔鐘舵�� - null, // 鍏ュ嚭搴撶被鍨� - shuttleSlave.getId(), // 鍥涘悜绌挎杞� - null, // plc - null, // 鐩爣搴撲綅 - null, // 鐩爣绔� - null, // 婧愮珯 - null, // 婧愬簱浣� - null, // 鏉$爜 - (int)shuttleProtocol.getStatusErrorCode(), // 寮傚父鐮� - errName, // 寮傚父 - 1, // 寮傚父鎯呭喌 - now, // 娣诲姞鏃堕棿 - null, // 娣诲姞浜哄憳 - now, // 淇敼鏃堕棿 - null, // 淇敼浜哄憳 - "鏃犱换鍔″紓甯�" // 澶囨敞 - ); - if (!basShuttleErrLogService.insert(basShuttleErrLog)) { - News.error("鍥涘悜绌挎杞lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName); - } - } - // 鏃犲紓甯� - } else { - // 寮傚父淇 - if (latest != null && latest.getStatus() == 1) { - latest.setEndTime(now); - latest.setUpdateTime(now); - latest.setStatus(2); - if (!basShuttleErrLogService.updateById(latest)) { - News.error("鍥涘悜绌挎杞lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId()); - } - } - } +// //鏃犱换鍔� +// BasShuttleErrLog latest = basShuttleErrLogService.findLatest(shuttleSlave.getId()); +// // 鏈夊紓甯� +// if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) { +// // 璁板綍鏂板紓甯� +// if (latest == null || (latest.getErrCode() != shuttleProtocol.getStatusErrorCode().intValue())) { +// BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue()); +// String errName = basShuttleErr==null? "鏈煡寮傚父":basShuttleErr.getErrName(); +// BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog( +// null, // 缂栧彿 +// null, // 宸ヤ綔鍙� +// now, // 鍙戠敓鏃堕棿 +// null, // 缁撴潫鏃堕棿 +// null, // 宸ヤ綔鐘舵�� +// null, // 鍏ュ嚭搴撶被鍨� +// shuttleSlave.getId(), // 鍥涘悜绌挎杞� +// null, // plc +// null, // 鐩爣搴撲綅 +// null, // 鐩爣绔� +// null, // 婧愮珯 +// null, // 婧愬簱浣� +// null, // 鏉$爜 +// (int)shuttleProtocol.getStatusErrorCode(), // 寮傚父鐮� +// errName, // 寮傚父 +// 1, // 寮傚父鎯呭喌 +// now, // 娣诲姞鏃堕棿 +// null, // 娣诲姞浜哄憳 +// now, // 淇敼鏃堕棿 +// null, // 淇敼浜哄憳 +// "鏃犱换鍔″紓甯�" // 澶囨敞 +// ); +// if (!basShuttleErrLogService.insert(basShuttleErrLog)) { +// News.error("鍥涘悜绌挎杞lc寮傚父璁板綍澶辫触 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName); +// } +// } +// // 鏃犲紓甯� +// } else { +// // 寮傚父淇 +// if (latest != null && latest.getStatus() == 1) { +// latest.setEndTime(now); +// latest.setUpdateTime(now); +// latest.setStatus(2); +// if (!basShuttleErrLogService.updateById(latest)) { +// News.error("鍥涘悜绌挎杞lc寮傚父璁板綍淇澶辫触 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId()); +// } +// } +// } } } } -- Gitblit v1.9.1