From 4e6aa344572b71520b2acb0b32de51506566eab7 Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期三, 02 八月 2023 08:56:31 +0800 Subject: [PATCH] 小车调度分离 --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 445 ++++++------------------------------------------------- 1 files changed, 49 insertions(+), 396 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 031a41d..75868e7 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -2,10 +2,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.mapper.EntityWrapper; -import com.baomidou.mybatisplus.mapper.Wrapper; import com.core.common.Cools; -import com.core.common.SpringUtils; import com.core.exception.CoolException; import com.zy.asrs.entity.*; import com.zy.asrs.mapper.*; @@ -13,11 +10,9 @@ import com.zy.asrs.utils.Utils; import com.zy.common.model.*; import com.zy.common.model.enums.NavigationMapType; -import com.zy.common.model.enums.WrkChargeType; import com.zy.common.service.CommonService; import com.zy.common.service.erp.ErpService; import com.zy.common.utils.*; -import com.zy.core.CrnThread; import com.zy.core.DevpThread; import com.zy.core.News; import com.zy.core.cache.MessageQueue; @@ -97,6 +92,8 @@ private OrderDetlMapper orderDetlMapper; @Autowired private BasLiftService basLiftService; + @Autowired + private ShuttleDispatchUtils shuttleDispatchUtils; @Autowired private RedisUtil redisUtil; @@ -708,7 +705,7 @@ public boolean shuttleInExecuteStep1(WrkMast wrkMast, BasDevp basDevp) { if (wrkMast.getWrkSts() == 4) { if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴� - dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐� + shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐� return false; } @@ -728,7 +725,7 @@ //鍒ゆ柇灏忚溅鏄惁鍒拌揪杈撻�佺珯鐐瑰簱浣� if (!shuttleProtocol.getCurrentLocNo().equals(basDevp.getLocNo())) { //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃� - dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐� + shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), basDevp.getLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐� return false; } @@ -975,7 +972,7 @@ //21.鐢熸垚鍑哄簱浠诲姟 => 22.灏忚溅鎼繍涓� if (wrkMast.getWrkSts() == 21) { if (wrkMast.getShuttleNo() == null) {//娌℃湁缁戝畾灏忚溅锛岃繘琛岃皟搴� - dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐� + shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄥ簱浣嶈繘琛屽彇璐� return false; } @@ -1001,7 +998,7 @@ //鍒ゆ柇灏忚溅鏄惁鍒拌揪璐х墿搴撲綅 if (!shuttleProtocol.getCurrentLocNo().equals(wrkMast.getSourceLocNo())) { //灏忚溅涓嶅湪杈撻�佺珯鐐逛綅缃� - dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐� + shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), wrkMast.getSourceLocNo(), wrkMast.getShuttleNo());//璋冨害灏忚溅鍒拌揣鐗╂墍鍦ㄨ緭閫佺珯鐐硅繘琛屽彇璐� return false; } @@ -1163,8 +1160,8 @@ public synchronized void shuttleFinished() { for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { //鑾峰彇鍥涘悜绌挎杞︿俊鎭� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } @@ -1172,7 +1169,7 @@ //鍥涘悜绌挎杞︾姸鎬佷负绛夊緟纭銆佸皬杞﹀浜庣┖闂茬姸鎬� if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.WAITING.id //浠诲姟瀹屾垚绛夊緟纭 && shuttleProtocol.getTaskNo() != 0 - && shuttleProtocol.getBusyStatus() == 0 + && shuttleProtocol.getFree() == ShuttleStatusType.IDLE.id ) { //灏嗕换鍔℃。鏍囪涓哄畬鎴� WrkMast wrkMast = wrkMastMapper.selectByWorkNo(shuttleProtocol.getTaskNo().intValue()); @@ -1181,7 +1178,7 @@ case 5://5.灏忚溅鎼繍涓� ==> 9.鍏ュ簱瀹屾垚 wrkMast.setWrkSts(9L); //浠诲姟鍙锋竻闆� - shuttleProtocol.setTaskNo((short) 0); + shuttleProtocol.setTaskNo(0); break; case 22://22.灏忚溅鎼繍涓� ==> 23.灏忚溅鎼繍瀹屾垚 wrkMast.setWrkSts(23L); @@ -2052,8 +2049,8 @@ public synchronized void loopShuttleCharge() { for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { //鑾峰彇鍥涘悜绌挎杞︾嚎绋� - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } @@ -2110,412 +2107,68 @@ continue; } - ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkCharge.getShuttleNo()); + NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkCharge.getShuttleNo()); if (shuttleThread == null) { continue; } - ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); if (shuttleProtocol == null) { continue; } - //鑾峰彇鎻愬崌鏈� - LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, 1); - if (liftThread == null) { - continue; - } - LiftProtocol liftProtocol = liftThread.getLiftProtocol(); - if (liftProtocol == null) { - continue; - } - //鍏呯數搴撲綅鍙� - String chargeLocNo = wrkCharge.getLocNo(); - //鍏呯數搴撲綅灞傞珮 - Integer chargeLocNoLev = Utils.getLev(chargeLocNo); - if (wrkCharge.getWrkSts() == 51) { - //褰撳墠绌挎杞﹀簱浣嶅彿 - String currentLocNo = shuttleProtocol.getCurrentLocNo(); - if (currentLocNo == null) { - continue; - } - //灏忚溅褰撳墠灞傞珮 - Integer currentLev = Utils.getLev(currentLocNo); - - if (currentLev == chargeLocNoLev) { - //鍚屼竴灞傛棤闇�缁忚繃鎻愬崌鏈� - //鐩存帴璁$畻杞﹀埌鍏呯數搴撲綅 - - ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); - - //鑾峰彇灏忚溅鍒板厖鐢靛簱浣嶈矾寰勬寚浠� - List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, chargeLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); - if (commands == null) { - continue;//鏈壘鍒拌矾寰� - } - //杩涜鍏呯數涓� - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); - - assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); - assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//鍏呯數 - assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); - assignCommand.setCharge(true);//鍏呯數浠诲姟 - - //鍒涘缓鍏呯數鎸囦护 - ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 1);//寮�濮嬪厖鐢� - commands.add(command); - - //鎸囦护闆嗗垎閰� -// assignCommand.setCommands(commands); - - wrkCharge.setWrkSts(56L);//鍏呯數涓姸鎬� - if (wrkChargeMapper.updateById(wrkCharge) > 0) { - //涓嬪彂浠诲姟 - MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); - } - }else { - //涓嶅悓灞傦紝璋冨害灏忚溅鍒板厖鐢垫々鐩爣灞� - - ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); - - //鑾峰彇灏忚溅褰撳墠妤煎眰鐨勭珯鐐瑰彿 - String liftSiteLocNo = Utils.levToOutInStaLocNo(currentLev); - - //灏忚溅绉诲姩鍒版彁鍗囨満鍙g珯鐐癸紝璁$畻璺緞 - List<ShuttleCommand> commands = this.shuttleAssignCommand(currentLocNo, liftSiteLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); - if (commands == null) { - continue;//鏈壘鍒拌矾寰� - } - - //鑾峰彇褰撳墠灏忚溅鎵�鍦ㄦゼ灞傜殑绔欑偣淇℃伅 - BasDevp basDevp = basDevpService.queryByLocNo(liftSiteLocNo); - if (basDevp == null) { - continue;//鎵句笉鍒扮珯鐐逛俊鎭� - } - Short basDevpQrCode = Short.parseShort(basDevp.getQrCodeValue());//绔欑偣浜岀淮鐮� - -// //澧炲姞绉诲姩杩涙彁鍗囨満鍛戒护 -// ShuttleCommand moveCommand = shuttleThread.getMoveCommand(basDevpQrCode, liftProtocol.getBarcode(), 1600, ShuttleRunDirection.TOP.id, basDevpQrCode, 1600, 500); -// commands.add(moveCommand); - - //鍒嗛厤鐩爣搴撲綅 - shuttleProtocol.setLocNo(chargeLocNo); - assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); - assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//鍏呯數 - assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); - assignCommand.setCharge(true);//鍏呯數浠诲姟 - //鐩爣搴撲綅 - assignCommand.setLocNo(chargeLocNo); - //婧愬簱浣� - assignCommand.setSourceLocNo(currentLocNo); -// assignCommand.setCommands(commands); - wrkCharge.setWrkSts(52L);//灏忚溅杩佺Щ鐘舵�� - if (wrkChargeMapper.updateById(wrkCharge) > 0) { - //涓嬪彂浠诲姟 - MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); - } - } - - }else if(wrkCharge.getWrkSts() == 53){ - //灏忚溅宸茬粡杈惧埌鎻愬崌鏈哄唴 - - //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀浜庣┖闂茬姸鎬� - if (!liftProtocol.isIdle(wrkCharge.getWrkNo().shortValue())) { + if (!shuttleProtocol.getCurrentLocNo().equals(wrkCharge.getLocNo())) { + //灏忚溅涓嶅湪鍏呯數妗╀綅缃� + shuttleDispatchUtils.dispatchShuttle(wrkCharge.getWrkNo(), wrkCharge.getLocNo(), shuttle.getId());//璋冨害灏忚溅鍘诲厖鐢垫々 continue; } -// //鍒ゆ柇灏忚溅鏄惁鍦ㄦ彁鍗囨満鍐� -// if (shuttleProtocol.getCurrentCode().intValue() != liftProtocol.getBarcode().intValue()) { -// //灏忚溅涓嶅湪鎻愬崌鏈哄唴 -// continue; -// } - - //缁欐彁鍗囨満鍒嗛厤浠诲姟 - liftProtocol.setTaskNo(wrkCharge.getWrkNo().shortValue());//璁剧疆浠诲姟鍙� - liftProtocol.setShuttleNo(wrkCharge.getShuttleNo().shortValue());//璁剧疆鍥涘悜绌挎杞﹀彿 - liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓� - - //鍛戒护list - ArrayList<LiftCommand> commands = new ArrayList<>(); - -// //鎻愬崌鏈哄墠寰�鐩爣妤煎眰 -// //鑾峰彇鍏呯數搴撲綅鐩爣妤煎眰鍛戒护 -// LiftCommand command1 = liftThread.getLiftUpDownCommand(liftProtocol.getLiftNo(), liftProtocol.getTaskNo(), chargeLocNoLev >= 2 ? chargeLocNoLev + 1 : chargeLocNoLev); -// commands.add(command1);//灏嗗懡浠ゆ坊鍔犺繘list - - wrkCharge.setWrkSts(54L);//鎻愬崌鏈烘惉杩愪腑 - //鎵�闇�鍛戒护缁勫悎瀹屾瘯锛屾洿鏂版暟鎹簱锛屾彁浜ゅ埌绾跨▼鍘诲伐浣� - LiftAssignCommand assignCommand = new LiftAssignCommand(); -// assignCommand.setCommands(commands); - assignCommand.setLiftNo(liftProtocol.getLiftNo()); - assignCommand.setTaskNo(liftProtocol.getTaskNo()); - if (wrkChargeMapper.updateById(wrkCharge) > 0) { - //涓嬪彂浠诲姟 - MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); - } - - }else if(wrkCharge.getWrkSts() == 55){//55.鎻愬崌鏈鸿縼绉诲皬杞﹀畬鎴� - //鐩存帴璁$畻杞﹀埌鍏呯數搴撲綅 - + //灏忚溅宸茬粡鍦ㄥ厖鐢垫々浣嶇疆锛屼笅鍙戝厖鐢靛懡浠� + NyShuttleHttpCommand chargeCommand = NyHttpUtils.getChargeCommand(shuttle.getId(), wrkCharge.getWrkNo(), true); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(chargeCommand); + //鍒涘缓鍒嗛厤鍛戒护 ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); + assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿 + assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue());//浠诲姟鍙� + assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//鍑哄簱妯″紡 + assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆) + assignCommand.setCommands(commands);//杩愯鍛戒护 - Short liftLev = liftProtocol.getLev(); - if (liftLev == null) { - continue; - } - //鍒ゆ柇鎻愬崌鏈烘ゼ灞傛槸鍚﹀埌杈剧洰鏍囨ゼ灞� - if (liftLev.intValue() != chargeLocNoLev) { - continue;//娌℃湁鍒拌揪鐩爣妤煎眰 - } - - //姝ゆ椂杞﹀湪鎻愬崌鏈哄唴閮紝涓嬭揪涓�姝ユ寚浠よ杞︾Щ鍔ㄥ埌鎻愬崌鏈哄彛 - Integer staNo = Utils.levToOutInStaNo(liftLev >= 2 ? liftLev + 1 : liftLev);//绔欑偣鍙� - BasDevp basDevp = basDevpService.selectById(staNo); - if (basDevp == null) { - continue;//绔欑偣涓嶅瓨鍦� - } - - //鑾峰彇鎻愬崌鏈哄彛鍒板厖鐢靛簱浣嶈矾寰勬寚浠� - List<ShuttleCommand> commands = this.shuttleAssignCommand(basDevp.getLocNo(), chargeLocNo, NavigationMapType.NONE.id, assignCommand, shuttleThread); - if (commands == null) { - continue;//鏈壘鍒拌矾寰� - } - -// short startCode = liftProtocol.getBarcode();//鎻愬崌鏈哄唴閮ㄤ簩缁寸爜 -// Short distCode = Short.parseShort(basDevp.getQrCodeValue());//鎻愬崌鏈哄彛绔欑偣浜岀淮鐮� -// Short runDirection = ShuttleRunDirection.BOTTOM.id;//杩愯鏂瑰悜 -// //鑾峰彇鍛戒护 -// ShuttleCommand moveCommand = shuttleThread.getMoveCommand(startCode, distCode, 1600, runDirection, startCode, 1600, 500); -// commands.add(0, moveCommand);//灏嗚鎸囦护娣诲姞鍒伴槦澶� - - //杩涜鍏呯數涓� - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); - - assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); - assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//鍏呯數 - assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); - assignCommand.setCharge(true);//鍏呯數浠诲姟 - - //鍒涘缓鍏呯數鎸囦护 - ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 1);//寮�濮嬪厖鐢� - commands.add(command); - - //鎸囦护闆嗗垎閰� -// assignCommand.setCommands(commands); - - wrkCharge.setWrkSts(56L);//鍏呯數涓姸鎬� + wrkCharge.setWrkSts(52L);//51.鐢熸垚鍏呯數浠诲姟 => 52.灏忚溅鍘诲厖鐢典腑 + wrkCharge.setModiTime(new Date()); if (wrkChargeMapper.updateById(wrkCharge) > 0) { //涓嬪彂浠诲姟 MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } - }else if (wrkCharge.getWrkSts() == 57) {//57.灏忚溅鍒拌揪鍏呯數妗� - //鍏呯數涓� - //鍒ゆ柇灏忚溅鏄惁鍏呮弧鐢甸噺锛屾弧鐢�1000鎴栫數鍘�54V浠ヤ笂 - if (shuttleProtocol.getBatteryPower() == null || shuttleProtocol.getCurrentVoltage() == null) { - continue; - } - if (shuttleProtocol.getBatteryPower() >= 1000 && shuttleProtocol.getCurrentVoltage() >= 54000) { - //鍏呮弧锛屾柇寮�鍏呯數 -// List<ShuttleCommand> commands = new ArrayList<>(); -// ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); -// assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo()); -// assignCommand.setTaskMode((short) 0); -// assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue()); -// assignCommand.setCharge(true); -// -// //鍒涘缓鍏呯數鎸囦护 -// ShuttleCommand command = shuttleThread.getChargeSwitchCommand((short) 2);//鏂紑鍏呯數 -// commands.add(command); -// -// //鎸囦护闆嗗垎閰� -// assignCommand.setCommands(commands); -// -// shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING_WAITING); - - //灏嗗皬杞︾Щ鍔ㄥ埌绌洪棽鐨勫贩閬� - ShuttleAssignCommand assignCommand = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(shuttleProtocol.getLocNo()), shuttleProtocol.getShuttleNo().intValue(), shuttleThread, null); - if (assignCommand == null) { - continue; - } - - wrkCharge.setWrkSts(60L);//60.鍏呯數浠诲姟瀹屾垚 - if (wrkChargeMapper.updateById(wrkCharge) > 0) { - //涓嬪彂浠诲姟 - MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); - } - } - - if (shuttleProtocol.getProtocolStatus() == ShuttleProtocolStatusType.CHARGING_WAITING.id) { - shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.CHARGING); - } - } - } - - } - - /** - * 璋冨害杞﹁締 - */ - public void dispatchShuttle(Integer wrkNo, String locNo) { - ArrayList<NyShuttleThread> sameLev = new ArrayList<>();//鐩稿悓妤煎眰鐨勭┛姊溅 - ArrayList<NyShuttleThread> diffLev = new ArrayList<>();//涓嶅悓妤煎眰鐨勭┛姊溅 - - for (ShuttleSlave shuttle : slaveProperties.getShuttle()) { - //鑾峰彇鍥涘悜绌挎杞︾嚎绋� - NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId()); - NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); - if (shuttleProtocol == null || shuttleProtocol.getShuttleNo() == null) { - continue; - } - - if (!shuttleProtocol.isIdle()) { - continue; - } - - int currentLev = shuttleProtocol.getPoint().getZ();//灏忚溅褰撳墠灞傞珮 - String currentLocNo = shuttleProtocol.getCurrentLocNo();//灏忚溅褰撳墠搴撲綅鍙� - - if (currentLocNo.equals(locNo)) { - //杞﹁締褰撳墠浣嶇疆宸茬粡鏄洰鏍囧簱浣嶏紝璋冨害璇ヨ溅 - shuttleMoveGenerate(wrkNo, locNo, shuttleProtocol.getShuttleNo().intValue()); - break; - } - - if (currentLev == Utils.getLev(locNo)) { - //宸ヤ綔妗fゼ灞傜浉鍚岀殑绌挎杞� - sameLev.add(shuttleThread); - }else { - //宸ヤ綔妗d笉鍚屾ゼ灞傜殑绌挎杞� - diffLev.add(shuttleThread); - } - - } - - Integer recentAllDistance = 9999999; - NyShuttleThread recentShuttle = null;//褰撳墠璺濈鏈�杩戠殑鍥涘悜绌挎杞︾嚎绋� - if (sameLev.size() > 0) { - //鍚屼竴妤煎眰鏈夌┖闂茬┛姊溅锛屽垯鍙湪宸ヤ綔妗fゼ灞傚鎵� - //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞� - for (NyShuttleThread shuttleThread : sameLev) { - //褰撳墠绌挎杞﹀簱浣嶅彿 - String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); - //褰撳墠绌挎杞︾嚎绋嬪埌鐩爣鍦扮偣璺濈 - List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, locNo, 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; - } - } - }else { - //鍚屼竴妤煎眰锛屾病鏈夌┖闂茬┛姊溅锛屽彧鑳戒粠鍏朵粬妤煎眰璋冨害 - //瀵绘壘绂讳换鍔℃渶杩戠殑绌挎杞� - for (NyShuttleThread shuttleThread : diffLev) { - - //褰撳墠绌挎杞﹀簱浣嶅彿 - String currentLocNo = shuttleThread.getShuttleProtocol().getCurrentLocNo(); - int currentLev = Utils.getLev(currentLocNo); - List<WrkMast> wrkMasts1 = wrkMastService.selectNoShuttleWrkByLev(currentLev);//鍒ゆ柇褰撳墠绌挎杞︽ゼ灞傛槸鍚︽湁寰呭垎閰嶈溅杈嗙殑浠诲姟锛屽鏋滄湁鍒欎笉鍒嗛厤杩欒締杞� - if (wrkMasts1.size() > 0) { - //瀛樺湪鍏朵粬浠诲姟锛岃烦杩囪繖杈嗚溅 + } else if (wrkCharge.getWrkSts() == 52) { + //妫�娴嬪皬杞︽槸鍚︽弧鐢� + if (shuttleProtocol.getPowerPercent() < 100) { continue; } - //褰撳墠绌挎杞︾嚎绋嬪埌褰撳墠杞﹀瓙鎵�鍦ㄦゼ灞傜殑鎻愬崌鏈哄彛璺濈 - List<NavigateNode> currentShuttlePath = NavigateUtils.calc(currentLocNo, Utils.levToOutInStaLocNo(currentLev), NavigationMapType.NORMAL.id, Utils.getShuttlePoints(shuttleThread.getSlave().getId(), currentLev));//鎼滅储绌洪棽绌挎杞︼紝浣跨敤姝e父閫氶亾鍦板浘 - if (currentShuttlePath == null) { - continue; - } + //灏忚溅婊$數锛岀粨鏉熷厖鐢典换鍔� + NyShuttleHttpCommand chargeCommand = NyHttpUtils.getChargeCommand(shuttle.getId(), wrkCharge.getWrkNo(), false); + ArrayList<NyShuttleHttpCommand> commands = new ArrayList<>(); + commands.add(chargeCommand); + //鍒涘缓鍒嗛厤鍛戒护 + ShuttleAssignCommand assignCommand = new ShuttleAssignCommand(); + assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//鍥涘悜绌挎杞﹀彿 + assignCommand.setTaskNo(wrkCharge.getWrkNo().shortValue());//浠诲姟鍙� + assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id.shortValue());//鍑哄簱妯″紡 + assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//婧愬簱浣�(灏忚溅褰撳墠浣嶇疆) + assignCommand.setCommands(commands);//杩愯鍛戒护 - Integer currentAllDistance = NavigateUtils.getOriginPathAllDistance(currentShuttlePath);//璁$畻褰撳墠璺緞琛岃蛋鎬昏窛绂� - if (currentAllDistance < recentAllDistance) { - //濡傛灉褰撳墠妤煎眰鐨勮溅璺緞鏇村皬锛屽垯鏇存柊鏈�杩戠┛姊溅 - recentShuttle = shuttleThread; + wrkCharge.setWrkSts(60L);//52.灏忚溅鍘诲厖鐢典腑 => 60.鍏呯數浠诲姟瀹屾垚 + wrkCharge.setModiTime(new Date()); + if (wrkChargeMapper.updateById(wrkCharge) > 0) { + //涓嬪彂浠诲姟 + MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand)); } } + } - if (recentShuttle == null) {//娌℃湁鎼滅储鍒板彲鐢ㄧ┛姊溅 - return; - } - - //鎼滅储鍒板彲鐢ㄧ┛姊溅锛岃皟搴﹁杞� - shuttleMoveGenerate(wrkNo, locNo, recentShuttle.getSlave().getId()); - } - - /** - * 灏忚溅杩佺Щ浠诲姟鐢熸垚 - */ - @Transactional - public boolean shuttleMoveGenerate(Integer wrkNo, String locNo, Integer shuttleNo) { - Date now = new Date(); - //鑾峰彇鍥涘悜绌挎杞︾嚎绋� - NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleNo); - if (shuttleThread == null) { - return false; - } - NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); - if (shuttleProtocol == null) { - return false; - } - - //灏忚溅澶勪簬绌洪棽鐘舵�� - if (!shuttleProtocol.isIdleNoCharge()) { - return false; - } - - //鍒ゆ柇绌挎杞︽槸鍚﹀瓨鍦ㄦ湭瀹屾垚鐨勫皬杞︾Щ搴撲换鍔� - WrkMast hasMoveWorking = wrkMastMapper.selectShuttleHasMoveWorking(shuttleNo); - if (hasMoveWorking != null) {//灏忚溅瀛樺湪绉诲簱浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔� - return false; - } - - //鍒ゆ柇鏄惁鏈夊叾浠栦换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅 - WrkMast wrkMast2 = wrkMastMapper.selectShuttleWorking(shuttleNo); - if (wrkMast2 != null) {//灏忚溅瀛樺湪鍏朵粬宸ヤ綔妗d换鍔★紝绛夊緟鎵ц瀹屾垚鍚庡啀鐢熸垚鏂扮殑浠诲姟 - return false; - } - - //鍒ゆ柇鏄惁鏈夊厖鐢典换鍔℃鍦ㄤ娇鐢ㄧ┛姊溅 - WrkCharge wrkCharge = wrkChargeMapper.selectWorking(shuttleNo); - if (wrkCharge != null) {//灏忚溅瀛樺湪鍏呯數浠诲姟锛岀瓑寰呮墽琛屽畬鎴愬悗鍐嶇敓鎴愭柊鐨勪换鍔� - return false; - } - - // 鑾峰彇宸ヤ綔鍙� - int workNo = commonService.getWorkNo(0); - // 淇濆瓨宸ヤ綔妗� - WrkMast wrkMast = new WrkMast(); - wrkMast.setWrkNo(workNo); - wrkMast.setIoTime(now); - wrkMast.setWrkSts(101L); // 宸ヤ綔鐘舵�侊細101.绉诲姩鍒拌繎鐐圭瓑寰呰縼鍑� - wrkMast.setIoType(200); // 鍏ュ嚭搴撶姸鎬侊細 200.灏忚溅绉诲簱 - wrkMast.setIoPri(20D); - wrkMast.setShuttleNo(shuttleNo);//绌挎杞﹀彿 - wrkMast.setSourceLocNo(shuttleProtocol.getCurrentLocNo()); // 婧愬簱浣� => 灏忚溅褰撳墠搴撲綅鍙� - wrkMast.setLocNo(locNo); // 鐩爣搴撲綅 - wrkMast.setPicking("N"); // 鎷f枡 - wrkMast.setExitMk("N"); // 閫�鍑� - wrkMast.setLinkMis("N"); - wrkMast.setAppeTime(now); - wrkMast.setModiTime(now); - int res = wrkMastMapper.insert(wrkMast); - if (res == 0) { - News.error("灏忚溅杩佺Щ --- 淇濆瓨宸ヤ綔妗eけ璐ワ紒 绌挎杞﹀彿锛�" + shuttleNo); - throw new CoolException("淇濆瓨宸ヤ綔妗eけ璐�"); - } - - //缁欏伐浣滄。缁戝畾灏忚溅鍙� - WrkMast wrkMast1 = wrkMastMapper.selectByWorkNo(wrkNo); - if (wrkMast1 != null) { - wrkMast1.setShuttleNo(shuttleNo); - wrkMastMapper.updateById(wrkMast1); - } - - return true; } /** -- Gitblit v1.9.1