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 = "" ;//任务完成方式(自然,强制)
@@ -76,7 +81,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 +100,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,7 +130,7 @@
                //根据方法setTask的逻辑,只要RTU在升级之列,此处ugRtuState一定不为null
                //为保险,实现下面逻辑
                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不在升级之列
@@ -174,11 +184,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();
        }
    }
    /**
@@ -192,18 +204,18 @@
            if(this.upgradeRtus != null && this.upgradeRtus.size() > 0){
                Collection<UpgradeRtu> col = this.upgradeRtus.values() ;
                for(UpgradeRtu info : col){
                    if(info.state == UpgradeRtuDev.STATE_OFFLINE){
                    if(info.state == UpgradeRtu.STATE_OFFLINE){
                        state.offLineTotal ++ ;
                    }else if(info.state == UpgradeRtuDev.STATE_UNSTART){
                    }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.failTotal++;
                    }
                    if(info.isOver){
@@ -254,8 +266,36 @@
    ///////////////////////////////////////////////////////////
    //以下方法为内部服务,不对外提供服务
    ///////////////////////////////////////////////////////////
    /**
     * 统计当前正在升级的RTU数量,为受限同时升级数量做准备
     * 判断是否没用任何一个RTU进行过升级,而且超过了时限
     * @return -1:无一RTU升级且超时,0:无RTU升级但未超时等待,1有RTU升级正常执行
     */
    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 ;
    }
    /**
     * 统计当前正在升级的RTU数量,为同时升级数量限制做准备
     */
    protected void statisticsRunningRtuCount(){
        int runningTotal = 0 ;