liurunyu
2024-11-28 b9a55925e492dcd02d6b8268797b0a02136cf3a7
pipIrr-platform/pipIrr-web/pipIrr-web-remote/src/main/java/com/dy/pipIrrRemote/rtuUpgrage/RtuUpgradeStateReceiverCtrl.java
@@ -21,6 +21,7 @@
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -65,11 +66,11 @@
            }
        }
        if(cache == null){
            cache = info;
            //此时不做任务操作,只保障cache不为空, 等待下次发来数据
            if(info.ugRtuStateList != null && info.ugRtuStateList.size() > 0){
                List<UpgradeRtu> overList = info.ugRtuStateList.stream().filter(itemVo -> itemVo.isOver).collect(Collectors.toList()) ;
                if(overList != null && overList.size() > 0){
                    cache = info;
                    this.save2Db(info.ugTaskId, overList);
                }
            }
@@ -78,8 +79,13 @@
            if(info.ugRtuStateList != null && info.ugRtuStateList.size() > 0){
                //此时保证两个集合都不为null
                this.save2Db(info.ugTaskId, info.ugRtuStateList, cache.ugRtuStateList);
                cache = info;
            }
            if(info.ugRtuStateList != null && info.ugRtuStateList.size() > 0){
                //此时保证两个集合都不为null
                info.ugRtuStateList.stream().sorted(Comparator.comparing(UpgradeRtu::getRtuAddr, Comparator.naturalOrder())).collect(Collectors.toList());
            }
            //cache赋值必须放在上面处理的后面,否则上面的比较不成功
            cache = info;
        }
        return null;
    }
@@ -103,9 +109,10 @@
     */
    private void save2Db(String taskId, List<UpgradeRtu> newList, List<UpgradeRtu> oldList){
        List<UpgradeRtu> newOverList = newList.stream().filter(vo -> vo.isOver).collect(Collectors.toList()) ;
        List<UpgradeRtu> oldNoOverList = newList.stream().filter(vo -> !vo.isOver).collect(Collectors.toList()) ;
        for(UpgradeRtu nvo : newOverList){
            if(nvo != null) {
                if(oldList.stream().anyMatch(vo -> vo.rtuAddr.equals(nvo.rtuAddr) && vo.isOver == false)){
                if(oldNoOverList.stream().anyMatch(vo -> vo.rtuAddr.equals(nvo.rtuAddr))){
                    //上次没有升级结束,而当前升级结束了
                    this.sv.saveRtuUpgradeState(Long.parseLong(taskId), nvo);
                }
@@ -154,7 +161,7 @@
                                @Override
                                public Object execute() throws Exception {
                                    while(!this.stop){
                                        if(!runDemo()){
                                        if(!runInDemo()){
                                            this.stop = true ;
                                        }else{
                                            try {
@@ -188,7 +195,7 @@
            }
        }
    }
    private boolean runDemo(){
    private boolean runInDemo(){
        for(UpgradeRtu rtu : cache.ugRtuStateList){
            this.rtuUpgrade(rtu) ;
        }
@@ -244,7 +251,7 @@
        }
        int n = Integer.parseInt(new CreateRandom().create(3)) ;
        if(n == 540 || n == 541 || n == 542 || n == 543 || n == 544 || n == 545){
        if(n == 540 || n == 541 || n == 542 || n == 543 || n == 544 || n == 545 || n == 546 || n == 547 || n == 548 || n == 549 ){
            if(rtu.currentPackage == 1){
                //1包死
                rtu.state = UpgradeRtu.STATE_FAILONE ;
@@ -296,6 +303,7 @@
            for(UpgradeRtu rtu : cache.ugRtuStateList){
                if(rtu.state == UpgradeRtu.STATE_OFFLINE){
                    cache.ugOverallState.offLineTotal ++ ;
                    cache.ugOverallState.failTotal++;
                }else if(rtu.state == UpgradeRtu.STATE_UNSTART){
                    cache.ugOverallState.unStartTotal ++ ;
                }else if(rtu.state == UpgradeRtu.STATE_RUNNING){
@@ -304,9 +312,10 @@
                }else if(rtu.state == UpgradeRtu.STATE_SUCCESS) {
                    cache.ugOverallState.successTotal++;
                }else if(rtu.state == UpgradeRtu.STATE_FAILONE) {
                    cache.ugOverallState.failOneTotal++;
                    cache.ugOverallState.dieOneTotal++;
                    cache.ugOverallState.failTotal++;
                }else if(rtu.state == UpgradeRtu.STATE_FAIL) {
                    cache.ugOverallState.dieMultiTotal++;
                    cache.ugOverallState.failTotal++;
                }
                if(rtu.isOver){
@@ -317,6 +326,15 @@
        if(!hasRunning){
            cache.ugOverallState.allOver = true ;
        }
        if(cache.ugOverallState.allOver){
            cache.ugOverallState.overTotal = 0;
            if(cache.ugRtuStateList != null && cache.ugRtuStateList.size() > 0){
                for(UpgradeRtu rtu : cache.ugRtuStateList){
                    rtu.isOver = true ;
                    cache.ugOverallState.overTotal++;
                }
            }
        }
        return hasRunning ;
    }
}