From 87c4efe93e6fe31a9c989b4aa5cc0c8f559b845d Mon Sep 17 00:00:00 2001 From: Junjie <fallin.jie@qq.com> Date: 星期五, 31 三月 2023 16:50:47 +0800 Subject: [PATCH] 提升机代码,四向穿梭车线程优化 --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 154 insertions(+), 15 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 8bb3c30..0db902b 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -23,10 +23,7 @@ import com.zy.core.enums.*; import com.zy.core.model.*; import com.zy.core.model.command.*; -import com.zy.core.model.protocol.CrnProtocol; -import com.zy.core.model.protocol.ShuttleProtocol; -import com.zy.core.model.protocol.StaProtocol; -import com.zy.core.model.protocol.SteProtocol; +import com.zy.core.model.protocol.*; import com.zy.core.properties.SlaveProperties; import com.zy.core.thread.*; import lombok.extern.slf4j.Slf4j; @@ -673,9 +670,8 @@ //鍏ュ嚭搴撴ā寮� assignCommand.setTaskMode(ShuttleTaskModeType.PAK_IN.id.shortValue()); //婧愬簱浣�(灏忚溅褰撳墠浣嶇疆) - Short currentCode = shuttleProtocol.getCurrentCode(); - LocMast currentLocMast = locMastService.queryByQrCode(currentCode.toString()); - assignCommand.setSourceLocNo(currentLocMast.getLocNo()); + String currentLocNo = shuttleProtocol.getCurrentLocNo(); + assignCommand.setSourceLocNo(currentLocNo); if (wrkMast.getWrkSts() == 8 || Boolean.parseBoolean(searchIdleShuttle.get("sameLay").toString())) { //鍚屼竴灞� @@ -688,7 +684,6 @@ //涓嶅悓灞傦紝灏嗙洰鏍囧簱浣嶅垎閰嶆垚鎻愬崌鏈哄簱浣嶅彿 //灏忚溅褰撳墠灞傞珮 - String currentLocNo = currentLocMast.getLocNo(); Integer currentLev = Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length())); //鑾峰彇鎻愬崌鏈� @@ -736,9 +731,7 @@ continue; } - Short currentCode = shuttleProtocol.getCurrentCode();//鍥涘悜绌挎杞﹀綋鍓嶄綅缃簩缁寸爜 - LocMast shuttleLocMast = locMastService.queryByQrCode(currentCode.toString());//鎵惧埌浜岀淮鐮佸搴旂殑搴撲綅璁板綍 - String shuttleLocNo = shuttleLocMast.getLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿 + String shuttleLocNo = shuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿 String shuttleLocNoLay = shuttleLocNo.substring(shuttleLocNo.length() - 2, shuttleLocNo.length());//搴撲綅鍙峰搴斿眰楂� if (lay.equals(shuttleLocNoLay)) { //褰撳墠鍥涘悜绌挎杞﹀拰宸ヤ綔妗d换鍔″湪鍚屼竴灞傦紝鍒欒皟閰嶈杞﹁締 @@ -752,9 +745,7 @@ recentShuttle = shuttleThread; }else { ShuttleProtocol recentShuttleProtocol = recentShuttle.getShuttleProtocol();//鐩墠鏈�杩戠┛姊溅 - Short recentShuttleCurrentCode = recentShuttleProtocol.getCurrentCode();//鐩墠鏈�杩戠┛姊溅浣嶇疆浜岀淮鐮� - LocMast recentShuttleLocMast = locMastService.queryByQrCode(recentShuttleCurrentCode.toString());//鎵惧埌浜岀淮鐮佸搴旂殑搴撲綅璁板綍 - String recentShuttleLocNo = recentShuttleLocMast.getLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿 + String recentShuttleLocNo = recentShuttleProtocol.getCurrentLocNo();//浜岀淮鐮佸搴斿簱浣嶅彿 String recentShuttleLocNoLay = recentShuttleLocNo.substring(recentShuttleLocNo.length() - 2, recentShuttleLocNo.length());//搴撲綅鍙峰搴斿眰楂� int recentShuttleLocNoLayInt = Integer.parseInt(recentShuttleLocNoLay); @@ -838,7 +829,9 @@ shuttleProtocol.setLocNo(null); //鏍囪澶嶄綅 shuttleProtocol.setPakMk(true); - News.info("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚爢鍨涙満鍙�={}", shuttleProtocol.getShuttleNo()); + //浠诲姟鎸囦护娓呴浂 + shuttleProtocol.setAssignCommand(null); + News.info("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傚洓鍚戠┛姊溅鍙�={}", shuttleProtocol.getShuttleNo()); } else { News.error("鍥涘悜绌挎杞﹀凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傚洓鍚戠┛姊溅鍙�={}锛屽伐浣滃彿={}", shuttleProtocol.getShuttleNo(), shuttleProtocol.getTaskNo()); } @@ -849,6 +842,152 @@ } /** + * 鎻愬崌鏈轰换鍔� + */ + public synchronized void liftIoExecute() { + for (LiftSlave liftSlave : slaveProperties.getLift()) { + LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId()); + if (liftThread == null) { + continue; + } + LiftProtocol liftProtocol = liftThread.getLiftProtocol(); + if (liftProtocol == null) { + continue; + } + + //鍒ゆ柇鎻愬崌鏈烘槸鍚﹀浜庣┖闂茬姸鎬� + if (!liftProtocol.isIdle()) { + continue; + } + + //鎼滅储鏄惁鏈夊緟澶勭悊鐨勪换鍔� + WrkMast wrkMast = wrkMastMapper.selectLiftStep6(); + if (wrkMast == null) { + continue; + } + + //缁欐彁鍗囨満鍒嗛厤浠诲姟 + liftProtocol.setLiftLock(true);//閿佸畾鎻愬崌鏈� + liftProtocol.setTaskNo(wrkMast.getWrkNo().shortValue());//璁剧疆浠诲姟鍙� + liftProtocol.setShuttleNo(wrkMast.getShuttleNo().shortValue());//璁剧疆鍥涘悜绌挎杞﹀彿 + liftProtocol.setProtocolStatus(LiftProtocolStatusType.WORKING);//璁剧疆鎻愬崌鏈虹姸鎬佷负宸ヤ綔涓� + + //鎵惧埌鍥涘悜绌挎杞︾殑绾跨▼ + ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, liftProtocol.getShuttleNo().intValue()); + if (shuttleThread == null) { + continue; + } + ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol(); + if (shuttleProtocol == null) { + continue; + } + + //鍛戒护list + ArrayList<LiftCommand> commands = new ArrayList<>(); + + //褰撳墠绌挎杞﹀簱浣嶅彿 + String currentLocNo = shuttleProtocol.getCurrentLocNo(); + //褰撳墠绌挎杞︽ゼ灞� + int currentLocNoLey = Integer.parseInt(currentLocNo.substring(currentLocNo.length() - 2, currentLocNo.length())); + + //宸ヤ綔妗g洰鏍囧簱浣嶅彿 + String wrkMastLocNo = wrkMast.getLocNo(); + //宸ヤ綔妗g洰鏍囧簱浣嶆ゼ灞� + int wrkMastLocNoLey = Integer.parseInt(wrkMastLocNo.substring(wrkMastLocNo.length() - 2, wrkMastLocNo.length())); + + //鎻愬崌鏈哄綋鍓嶆ゼ灞� + int liftLev = liftProtocol.getLev().intValue(); + if (liftLev != currentLocNoLey) { + //涓嶅悓妤煎眰 + LiftCommand command1 = new LiftCommand(); + command1.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿 + command1.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙� + command1.setRun((short) 1);//鍗囬檷 + command1.setDistPosition((short) currentLocNoLey);//鐩爣妤煎眰(绌挎杞︽墍鍦ㄦゼ灞�) + command1.setLiftLock(true);//閿佸畾鎻愬崌鏈� + + commands.add(command1);//灏嗗懡浠ゆ坊鍔犺繘list + } + + //杈撻�佺嚎灏嗗洓鍚戠┛姊溅绉诲姩杩涙潵 + LiftCommand command2 = new LiftCommand(); + command2.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿 + command2.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙� + command2.setRun((short) 6);//杈撻�佺嚎杩愪綔 + command2.setLiftLock(true);//閿佸畾鎻愬崌鏈� + + commands.add(command2);//灏嗗懡浠ゆ坊鍔犺繘list + + //鎻愬崌鏈烘惉杩愬洓鍚戠┛姊溅 + LiftCommand command3 = new LiftCommand(); + command3.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿 + command3.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙� + command3.setRun((short) 1);//鍗囬檷 + command3.setDistPosition((short) wrkMastLocNoLey);//宸ヤ綔妗g洰鏍囨ゼ灞� + command3.setLiftLock(true);//閿佸畾鎻愬崌鏈� + + commands.add(command3);//灏嗗懡浠ゆ坊鍔犺繘list + + //鎻愬崌鏈哄埌杈炬寚瀹氭ゼ灞傦紝杈撻�佺嚎灏嗗洓鍚戠┛姊溅绉诲嚭鍘� + //杈撻�佺嚎灏嗗洓鍚戠┛姊溅绉诲姩杩涙潵 + LiftCommand command4 = new LiftCommand(); + command4.setLiftNo(liftProtocol.getLiftNo());//鎻愬崌鏈哄彿 + command4.setTaskNo(liftProtocol.getTaskNo());//浠诲姟鍙� + command4.setRun((short) 3);//杈撻�佺嚎杩愪綔 + command4.setLiftLock(true);//閿佸畾鎻愬崌鏈� + + commands.add(command4);//灏嗗懡浠ゆ坊鍔犺繘list + + wrkMast.setWrkSts(7L);//绉诲姩浠诲姟 + //鎵�闇�鍛戒护缁勫悎瀹屾瘯锛屾洿鏂版暟鎹簱锛屾彁浜ゅ埌绾跨▼鍘诲伐浣� + LiftAssignCommand assignCommand = new LiftAssignCommand(); + assignCommand.setCommands(commands); + assignCommand.setLiftNo(liftProtocol.getLiftNo()); + assignCommand.setTaskNo(liftProtocol.getTaskNo()); + if (wrkMastMapper.updateById(wrkMast) > 0) { + //涓嬪彂浠诲姟 + MessageQueue.offer(SlaveType.Lift, liftProtocol.getLiftNo().intValue(), new Task(3, assignCommand)); + } + } + } + + /** + * 鎻愬崌鏈轰换鍔″畬鎴� + */ + public synchronized void liftFinished() { + for (LiftSlave liftSlave : slaveProperties.getLift()) { + //鑾峰彇鎻愬崌鏈轰俊鎭� + LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftSlave.getId()); + LiftProtocol liftProtocol = liftThread.getLiftProtocol(); + if (liftProtocol == null) { + continue; + } + + //鎻愬崌鏈轰负绛夊緟纭 + if (liftProtocol.getProtocolStatus() == LiftProtocolStatusType.WAITING.id && liftProtocol.getTaskNo() != 0) { + //灏嗕换鍔℃。鏍囪涓哄畬鎴� + WrkMast wrkMast = wrkMastMapper.selectByWorkNo7(liftProtocol.getTaskNo().intValue()); + if (wrkMast != null) { + wrkMast.setWrkSts(8L); + if (wrkMastMapper.updateById(wrkMast) > 0) { + //璁剧疆鎻愬崌鏈轰负绌洪棽鐘舵�� + liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE); + //浠诲姟鍙锋竻闆� + liftProtocol.setTaskNo((short) 0); + //鏍囪澶嶄綅 + liftProtocol.setPakMk(true); + //浠诲姟鎸囦护娓呴浂 + liftProtocol.setAssignCommand(null); + News.info("鎻愬崌鏈哄凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅銆傛彁鍗囨満鍙�={}", liftProtocol.getLiftNo()); + } else { + News.error("鎻愬崌鏈哄凡纭涓斾换鍔″畬鎴愮姸鎬�,澶嶄綅澶辫触锛屼絾鏈壘鍒板伐浣滄。銆傛彁鍗囨満鍙�={}锛屽伐浣滃彿={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo()); + } + } + } + } + } + + /** * 鍏ュ嚭搴� ===>> 鍫嗗灈鏈哄叆鍑哄簱浣滀笟涓嬪彂 */ public synchronized void crnIoExecute(){ -- Gitblit v1.9.1