From c12d108ee5d786d460718fd258a87bda64a6aa39 Mon Sep 17 00:00:00 2001 From: lty <876263681@qq.com> Date: 星期二, 25 三月 2025 14:36:09 +0800 Subject: [PATCH] #输送线循环优化 --- src/main/java/com/zy/core/thread/SiemensCrnThread.java | 7 --- src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java | 111 +++++++++++++++++++++++-------------------------------- 2 files changed, 48 insertions(+), 70 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 5680365..3303ad3 100644 --- a/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java +++ b/src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java @@ -113,91 +113,74 @@ private CrnController crnController; @Autowired private SiteController siteController; - //鍑哄簱绔欑偣鑷�112寰幆绔欑偣 @Synchronized - public void shiftTargetToCyclePoint() throws IOException, InterruptedException{ - try{ + public void shiftTargetToCyclePoint() throws IOException, InterruptedException { + try { for (DevpSlave devp : slaveProperties.getDevp()) { for (DevpSlave.Sta outSta : devp.getOutSta()) { DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId()); - StaProtocol staProtocol = devpThread.getStation().get(outSta.getStaNo()); - StaProtocol staProtocol1 = devpThread.getStation().get(1001); - StaProtocol staProtocol2 = devpThread.getStation().get(1002); - StaProtocol staProtocol3 = devpThread.getStation().get(1003); - StaProtocol staProtocol4 = devpThread.getStation().get(1004); - StaProtocol staProtocol6 = devpThread.getStation().get(111); + if (devpThread == null) { + continue; + } + + StaProtocol staProtocol = getClonedStation(devpThread, outSta.getStaNo()); if (staProtocol == null) { continue; - } else { - staProtocol = staProtocol.clone(); } - if (staProtocol1 == null) { - continue; - } else { - staProtocol1 = staProtocol1.clone(); - } - if (staProtocol2 == null) { - continue; - } else { - staProtocol2 = staProtocol2.clone(); - } - if (staProtocol3 == null) { - continue; - } else { - staProtocol3 = staProtocol3.clone(); - } - if (staProtocol4 == null) { - continue; - } else { - staProtocol4 = staProtocol4.clone(); - } - if (staProtocol6 == null) { - continue; - } else { - staProtocol6 = staProtocol6.clone(); - } - boolean result = false; - switch(outSta.getStaNo()){ - case 105: if (staProtocol1.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 105){ - result = true; - } - case 107: if (staProtocol2.isLoading()){ - result = true; - } - case 109: if (staProtocol3.isLoading()){ - result = true; - } - case 110: if ((staProtocol4.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 110) || ((staProtocol6.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 111))){ - result = true; - } - default: break; + // 鑾峰彇鍏朵粬鐩稿叧绔欑偣 + StaProtocol staProtocol1 = getClonedStation(devpThread, 1001); + StaProtocol staProtocol2 = getClonedStation(devpThread, 1002); + StaProtocol staProtocol3 = getClonedStation(devpThread, 1003); + StaProtocol staProtocol4 = getClonedStation(devpThread, 1004); + StaProtocol staProtocol6 = getClonedStation(devpThread, 111); + + boolean result = false; + switch (outSta.getStaNo()) { + case 105: + result = (staProtocol1 != null && staProtocol1.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 105); + break; + case 107: + result = (staProtocol2 != null && staProtocol2.isLoading()); + break; + case 109: + result = (staProtocol3 != null && staProtocol3.isLoading()); + break; + case 110: + result = ((staProtocol4 != null && staProtocol4.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 110) || + (staProtocol6 != null && staProtocol6.isLoading() && staProtocol.isLoading() && staProtocol.getStaNo() == 111)); + break; + default: + break; } - if(result){ - if(staProtocol.getSiteId() == 107 || staProtocol.getSiteId() == 109){ - StaProtocol staProtocol5 = devpThread.getStation().get(staProtocol.getSiteId() - 1); - if (staProtocol5== null) { - continue; - } else { - staProtocol5 = staProtocol5.clone(); - } - if((staProtocol5.isLoading() && staProtocol5.getStaNo() == 107) || ((staProtocol5.isLoading() && staProtocol5.getStaNo() == 109))){ + + if (result) { + if (staProtocol.getSiteId() == 107 || staProtocol.getSiteId() == 109) { + StaProtocol staProtocol5 = getClonedStation(devpThread, staProtocol.getSiteId() - 1); + if (staProtocol5 != null && (staProtocol5.isLoading() && (staProtocol5.getStaNo() == 107 || staProtocol5.getStaNo() == 109))) { staProtocol5.setStaNo((short) 112); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol5)); } - }else{ + } else { staProtocol.setStaNo((short) 112); MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol)); } } } } - }catch (Exception e) { - log.error("generateStoreWrkFile e", e); - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + } catch (Exception e) { + log.error("shiftTargetToCyclePoint error", e); } } + /** + * 鑾峰彇绔欑偣骞跺厠闅� + */ + private StaProtocol getClonedStation(DevpThread devpThread, int staNo) { + StaProtocol staProtocol = devpThread.getStation().get(staNo); + return (staProtocol != null) ? staProtocol.clone() : null; + } + //112寰幆绔欑偣鑷冲嚭搴撶珯 public synchronized void shiftCyclePointToTarget() throws IOException, InterruptedException{ try{ diff --git a/src/main/java/com/zy/core/thread/SiemensCrnThread.java b/src/main/java/com/zy/core/thread/SiemensCrnThread.java index cb14968..b66082c 100644 --- a/src/main/java/com/zy/core/thread/SiemensCrnThread.java +++ b/src/main/java/com/zy/core/thread/SiemensCrnThread.java @@ -396,11 +396,6 @@ OperateResult result = siemensNet.Write("DB100.0", array); int i=0; -// if(result.IsSuccess){ -// log.info("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鎴愬姛[id:{}]>>>>鍐欏叆[{}]", slave.getId(),JSON.toJSON(command)); -// }else{ -// log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆澶辫触锛侊紒锛乕id:{}]>>>>鍐欏叆[{}]", slave.getId(),JSON.toJSON(command)); -// } do{ //鍫嗗灈鏈轰换鍔″啓鍏ュ悗锛屽洖璇讳竴娆★紝鐪嬫槸鍚︽垚鍔� Thread.sleep(300); @@ -424,7 +419,7 @@ log.error("鍫嗗灈鏈哄懡浠ゅ湴鍧�鍐欏叆鍚庡洖璇诲け璐id:{}]>>>>閲嶅啓[{}] >>>>> 鍐欏叆[{}],===>>鍥炶[{}]", slave.getId(), i,JSON.toJSON(command),JSON.toJSON(one)); result = siemensNet.Write("DB100.0", array); }else{ - result = siemensNet.Write("DB100.18", (short) 1); + result = siemensNet.Write("DB100.18", (short) 0); i=5; } } -- Gitblit v1.9.1