liurunyu
2024-07-05 b83f639362ae959de55900d14d132585cd72a90d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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.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()) ;
                    //第一次发现,下发清空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) ;
        }
    }
}