From 14d7f0df63340ede75458c0e91b902376ef4dd64 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 20 十一月 2024 11:26:32 +0800
Subject: [PATCH] 1、优化代码;2、修改长级测试中发现的bug;3、通信中间件配置文件配置项修改

---
 pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java |   55 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 46 insertions(+), 9 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 77e5baf..68d6305 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,11 @@
 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;
 
 /**
  * @Author: liurunyu
@@ -18,6 +21,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 +42,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 = "" ;//浠诲姟瀹屾垚鏂瑰紡锛堣嚜鐒讹紝寮哄埗锛�
@@ -95,15 +100,19 @@
         this.setupDtLong = System.currentTimeMillis() ;
         this.taskVo = taskVo ;
 
-        this.upgradeRtus = new HashMap<>();
-        if(taskVo.softFileData64 != null && taskVo.softFileData64.trim().equals("")){
+        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.softFileDataGrp.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);
             }
         }
     }
@@ -121,7 +130,7 @@
                 //鏍规嵁鏂规硶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涓嶅湪鍗囩骇涔嬪垪
@@ -257,8 +266,36 @@
     ///////////////////////////////////////////////////////////
     //浠ヤ笅鏂规硶涓哄唴閮ㄦ湇鍔★紝涓嶅澶栨彁渚涙湇鍔�
     ///////////////////////////////////////////////////////////
+
     /**
-     * 缁熻褰撳墠姝e湪鍗囩骇鐨凴TU鏁伴噺锛屼负鍙楅檺鍚屾椂鍗囩骇鏁伴噺鍋氬噯澶�
+     * 鍒ゆ柇鏄惁娌$敤浠讳綍涓�涓猂TU杩涜杩囧崌绾э紝鑰屼笖瓒呰繃浜嗘椂闄�
+     * @return -1:鏃犱竴RTU鍗囩骇涓旇秴鏃讹紝0锛氭棤RTU鍗囩骇浣嗘湭瓒呮椂绛夊緟锛�1鏈塕TU鍗囩骇姝e父鎵ц
+     */
+    protected int countNoOneRtuUpgrade(){
+        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 statisticsRunningRtuCount(){
         int runningTotal = 0 ;

--
Gitblit v1.8.0