liurunyu
2024-12-05 0cbe3bf67b051b6e66861ea97da2aea08e1fb2ad
pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/server/upgrade/UpgradeTask.java
@@ -1,12 +1,14 @@
package com.dy.rtuMw.server.upgrade;
import com.alibaba.fastjson2.annotation.JSONField;
import com.dy.common.mw.protocol.rtuState.RtuStatus;
import com.dy.common.softUpgrade.parse.HexFileParse;
import com.dy.common.softUpgrade.state.UpgradeRtu;
import com.dy.common.softUpgrade.state.UpgradeState;
import com.dy.common.softUpgrade.state.UpgradeTaskVo;
import com.dy.common.util.Callback;
import com.dy.common.util.DateTime;
import com.dy.rtuMw.server.forTcp.RtuStatusDealer;
import lombok.Data;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -32,6 +34,8 @@
    protected Integer failTryTimes ;//升级失败后,重新偿试升级次数,0表示不重新偿试升级
    @JSONField(serialize = false)
    protected Integer ugMaxRtuSameTime ;//同时升级RTU最大个数
    @JSONField(serialize = false)
    private Integer lastOpenMaxGoOn ;//阀开(泵开)状态设置以来持续最长时间(秒钟),超过这个时间认为状态无效(这个时长取决于工作报间隔)
    public String setupDt ;//设置时间(yyyy-mm-dd HH:MM:SS)
    @JSONField(serialize = false)
@@ -60,7 +64,8 @@
    /**
     *  初始化配置信息
     */
    public void initOption(Integer failTryTimes, Integer ugMaxRtuSameTime) {
    public void initOption(Integer lastOpenMaxGoOn, Integer failTryTimes, Integer ugMaxRtuSameTime) {
        this.lastOpenMaxGoOn = lastOpenMaxGoOn;
        this.failTryTimes = failTryTimes;
        this.ugMaxRtuSameTime = ugMaxRtuSameTime;
    }
@@ -222,6 +227,9 @@
                    }else if(info.state == UpgradeRtu.STATE_FAILOFFLINE) {
                        state.failTotal++;
                        state.failOffTotal++;
                    }else if(info.state == UpgradeRtu.STATE_FAILOPEN) {
                        state.failTotal++;
                        state.failOpenTotal++;
                    }
                    if(info.isOver){
                        state.overTotal++;
@@ -282,6 +290,29 @@
    ///////////////////////////////////////////////////////////
    /**
     * 阀开(泵开)不升级处理
     */
    protected void openNoUpgrade(){
        if(this.upgradeRtus != null && this.upgradeRtus.size() > 0){
            Map<String, RtuStatus> rsAllMap = RtuStatusDealer.allStatus() ;
            Long now = System.currentTimeMillis() ;
            this.upgradeRtus.values().stream().forEach(a -> {
                RtuStatus rs = rsAllMap.get(a.rtuAddr) ;
                if(rs != null
                        && rs.valveOpenTrueCloseFalse != null && rs.valveOpenTrueCloseFalse.booleanValue() == true
                        && rs.valveStatusLastTimeStamp != null){
                    //有状态,并且是阀开(泵开)
                    Long gap = now - rs.valveStatusLastTimeStamp ;
                    if(gap < this.lastOpenMaxGoOn){
                        //这时采纳阀门打开状态不能升级
                        a.isOver = true ;
                        a.state = UpgradeRtu.STATE_FAILOPEN ;
                    }
                }
            });
        }
    }
    /**
     * 判断是否没用任何一个RTU进行过升级,而且超过了时限
     * @return -1:无一RTU升级且超时,0:无RTU升级但未超时等待,1有RTU升级正常执行
     */