liurunyu
2024-12-05 e48d097ca0532090a7a109af4c2c9c6e1b288a34
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java
@@ -52,7 +52,7 @@
    ///////////////////////////////////////////////////
    //以下内部控制用
    @JSONField(serialize = false)
    private int curUgRunningRtuTotal = 0 ;//当前正在升级的RTU个数
    protected int curUgRunningRtuTotal = 0 ;//当前正在升级的RTU个数
    public UpgradeTask() {
        this.curUgRunningRtuTotal = 0 ;
@@ -176,7 +176,6 @@
            }
        }
    }
    /**
     * 强制结束升级任务
     */
@@ -189,6 +188,7 @@
            //this.upgradeState.clear();
        }
    }
    /**
     * 当前升级状态
@@ -210,11 +210,15 @@
                    }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.failMultiTotal++;
                        state.failTotal++;
                        state.dieMultiTotal++;
                        if(info.isOver) {
                            state.failTotal++;
                        }
                    }else if(info.state == UpgradeRtu.STATE_FAILOFFLINE) {
                        state.failTotal++;
                        state.failOffTotal++;
@@ -307,7 +311,7 @@
    /**
     * 统计当前正在升级的RTU数量,为同时升级数量限制做准备
     */
    protected void countRunningRtuCount(){
    protected int countRunningRtuCount(){
        int runningTotal = 0 ;
        Collection<UpgradeRtu> col = this.upgradeRtus.values() ;
        for(UpgradeRtu info : col){
@@ -315,28 +319,65 @@
                runningTotal ++ ;
            }
        }
        this.curUgRunningRtuTotal = runningTotal ;
        return this.curUgRunningRtuTotal = runningTotal ;
    }
    /**
     * 统计需要升级但当前离线RTU的情况,超过时限的设备为升级完成
     * @return -1:没有超时,0超时了且无因离线被强制设置升级完成的RTU,>0离线被强制设置升级完成的RTU数量
     */
    protected void countOffRtuAndSetIfOver() {
    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 ;
    }
    /**
     * 统计是否升级全部结束
     */