liurunyu
2024-11-20 f695fa17fce26c0266ff682622d761767a8dcbfa
1、优化代码;
2、增加一个统计状态:离线升级失败状态。
4个文件已修改
47 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/softUpgrade/state/UpgradeState.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeUnit.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/softUpgrade/state/UpgradeState.java
@@ -16,8 +16,9 @@
    public int runningTotal ;//所有正在升级
    public int overTotal ;//所有结束(包括成功与所有失败)
    public int successTotal ;//所有成功
    public int failTotal ;//所有失败
    public int failTotal ;//所有失败(一包死失败+多包死失败+离线失败)
    public int failOneTotal ;//所有一包死失败
    public int failOffTotal ;//所有离线失败
    public Boolean allOver ;//所有都结束(true:是,false:否)
@@ -34,6 +35,7 @@
        this.successTotal = 0;
        this.failTotal = 0;
        this.failOneTotal = 0;
        this.failOffTotal = 0;
        this.allOver = false ;
    }
@@ -47,7 +49,8 @@
        sb.append("    \n已结束总数:" + overTotal) ;
        sb.append("    \n成功总数:" + successTotal) ;
        sb.append("    \n失败总数:" + failTotal) ;
        sb.append("    \n1包死总数:" + failOneTotal) ;
        sb.append("    \n1包死失败总数:" + failOneTotal) ;
        sb.append("    \n离线失败总数:" + failOffTotal) ;
        sb.append("    \n全结束:" + allOver) ;
        return sb.toString() ;
    }
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeManager.java
@@ -75,10 +75,13 @@
    }
    /**
     * 结束当前升级任务
     * 强制结束当前升级任务,
     * 此功能可能不会开放出去,
     * 因为强制结束升级任务,对一个未升级完成的RTU就会卡死,
     * 所以当强制结束升级任务,代码逻辑并没有强制结果RTU升级过程,如果升级过程也强制停止,那么RTU真会卡死
     * @throws Exception
     */
    public void overUpgradeTask() throws Exception {
    public void forceOverUpgradeTask() throws Exception {
        if(this.task != null){
            this.stop();
            this.task.forceOver();
@@ -193,20 +196,21 @@
                if(!this.task.taskIsOver){
                    //升级任务未完成
                    //工作1:判断是否无任何一个RTU进行过升级,并且达到时限,则认为当前升级任务完成
                    int temp = this.task.countNoOneRtuUpgrade() ;
                    //-1:无一RTU升级且超时,0:无RTU升级但未超时等待,1有RTU升级正常执行
                    int temp = this.task.countNoOneRtuUpgradeInDuration() ;
                    if(temp == -1){
                        this.task.taskIsOver = true ;
                        //任务已经完成
                        this.stop();
                    }else if(temp == 1){
                        //工作2:统计当前正在升级的RTU数量,为同时升级数量限制做准备
                        this.task.statisticsRunningRtuCount() ;
                        this.task.countRunningRtuCount() ;
                        //工作3:统计需要升级但当前离线RTU的情况
                        this.task.statisticsOffRtuCountAndSet() ;
                        //工作3:统计需要升级但当前离线RTU的情况,超过时限的设备为升级完成
                        this.task.countOffRtuAndSetIfOver() ;
                        //工作4:统计是否全部升级完成
                        this.task.taskIsOver = this.task.statisticsIsAllOver() ;
                        this.task.taskIsOver = this.task.countIsAllOver() ;
                    }else if(temp == 0){
                        //不作为
                    }
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java
@@ -202,8 +202,7 @@
        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){
                this.upgradeRtus.values().stream().forEach(info ->{
                    if(info.state == UpgradeRtu.STATE_OFFLINE){
                        state.offLineTotal ++ ;
                    }else if(info.state == UpgradeRtu.STATE_UNSTART){
@@ -212,16 +211,19 @@
                        state.runningTotal ++ ;
                    }else if(info.state == UpgradeRtu.STATE_SUCCESS) {
                        state.successTotal++;
                    }else if(info.state == UpgradeRtu.STATE_FAIL) {
                        state.failTotal++;
                    }else if(info.state == UpgradeRtu.STATE_FAILONE) {
                        state.failOneTotal++;
                        state.failTotal++;
                    }else if(info.state == UpgradeRtu.STATE_FAIL) {
                    }else if(info.state == UpgradeRtu.STATE_FAILOFFLINE) {
                        state.failTotal++;
                        state.failOffTotal++;
                    }
                    if(info.isOver){
                        state.overTotal++;
                    }
                }
                });
            }
        }
        return state ;
@@ -271,7 +273,7 @@
     * 判断是否没用任何一个RTU进行过升级,而且超过了时限
     * @return -1:无一RTU升级且超时,0:无RTU升级但未超时等待,1有RTU升级正常执行
     */
    protected int countNoOneRtuUpgrade(){
    protected int countNoOneRtuUpgradeInDuration(){
        if(this.upgradeRtus == null || upgradeRtus.size() == 0){
            //当前没有任何一个设备进行过升级
            Long now = System.currentTimeMillis() ;
@@ -297,7 +299,7 @@
    /**
     * 统计当前正在升级的RTU数量,为同时升级数量限制做准备
     */
    protected void statisticsRunningRtuCount(){
    protected void countRunningRtuCount(){
        int runningTotal = 0 ;
        Collection<UpgradeRtu> col = this.upgradeRtus.values() ;
        for(UpgradeRtu info : col){
@@ -309,9 +311,9 @@
    }
    /**
     * 统计需要升级但当前离线RTU的情况
     * 统计需要升级但当前离线RTU的情况,超过时限的设备为升级完成
     */
    protected void statisticsOffRtuCountAndSet() {
    protected void countOffRtuAndSetIfOver() {
        Long now = System.currentTimeMillis() ;
        if(now - this.setupDtLong > UpgradeUnit.confVo.rtuOffLineWaitDuration){
            //rtu离线,等待其升级的时长(毫秒),超过配置的最大时长,设置其升级失败,且设置升级任务完成
@@ -330,7 +332,7 @@
    /**
     * 统计是否升级全部结束
     */
    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){
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeUnit.java
@@ -78,7 +78,7 @@
     */
    public void overUpgradeTask() throws Exception {
        if(manager != null ){
            manager.overUpgradeTask() ;
            manager.forceOverUpgradeTask() ;
        }
    }