From 0cbe3bf67b051b6e66861ea97da2aea08e1fb2ad Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 05 十二月 2024 17:40:37 +0800 Subject: [PATCH] 实现RTU阀开状态不长级功能设置与实现 --- pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java | 122 ++++++++++++++++++++++++++++++++++------ 1 files changed, 102 insertions(+), 20 deletions(-) diff --git a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java index 68d6305..c5d795e 100644 --- a/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java +++ b/pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java @@ -1,18 +1,21 @@ package com.dy.rtuMw.server.upgrade; import com.alibaba.fastjson2.annotation.JSONField; +import com.dy.common.mw.protocol.rtuState.RtuStatus; import com.dy.common.softUpgrade.parse.HexFileParse; import com.dy.common.softUpgrade.state.UpgradeRtu; import com.dy.common.softUpgrade.state.UpgradeState; import com.dy.common.softUpgrade.state.UpgradeTaskVo; import com.dy.common.util.Callback; import com.dy.common.util.DateTime; +import com.dy.rtuMw.server.forTcp.RtuStatusDealer; import lombok.Data; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; /** * @Author: liurunyu @@ -31,6 +34,8 @@ protected Integer failTryTimes ;//鍗囩骇澶辫触鍚庯紝閲嶆柊鍋胯瘯鍗囩骇娆℃暟锛�0琛ㄧず涓嶉噸鏂板伩璇曞崌绾� @JSONField(serialize = false) protected Integer ugMaxRtuSameTime ;//鍚屾椂鍗囩骇RTU鏈�澶т釜鏁� + @JSONField(serialize = false) + private Integer lastOpenMaxGoOn ;//闃�寮�锛堟车寮�锛夌姸鎬佽缃互鏉ユ寔缁渶闀挎椂闂达紙绉掗挓锛夛紝瓒呰繃杩欎釜鏃堕棿璁や负鐘舵�佹棤鏁堬紙杩欎釜鏃堕暱鍙栧喅浜庡伐浣滄姤闂撮殧锛� public String setupDt ;//璁剧疆鏃堕棿(yyyy-mm-dd HH:MM:SS) @JSONField(serialize = false) @@ -51,7 +56,7 @@ /////////////////////////////////////////////////// //浠ヤ笅鍐呴儴鎺у埗鐢� @JSONField(serialize = false) - private int curUgRunningRtuTotal = 0 ;//褰撳墠姝e湪鍗囩骇鐨凴TU涓暟 + protected int curUgRunningRtuTotal = 0 ;//褰撳墠姝e湪鍗囩骇鐨凴TU涓暟 public UpgradeTask() { this.curUgRunningRtuTotal = 0 ; @@ -59,7 +64,8 @@ /** * 鍒濆鍖栭厤缃俊鎭� */ - public void initOption(Integer failTryTimes, Integer ugMaxRtuSameTime) { + public void initOption(Integer lastOpenMaxGoOn, Integer failTryTimes, Integer ugMaxRtuSameTime) { + this.lastOpenMaxGoOn = lastOpenMaxGoOn; this.failTryTimes = failTryTimes; this.ugMaxRtuSameTime = ugMaxRtuSameTime; } @@ -136,8 +142,7 @@ //rtu涓嶅湪鍗囩骇涔嬪垪 return ; } - } - if(ugRtu != null){ + }else{ if(ugRtu.isOver){ //褰撳墠RTU宸茬粡鍗囩骇瀹屾垚锛屾棤闇�鍐嶅崌绾� return; @@ -173,13 +178,9 @@ ugRtu.trigger(code, protocolName, protocolVersion, this.softFileDataGrp, callbackCom) ; } } - }else{ - //rtu涓嶅湪鍗囩骇涔嬪垪 - return ; } } } - /** * 寮哄埗缁撴潫鍗囩骇浠诲姟 */ @@ -193,6 +194,7 @@ } } + /** * 褰撳墠鍗囩骇鐘舵�� * @return @@ -202,10 +204,10 @@ if(this.taskVo.rtuAddrList != null && this.taskVo.rtuAddrList.size() > 0){ state.rtuTotal = this.taskVo.rtuAddrList.size() ; if(this.upgradeRtus != null && this.upgradeRtus.size() > 0){ - Collection<UpgradeRtu> col = this.upgradeRtus.values() ; - for(UpgradeRtu info : col){ + AtomicBoolean hasRunning = new AtomicBoolean(false); + this.upgradeRtus.values().forEach(info ->{ if(info.state == UpgradeRtu.STATE_OFFLINE){ - state.offLineTotal ++ ; + state.offLineTotal++ ; }else if(info.state == UpgradeRtu.STATE_UNSTART){ state.unStartTotal ++ ; }else if(info.state == UpgradeRtu.STATE_RUNNING){ @@ -213,14 +215,32 @@ }else if(info.state == UpgradeRtu.STATE_SUCCESS) { state.successTotal++; }else if(info.state == UpgradeRtu.STATE_FAILONE) { - state.failOneTotal++; - state.failTotal++; + state.dieOneTotal++; + if(info.isOver){ + state.failTotal++; + } }else if(info.state == UpgradeRtu.STATE_FAIL) { + state.dieMultiTotal++; + if(info.isOver) { + state.failTotal++; + } + }else if(info.state == UpgradeRtu.STATE_FAILOFFLINE) { state.failTotal++; + state.failOffTotal++; + }else if(info.state == UpgradeRtu.STATE_FAILOPEN) { + state.failTotal++; + state.failOpenTotal++; } if(info.isOver){ state.overTotal++; + }else{ + hasRunning.set(true); } + }); + if(!hasRunning.get()){ + state.allOver = true ; + }else{ + state.allOver = false ; } } } @@ -264,14 +284,39 @@ } /////////////////////////////////////////////////////////// - //浠ヤ笅鏂规硶涓哄唴閮ㄦ湇鍔★紝涓嶅澶栨彁渚涙湇鍔� + // + // 浠ヤ笅鏂规硶涓哄唴閮ㄦ湇鍔★紝涓嶅澶栨彁渚涙湇鍔� + // /////////////////////////////////////////////////////////// + /** + * 闃�寮�锛堟车寮�锛変笉鍗囩骇澶勭悊 + */ + protected void openNoUpgrade(){ + if(this.upgradeRtus != null && this.upgradeRtus.size() > 0){ + Map<String, RtuStatus> rsAllMap = RtuStatusDealer.allStatus() ; + Long now = System.currentTimeMillis() ; + this.upgradeRtus.values().stream().forEach(a -> { + RtuStatus rs = rsAllMap.get(a.rtuAddr) ; + if(rs != null + && rs.valveOpenTrueCloseFalse != null && rs.valveOpenTrueCloseFalse.booleanValue() == true + && rs.valveStatusLastTimeStamp != null){ + //鏈夌姸鎬侊紝骞朵笖鏄榾寮�锛堟车寮�锛� + Long gap = now - rs.valveStatusLastTimeStamp ; + if(gap < this.lastOpenMaxGoOn){ + //杩欐椂閲囩撼闃�闂ㄦ墦寮�鐘舵�佷笉鑳藉崌绾� + a.isOver = true ; + a.state = UpgradeRtu.STATE_FAILOPEN ; + } + } + }); + } + } /** * 鍒ゆ柇鏄惁娌$敤浠讳綍涓�涓猂TU杩涜杩囧崌绾э紝鑰屼笖瓒呰繃浜嗘椂闄� * @return -1:鏃犱竴RTU鍗囩骇涓旇秴鏃讹紝0锛氭棤RTU鍗囩骇浣嗘湭瓒呮椂绛夊緟锛�1鏈塕TU鍗囩骇姝e父鎵ц */ - protected int countNoOneRtuUpgrade(){ + protected int countNoOneRtuUpgradeInDuration(){ if(this.upgradeRtus == null || upgradeRtus.size() == 0){ //褰撳墠娌℃湁浠讳綍涓�涓澶囪繘琛岃繃鍗囩骇 Long now = System.currentTimeMillis() ; @@ -297,7 +342,7 @@ /** * 缁熻褰撳墠姝e湪鍗囩骇鐨凴TU鏁伴噺锛屼负鍚屾椂鍗囩骇鏁伴噺闄愬埗鍋氬噯澶� */ - protected void statisticsRunningRtuCount(){ + protected int countRunningRtuCount(){ int runningTotal = 0 ; Collection<UpgradeRtu> col = this.upgradeRtus.values() ; for(UpgradeRtu info : col){ @@ -305,32 +350,69 @@ runningTotal ++ ; } } - this.curUgRunningRtuTotal = runningTotal ; + return this.curUgRunningRtuTotal = runningTotal ; } /** - * 缁熻闇�瑕佸崌绾т絾褰撳墠绂荤嚎RTU鐨勬儏鍐� + * 缁熻闇�瑕佸崌绾т絾褰撳墠绂荤嚎RTU鐨勬儏鍐碉紝瓒呰繃鏃堕檺鐨勮澶囦负鍗囩骇瀹屾垚 + * @return -1:娌℃湁瓒呮椂锛�0瓒呮椂浜嗕笖鏃犲洜绂荤嚎琚己鍒惰缃崌绾у畬鎴愮殑RTU锛�>0绂荤嚎琚己鍒惰缃崌绾у畬鎴愮殑RTU鏁伴噺 */ - protected void statisticsOffRtuCountAndSet() { + protected int countOffRtuAndSetIfOver() { Long now = System.currentTimeMillis() ; if(now - this.setupDtLong > UpgradeUnit.confVo.rtuOffLineWaitDuration){ //rtu绂荤嚎锛岀瓑寰呭叾鍗囩骇鐨勬椂闀�(姣)锛岃秴杩囬厤缃殑鏈�澶ф椂闀匡紝璁剧疆鍏跺崌绾уけ璐ワ紝涓旇缃崌绾т换鍔″畬鎴� + int count = 0 ; if (this.taskVo.rtuAddrList != null && this.taskVo.rtuAddrList.size() > 0) { Collection<UpgradeRtu> col = this.upgradeRtus.values() ; for(UpgradeRtu info : col){ if(info.state == UpgradeRtu.STATE_OFFLINE){ info.isOver = true ; info.state = UpgradeRtu.STATE_FAILOFFLINE ; + count ++ ; } } } + return count ; + }else{ + return -1 ; } } /** + * 缁熻:宸茬粡杩涘崌绾т絾RTU鍙堣繘鍏ュ仠姝㈠崌绾у彂鍛嗙姸鎬侊紝瓒呰繃涓�瀹氭椂闄愶紝璁剧疆璁惧涓�鍖呮鎴栧鍖呮锛屽苟璁剧疆涓哄崌绾у畬鎴� + * @return -1:娌℃湁瓒呮椂锛�0瓒呮椂浜嗕笖鏃犲洜绂荤嚎琚己鍒惰缃崌绾у畬鎴愮殑RTU锛�>0绂荤嚎琚己鍒惰缃崌绾у畬鎴愮殑RTU鏁伴噺 + */ + protected int countRunningIdleRtuAndSetIfOver() { + Long now = System.currentTimeMillis() ; + int count = -1 ; + if(now - this.setupDtLong > UpgradeUnit.confVo.rtuOffLineWaitDuration){ + //璁剧疆涓婂彞锛岄槻姝㈤绻佽繘鍏ヤ笅闈㈣鍙ヨ繘琛岃绠� + if (this.taskVo.rtuAddrList != null && this.taskVo.rtuAddrList.size() > 0) { + Collection<UpgradeRtu> col = this.upgradeRtus.values() ; + for(UpgradeRtu info : col){ + if(info.state == UpgradeRtu.STATE_RUNNING && info.isOver == false){ + //鍗囩骇涓紝浣嗘湭鍗囩骇瀹屾垚 + if(now - info.lastDownDtAt > UpgradeUnit.confVo.runningAndIdleDuration){ + if(info.currentPackage <= 1){ + //涓�鍖呮 + info.state = UpgradeRtu.STATE_FAILONE ; + }else{ + //澶氬寘姝� + info.state = UpgradeRtu.STATE_FAIL ; + } + info.isOver = true ; + count ++ ; + } + } + } + } + } + return count ; + } + /** * 缁熻鏄惁鍗囩骇鍏ㄩ儴缁撴潫 */ - protected boolean statisticsIsAllOver() { + protected boolean countIsAllOver() { if (this.taskVo.rtuAddrList != null && this.taskVo.rtuAddrList.size() > 0) { Collection<UpgradeRtu> col = this.upgradeRtus.values() ; for(UpgradeRtu info : col){ -- Gitblit v1.8.0