package com.dy.rtuMw.server.rtuData.p206V202404; 
 | 
  
 | 
import com.dy.common.mw.protocol.Command; 
 | 
import com.dy.common.mw.protocol.CommandType; 
 | 
import com.dy.common.mw.protocol.Data; 
 | 
import com.dy.common.mw.protocol.p206V1_0_0.CodeV1_0_1; 
 | 
import com.dy.common.mw.protocol.p206V202404.CodeV202404; 
 | 
import com.dy.common.springUtil.SpringContextUtil; 
 | 
import com.dy.pipIrrGlobal.pojoPr.PrController; 
 | 
import com.dy.pipIrrGlobal.pojoPr.PrControllerTramp; 
 | 
import com.dy.rtuMw.server.ServerProperties; 
 | 
import com.dy.rtuMw.server.rtuData.TaskSurpport; 
 | 
import com.dy.rtuMw.server.rtuData.dbSv.DbSv; 
 | 
import com.dy.rtuMw.web.com.CommandCtrl; 
 | 
import org.apache.logging.log4j.LogManager; 
 | 
import org.apache.logging.log4j.Logger; 
 | 
  
 | 
import java.text.ParseException; 
 | 
import java.util.Date; 
 | 
/** 
 | 
 * @Author liurunyu 
 | 
 * @Date 2024/5/8 14:18 
 | 
 */ 
 | 
public class TkPreGenObjsV202404 extends TaskSurpport { 
 | 
  
 | 
    private static final Logger log = LogManager.getLogger(TkPreGenObjsV202404.class.getName()) ; 
 | 
  
 | 
    //类ID,一定与Tree.xml配置文件中配置一致 
 | 
    public static final String taskId = "TkPreGenObjsV202404" ; 
 | 
  
 | 
    /** 
 | 
     * 执行节点任务 
 | 
     * @param data 需要处理的数据 
 | 
     */ 
 | 
    @Override 
 | 
    public void execute(Object data) throws ParseException { 
 | 
        Data d = (Data)data ; 
 | 
        String rtuAddr = d.getRtuAddr() ;//TkRtuData里判断了rtuAddr为空 
 | 
        DbSv sv = (DbSv) SpringContextUtil.getBean(DbSv.class) ; 
 | 
        if(sv != null){ 
 | 
            PrController controller = sv.getControllersByRtuAddrAndIntakeNotNull(rtuAddr) ; 
 | 
            PrControllerTramp controllerTramp = null ; 
 | 
            if(controller == null){ 
 | 
                //数据库中未查询到控制器(RTU实体)(已经绑定且控制器地址相符) 
 | 
                //流浪者控制器 
 | 
                controllerTramp = sv.getPrControllerTrampByRtuAddr(rtuAddr); 
 | 
                if(controllerTramp == null){ 
 | 
                    //第一次发现 
 | 
                    controllerTramp = new PrControllerTramp(null, rtuAddr, d.getProtocol(), new Date(), ServerProperties.orgTag) ; 
 | 
                    //第一次发现,下发清空RTU历史命令,以使其重新开始记录新地点的数据 
 | 
                    this.sendClearCommand(rtuAddr, d.protocol); 
 | 
                } 
 | 
            } 
 | 
            //不论是否为流浪控制器(RTU实体),都要进行下步工作,记录其上报的一些数据,当绑定控制器后,数据自动有了归属 
 | 
            this.taskResult = new Object[]{sv, controller, controllerTramp} ; 
 | 
            this.toNextTasks(data); 
 | 
        }else{ 
 | 
            log.error("严重错误,未能得到DbSv对象"); 
 | 
        } 
 | 
    } 
 | 
  
 | 
    /** 
 | 
     * 发送清空RTU的命令 
 | 
     * @param rtuAddr 
 | 
     * @param protocol 
 | 
     */ 
 | 
    private void sendClearCommand(String rtuAddr, String protocol){ 
 | 
        Command com = new Command() ; 
 | 
        com.id = Command.defaultId ; 
 | 
        com.rtuAddr = rtuAddr ; 
 | 
        com.protocol = protocol ; 
 | 
        com.type = CommandType.outerCommand; 
 | 
        com.code = CodeV202404.cd_99 ;//当前是p206V202404协议的任务 
 | 
        com.rtuResultSendWebUrl = Command.ignoreRtuResultSendWebUrl ; 
 | 
        com.param = null ; 
 | 
        com.attachment = null ; 
 | 
        CommandCtrl comCtrl = SpringContextUtil.getBean(CommandCtrl.class) ; 
 | 
        if(comCtrl != null){ 
 | 
            comCtrl.sendOutComFromLocal(com) ; 
 | 
        } 
 | 
    } 
 | 
} 
 |