From 107ef10e9309dd299e8983232dbec5beacecb06d Mon Sep 17 00:00:00 2001
From: zhubaomin <zhubaomin>
Date: 星期四, 28 十一月 2024 15:14:19 +0800
Subject: [PATCH] 获取任务类型列表接口,获取工单列表接口返回值增加处理结果ID字段
---
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java | 124 ++++++++++++++++++++++++++++++-----------
1 files changed, 90 insertions(+), 34 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 e0b3d13..b19ea75 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
@@ -8,8 +8,12 @@
import com.dy.common.util.Callback;
import com.dy.common.util.DateTime;
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
@@ -18,6 +22,8 @@
*/
@Data
public class UpgradeTask {
+
+ private static final Logger log = LogManager.getLogger(UpgradeTask.class.getName());
protected static final String TaskOverType_Natural = "鑷劧" ;
protected static final String TaskOverType_Force = "寮哄埗" ;
@@ -37,7 +43,7 @@
protected byte[][] softFileDataGrp ;//浠�512瀛楄妭涓哄崟浣嶆妸鍗囩骇绋嬪簭鏁版嵁鍒嗙粍
@JSONField(serialize = false)
- protected Map<String, UpgradeRtu> upgradeRtus;//鍗囩骇鐘舵��
+ protected ConcurrentHashMap<String, UpgradeRtu> upgradeRtus;//鍗囩骇鐘舵��
public boolean taskIsOver = false ;//浠诲姟鏄惁瀹屾垚
public String taskOverType = "" ;//浠诲姟瀹屾垚鏂瑰紡锛堣嚜鐒讹紝寮哄埗锛�
@@ -76,7 +82,7 @@
if(taskVo.softStartAddr == null || taskVo.softStartAddr.trim().length() != 8){
throw new Exception("绋嬪簭瑕嗙洊璧峰鍦板潃涓嶅悎娉曪紝蹇呴』鏄�8瀛楃锛堝崄鍏繘鍒讹級鐨勫瓧绗︿覆") ;
}
- if(taskVo.softFileData == null || taskVo.softFileData.length <= 0){
+ if(taskVo.softFileData64 == null || taskVo.softFileData64.trim().length() == 0){
throw new Exception("鍗囩骇绋嬪簭鍐呭蹇呴』鎻愪緵") ;
}
if(taskVo.softBytesCalculate == null){
@@ -95,14 +101,19 @@
this.setupDtLong = System.currentTimeMillis() ;
this.taskVo = taskVo ;
- this.upgradeRtus = new HashMap<>();
- if(taskVo.softFileData != null && taskVo.softFileData.length >0){
+ this.upgradeRtus = new ConcurrentHashMap<>();
+ if(taskVo.softFileData64 != null && !taskVo.softFileData64.trim().equals("")){
+ taskVo.softFileData = Base64.getDecoder().decode(taskVo.softFileData64);
List<byte[]> listBytes = new HexFileParse().splitBytesByUnit512(taskVo.softFileData);
this.softFileDataGrp = listBytes.toArray(new byte[0][]);
- for(String rtuAddr : this.taskVo.rtuAddrList){
- //姝ゆ椂鐘舵�佽缃垚绂荤嚎鐘舵��
- UpgradeRtuDev ugRtu = new UpgradeRtuDev(this, rtuAddr, this.taskVo.softFileData.length, UpgradeRtuDev.STATE_OFFLINE) ;
- this.upgradeRtus.put(rtuAddr, ugRtu) ;
+ try{
+ for(String rtuAddr : this.taskVo.rtuAddrList){
+ //姝ゆ椂鐘舵�佽缃垚绂荤嚎鐘舵��
+ UpgradeRtuDev ugRtu = new UpgradeRtuDev(this.taskVo, this.failTryTimes, rtuAddr, this.softFileDataGrp.length, UpgradeRtuDev.STATE_OFFLINE) ;
+ this.upgradeRtus.put(rtuAddr, ugRtu) ;
+ }
+ }catch (Exception e){
+ log.error(e);
}
}
}
@@ -120,14 +131,13 @@
//鏍规嵁鏂规硶setTask鐨勯�昏緫锛屽彧瑕丷TU鍦ㄥ崌绾т箣鍒楋紝姝ゅugRtuState涓�瀹氫笉涓簄ull
//涓轰繚闄╋紝瀹炵幇涓嬮潰閫昏緫
if(taskVo.rtuAddrList.contains(rtuAddr)){
- ugRtu = new UpgradeRtuDev(this, rtuAddr, this.taskVo.softFileData.length) ;
+ ugRtu = new UpgradeRtuDev(this.taskVo, this.failTryTimes, rtuAddr, this.taskVo.softFileData.length) ;
upgradeRtus.put(rtuAddr, ugRtu) ;
}else{
//rtu涓嶅湪鍗囩骇涔嬪垪
return ;
}
- }
- if(ugRtu != null){
+ }else{
if(ugRtu.isOver){
//褰撳墠RTU宸茬粡鍗囩骇瀹屾垚锛屾棤闇�鍐嶅崌绾�
return;
@@ -163,9 +173,6 @@
ugRtu.trigger(code, protocolName, protocolVersion, this.softFileDataGrp, callbackCom) ;
}
}
- }else{
- //rtu涓嶅湪鍗囩骇涔嬪垪
- return ;
}
}
}
@@ -174,11 +181,13 @@
* 寮哄埗缁撴潫鍗囩骇浠诲姟
*/
public void forceOver(){
- this.taskIsOver = true ;//寮哄埗璁剧疆浠诲姟瀹屾垚
- this.taskOverType = TaskOverType_Force ;//浠诲姟瀹屾垚鏂瑰紡锛堣嚜鐒讹紝寮哄埗锛�
- this.taskOverDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;//浠诲姟瀹屾垚鏃堕棿(yyyy-mm-dd HH:MM:SS)
- //this.taskVo.rtuAddrList.clear();
- //this.upgradeState.clear();
+ if(!this.taskIsOver){
+ this.taskIsOver = true ;//寮哄埗璁剧疆浠诲姟瀹屾垚
+ this.taskOverType = TaskOverType_Force ;//浠诲姟瀹屾垚鏂瑰紡锛堣嚜鐒讹紝寮哄埗锛�
+ this.taskOverDt = DateTime.yyyy_MM_dd_HH_mm_ss() ;//浠诲姟瀹屾垚鏃堕棿(yyyy-mm-dd HH:MM:SS)
+ //this.taskVo.rtuAddrList.clear();
+ //this.upgradeState.clear();
+ }
}
/**
@@ -190,25 +199,36 @@
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){
- if(info.state == UpgradeRtuDev.STATE_OFFLINE){
- state.offLineTotal ++ ;
- }else if(info.state == UpgradeRtuDev.STATE_UNSTART){
+ AtomicBoolean hasRunning = new AtomicBoolean(false);
+ this.upgradeRtus.values().forEach(info ->{
+ if(info.state == UpgradeRtu.STATE_OFFLINE){
+ state.offLineTotal++ ;
+ }else if(info.state == UpgradeRtu.STATE_UNSTART){
state.unStartTotal ++ ;
- }else if(info.state == UpgradeRtuDev.STATE_RUNNING){
+ }else if(info.state == UpgradeRtu.STATE_RUNNING){
state.runningTotal ++ ;
- }else if(info.state == UpgradeRtuDev.STATE_SUCCESS) {
+ }else if(info.state == UpgradeRtu.STATE_SUCCESS) {
state.successTotal++;
- }else if(info.state == UpgradeRtuDev.STATE_FAILONE) {
+ }else if(info.state == UpgradeRtu.STATE_FAILONE) {
state.failOneTotal++;
state.failTotal++;
- }else if(info.state == UpgradeRtuDev.STATE_FAIL) {
+ }else if(info.state == UpgradeRtu.STATE_FAIL) {
+ state.failMultiTotal++;
state.failTotal++;
+ }else if(info.state == UpgradeRtu.STATE_FAILOFFLINE) {
+ state.failTotal++;
+ state.failOffTotal++;
}
if(info.isOver){
state.overTotal++;
+ }else{
+ hasRunning.set(true);
}
+ });
+ if(!hasRunning.get()){
+ state.allOver = true ;
+ }else{
+ state.allOver = false ;
}
}
}
@@ -252,12 +272,42 @@
}
///////////////////////////////////////////////////////////
- //浠ヤ笅鏂规硶涓哄唴閮ㄦ湇鍔★紝涓嶅澶栨彁渚涙湇鍔�
+ //
+ // 浠ヤ笅鏂规硶涓哄唴閮ㄦ湇鍔★紝涓嶅澶栨彁渚涙湇鍔�
+ //
///////////////////////////////////////////////////////////
+
/**
- * 缁熻褰撳墠姝e湪鍗囩骇鐨凴TU鏁伴噺锛屼负鍙楅檺鍚屾椂鍗囩骇鏁伴噺鍋氬噯澶�
+ * 鍒ゆ柇鏄惁娌$敤浠讳綍涓�涓猂TU杩涜杩囧崌绾э紝鑰屼笖瓒呰繃浜嗘椂闄�
+ * @return -1:鏃犱竴RTU鍗囩骇涓旇秴鏃讹紝0锛氭棤RTU鍗囩骇浣嗘湭瓒呮椂绛夊緟锛�1鏈塕TU鍗囩骇姝e父鎵ц
*/
- protected void statisticsRunningRtuCount(){
+ protected int countNoOneRtuUpgradeInDuration(){
+ if(this.upgradeRtus == null || upgradeRtus.size() == 0){
+ //褰撳墠娌℃湁浠讳綍涓�涓澶囪繘琛岃繃鍗囩骇
+ Long now = System.currentTimeMillis() ;
+ if(now - this.setupDtLong > UpgradeUnit.confVo.noOneRtuUpgradeMaxDuration){
+ return -1 ;
+ }
+ }else{
+ Collection<UpgradeRtu> col = this.upgradeRtus.values() ;
+ for(UpgradeRtu info : col){
+ if(info.currentPackage > 0){
+ //褰撳墠鏈夎澶囪繘琛岃繃鍗囩骇
+ return 1 ;
+ }
+ }
+ Long now = System.currentTimeMillis() ;
+ if(now - this.setupDtLong > UpgradeUnit.confVo.noOneRtuUpgradeMaxDuration){
+ return -1 ;
+ }
+ }
+ return 0 ;
+ }
+
+ /**
+ * 缁熻褰撳墠姝e湪鍗囩骇鐨凴TU鏁伴噺锛屼负鍚屾椂鍗囩骇鏁伴噺闄愬埗鍋氬噯澶�
+ */
+ protected void countRunningRtuCount(){
int runningTotal = 0 ;
Collection<UpgradeRtu> col = this.upgradeRtus.values() ;
for(UpgradeRtu info : col){
@@ -269,28 +319,34 @@
}
/**
- * 缁熻闇�瑕佸崌绾т絾褰撳墠绂荤嚎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 ;
}
}
/**
* 缁熻鏄惁鍗囩骇鍏ㄩ儴缁撴潫
*/
- 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