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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.dy.simRtu202404;
 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
 
@Slf4j
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) //禁止启动数据库连接池
@ComponentScan(basePackages = {"com.dy.common", "com.dy.pipIrrGlobal", "com.dy.simRtu202404"},
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {
                        com.dy.common.apiDoc.SpringApiConfig.class, //一种排除类的方式
                        com.dy.pipIrrGlobal.config.DingTalk.class
                }),
                @ComponentScan.Filter(type = FilterType.REGEX, pattern = {
                        //二种排除类的方式,写正则表达式,需要对目标类的完全限定名完全匹配,否则不生效
                        "com.dy.common.aop..*",
                        "com.dy.common.apiDoc..*",
                        "com.dy.common.multiDataSource..*",
                        "com.dy.common.mybatis..*",
                        "com.dy.common.singleDataSource..*",
                        "com.dy.common.webFilter..*",
                        "com.dy.common.webListener..*",
                        "com.dy.pipIrrGlobal.webCtrls..*"
                })
        }
)
public class PipIrrMwSimulateRtu202404Application implements CommandLineRunner {
 
    /**
     * 参数0:rtu地址
     * 参数1:IC卡地址
     * 参数2:IC卡编号
     * 参数3:通信中间件IP
     * 参数4:通信中间件端口
     * 参数5:运行方式(0:只上报心跳;1:上报心跳 + 1次(开阀);2:上报心跳 + 1次(关阀);3:上报心跳 + 1次(开阀 + 关阀);4:上报心跳 +
     * @param args
     */
    public static void main(String[] args) {
        parseArg0(args, 0) ;
        parseArg1(args, 1) ;
        parseArg2(args, 2) ;
        parseArg3(args, 3) ;
        parseArg4(args, 4) ;
        parseArg5(args, 5) ;
        
        new SpringApplicationBuilder(PipIrrMwSimulateRtu202404Application.class)
                .web(WebApplicationType.NONE)//不启动web服务
                .run(args);
    }
 
    private static void parseArg0(String[] args, int index){
        if(args != null
                && args.length > index
                && args[index] != null
                && !args[index].trim().equals("")){
            ServerProperties.rtuAddr = args[index] ;//本模拟器模拟RTU地址
            log.info("参数1:" + ServerProperties.rtuAddr);
        }
        if(ServerProperties.rtuAddr == null){
            ServerProperties.rtuAddr = "37142501020100218" ;
        }
    }
    private static void parseArg1(String[] args, int index){
        if(args != null
                && args.length > index
                && args[index] != null
                && !args[index].trim().equals("")){
            ServerProperties.icCardAddr = args[index] ;//IC卡地址
            log.info("参数2:" + ServerProperties.icCardAddr);
        }
        if(ServerProperties.icCardAddr == null){
            ServerProperties.icCardAddr = "C49A340D" ;
        }
    }
    private static void parseArg2(String[] args, int index){
        if(args != null
                && args.length > index
                && args[index] != null
                && !args[index].trim().equals("")){
            ServerProperties.icCardNo = args[index] ;//IC卡编号
            log.info("参数3:" + ServerProperties.icCardNo);
        }
        if(ServerProperties.icCardNo == null){
            ServerProperties.icCardNo = "37142501020100257" ;
        }
    }
    private static void parseArg3(String[] args, int index){
        if(args != null
                && args.length > index
                && args[index] != null
                && !args[index].trim().equals("")){
            ServerProperties.serverIp = args[index] ;//通信中间件服务端IP
            log.info("参数4:" + ServerProperties.serverIp);
        }
        if(ServerProperties.serverIp == null){
            ServerProperties.serverIp = "127.0.0.1" ;
        }
    }
    private static void parseArg4(String[] args, int index){
        if(args != null
                && args.length > index
                && args[index] != null
                && !args[index].trim().equals("")){
            ServerProperties.serverPort = Integer.parseInt(args[index]) ;//通信中间件服务端端口
            log.info("参数5:" + ServerProperties.serverPort);
        }
        if(ServerProperties.serverPort == null){
            ServerProperties.serverPort = 60000 ;
        }
    }
    private static void parseArg5(String[] args, int index){
        if(args != null
                && args.length > index
                && args[index] != null
                && !args[index].trim().equals("")){
            ServerProperties.type = Integer.parseInt(args[index]) ;//运行方式
            log.info("参数6:" + ServerProperties.type);
        }
        if(ServerProperties.type == null){
            ServerProperties.type = 0 ;
        }
    }
    /**
     * Spring容器启动完成后,执行下面方法
     * @param args 参数
     * @throws Exception 异常
     */
    @Override
    public void run(String... args) throws Exception {
        try{
            //等待一下
            Thread.sleep(500L);
        }catch (Exception e){
            e.printStackTrace();
        }
        finally {
            this.startMwSv() ;
        }
    }
 
    private void startMwSv(){
        if(sv != null){
            sv.startServer();
        }
    }
 
 
    private Server sv ;
 
    @Autowired
    public void setSv(Server sv){
        this.sv = sv ;
    }
}