whyclj
2020-10-20 e9f26f7b367518b4087ff34b336aa3f2fbc0fd79
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
package main;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import com.base.Com;
import com.config.AppConfig;
import com.config.AppParam;
import com.dev.data.ConfigData;
import com.dev.data.Dev_UDPServer_Thread;
import com.dev.data.Dev_UDPServer_Thread_SQL;
import com.dev.data.Device_Timing_Thread;
import com.dev.data.Device_inf;
import com.dev.data.HistoryData_RealDelete_Thread;
import com.dev.data.InverterPowerUDPServer_Thread;
import com.dev.data.ReadConfigFile;
import com.dev.data.SteamTurbineUDPServer_Thread;
import com.sql.MysqlConnPool;
 
public class main_MonitorServer_EquieDeviceData {
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /*********************  Ï·½É豸ֻÄÜÑ¡ÔñÒ»¸ö    *******************************/
    public final static boolean is_app_for_cmcc_only = false;
    public final static boolean is_app_for_fbo_data_only = false;
    public final static boolean is_app_for_fbs_free_only = false;
    public final static boolean is_app_for_bpm7100_only = false;
    public final static boolean is_app_for_FBS9100S_only = true;
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    /**************************************************************************/
    public final static boolean app_debug = false;
    public final static double m_VersionNum = 1.203;
    public final static String m_Version = "Welcome To Use main_MonitorServer_EquieDeviceData V" 
                                            + m_VersionNum ;
    /**************************************************************************/
    /**************************************************************************/
    public static final int DEF_MysqlServerFBS9100S_Port = 3360;
    public static final int DEF_MysqlServer_Port = 5306;
    public static final int DEF_MysqlServerFBS_Port = 5307;
    public static final int DEF_MysqlServerFBO_Port = 5308;
    public static final int DEF_MysqlServerBPM7100_Port = 5309;
    
    public static final int DEF_Socket_Server_Port = 1982;
    public static final int DEF_Socket_ServerFBS_Port = 1992;
    public static final int DEF_Socket_ServerFBO_Port = 2002;
    public static final int DEF_Socket_ServerBPM7100_Port = 2001;
    
    public static final int DEF_Socket_Server_FBI_Port = 1983;
    public static final int DEF_Socket_Server_FBIFBS_Port = 1993;
    public static final int DEF_Socket_Server_FBIFBO_Port = 2003;
    
    public static final int DEF_Socket_Server_IDCE8200_Port = 8200;
    public static final int DEF_Socket_Server_IDCE8200FBS_Port = 8210;
    public static final int DEF_Socket_Server_IDCE8200FBO_Port = 8220;
    
    public static final int DEF_Socket_Server_MOBILE_Port = 2016;
    public static final int DEF_Socket_Server_MOBILEFBS_Port = 2026;
    public static final int DEF_Socket_Server_MOBILEFBO_Port = 2036;
    public static final int DEF_Socket_Server_MOBILEBPM7100_Port = 2037;
    
    public static final int DEF_FTP_Server_Port = 2110;
    public static final int DEF_FTP_ServerFBS_Port = 2116;
    public static final int DEF_FTP_ServerFBO_Port = 2122;
    public static final int DEF_FTP_ServerBPM7100_Port = 2123;
    
    public static int MysqlServer_Port = DEF_MysqlServer_Port;
    public static int Socket_Server_Port = DEF_Socket_Server_Port;
    public static int Socket_Server_FBI_Port = DEF_Socket_Server_FBI_Port;
    public static int Socket_Server_IDCE8200_Port = DEF_Socket_Server_IDCE8200_Port;
    public static int Socket_Server_Mobile_Port = DEF_Socket_Server_MOBILE_Port;
    public static int FTP_Server_Port = DEF_FTP_Server_Port;
    
    private static AppConfig m_AppConfig;
    
    private static MysqlConnPool GB_MysqlConnPool;
    public static AppParam GB_App_Param;
    /*********************************************************************************************/
    /*********************************************************************************************/
    public static void main(String[] args) {
        String ver = m_Version;
        if(is_app_for_fbs_free_only)
        {
            ver += " app_for_fbs_free_only";
            if(is_app_for_bpm7100_only) {
                ver += " and app_for_bms7100_only";
            }
            MysqlServer_Port = DEF_MysqlServerFBS_Port;
            Socket_Server_Port = DEF_Socket_ServerFBS_Port;
            Socket_Server_FBI_Port = DEF_Socket_Server_FBIFBS_Port;
            Socket_Server_IDCE8200_Port = DEF_Socket_Server_IDCE8200FBS_Port;
            Socket_Server_Mobile_Port = DEF_Socket_Server_MOBILEFBS_Port;
            FTP_Server_Port = DEF_FTP_ServerFBS_Port;
        }
        if(is_app_for_bpm7100_only)
        {
            ver += " and app_for_bms7100_only";
            MysqlServer_Port = DEF_MysqlServerBPM7100_Port;
            Socket_Server_Port = DEF_Socket_ServerBPM7100_Port;
            Socket_Server_Mobile_Port = DEF_Socket_Server_MOBILEBPM7100_Port;
            FTP_Server_Port = DEF_FTP_ServerBPM7100_Port;
        }
        if(is_app_for_fbo_data_only)
        {
            ver += " app_for_fbo_data_only";
            MysqlServer_Port = DEF_MysqlServerFBO_Port;
            Socket_Server_Port = DEF_Socket_ServerFBO_Port;
            Socket_Server_FBI_Port = DEF_Socket_Server_FBIFBO_Port;
            Socket_Server_IDCE8200_Port = DEF_Socket_Server_IDCE8200FBO_Port;
            Socket_Server_Mobile_Port = DEF_Socket_Server_MOBILEFBO_Port;
            FTP_Server_Port = DEF_FTP_ServerFBO_Port;
        }
        if(is_app_for_FBS9100S_only) {
            ver += " app_for_FBS9100S_only ";
            MysqlServer_Port = DEF_MysqlServerFBS9100S_Port;
            Socket_Server_Port = DEF_Socket_ServerFBS_Port;
            Socket_Server_FBI_Port = DEF_Socket_Server_FBIFBS_Port;
            Socket_Server_IDCE8200_Port = DEF_Socket_Server_IDCE8200FBS_Port;
            Socket_Server_Mobile_Port = DEF_Socket_Server_MOBILEFBS_Port;
            FTP_Server_Port = DEF_FTP_ServerFBS_Port;
        }
        //System.out.println(ver+"%%%%%%%%%%%%%");
        System.out.println("/****************************************************************");
        System.out.println("*****************************************************************");
        System.out.println("****************************************************************/");
        System.out.println(ver);
        System.out.println("Server Started At DateTime: " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
        //´´½¨config.xmlÎļþ
        m_AppConfig = new AppConfig();
        
        System.out.println("SQLserver IP£º" + m_AppConfig.getMysqlServerIp() + ", port: "+MysqlServer_Port);
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 
                                                m_AppConfig.getMysqlConnCountMax());
        
        /*
        //ÔÚÁ¬½Ó³ØÖлñÈ¡Á¬½Ó
        Sql_Mysql sql_ck = new Sql_Mysql(GB_MysqlConnPool.getConn());
        try {
            //´´½¨´ó¶àÊý¾Ý¿âÒÔ¼°Êý¾Ý¿âÖеıí¸ñ£¬²¢¸øÄ³Ð©±í¸ñÉèÖµ
            sql_ck.checkAndCreateDB();
        } catch (SQLException e1) {
            e1.printStackTrace();
        } f999+inally {
            sql_ck.close_con();
        }
        */
        
        //´´½¨tb_app_param±í,²¢ÇÒÉèÖñíÖеÄÊý¾Ý
        GB_App_Param = new AppParam(GB_MysqlConnPool);
        
        checkingMySQLServerStart();                //¼ì²âÊý¾Ý¿â·þÎñÊÇ·ñÆô¶¯
        /*********************************************************************************/
        /*********************************************************************************/
        Dev_UDPServer_Thread_SQL threadSql = new Dev_UDPServer_Thread_SQL();
        threadSql.initDB(GB_MysqlConnPool);        //³õʼ»¯Êý¾Ý¿â±í 
        
        //¹¹ÔìÉ豸Êý¾Ý
        List<Device_inf> devices = Device_inf.initDevice();
        
        ReadConfigFile readdata = new ReadConfigFile(m_AppConfig);
        
        //´Óftp·þÎñÆ÷½âÎöÅäÖÃÎļþ
        List<ConfigData> configs = readdata.readConfigData();
        
        
        List<ConfigData> SteamTurCfgs = new ArrayList<ConfigData>();
        //·ÖÎöÅäÖÃÎļþÖеÄÊý¾Ý
        readdata.analyConfigFile(configs,devices,SteamTurCfgs);
        
        
        //Ôݲ»¼Ç¼¸æ¾¯¼Ç¼
        //for (Device_inf device_inf : devices) {
        //    //System.out.println(device_inf);
        //    Dev_UDPServer_Thread_SQL.createDevAlarmDataTable(GB_MysqlConnPool, device_inf);
        //}
        
        threadSql.insertTb_device_inf(GB_MysqlConnPool,devices);
        
        threadSql.initRtDataCfgTable(GB_MysqlConnPool,devices);
//        for (ConfigData cfg : configs) {
//            System.out.println(cfg);
//        }
        System.out.println(configs.size());
        
        Dev_UDPServer_Thread_SQL.insertOrUpdateTb_DevData_RtTable(GB_MysqlConnPool,devices);
        /*******************************************************************/
        //UDP×ÓվͨѶ·þÎñÏß³Ì
        Dev_UDPServer_Thread udp_thread = new Dev_UDPServer_Thread(GB_MysqlConnPool,devices,configs,m_AppConfig);
        new Thread(udp_thread).start();
        
        
        //Äæ±äµçԴͨѶ·þÎñÏß³Ì
        InverterPowerUDPServer_Thread nibian_thread = new InverterPowerUDPServer_Thread(GB_MysqlConnPool,devices,m_AppConfig);
        new Thread(nibian_thread).start();
        
        
        //FTPÎļþ±¸·ÝÏß³Ì
        //FTPFileBackUp_Thread backup_thread = new FTPFileBackUp_Thread(m_AppConfig);
        //new Thread(backup_thread).start();
        
        
        //ÀúÊ·Êý¾ÝÑ­»·É¾³ýÏß³Ì
        HistoryData_RealDelete_Thread hist_thread = new HistoryData_RealDelete_Thread(GB_MysqlConnPool,m_AppConfig,devices);
        new Thread(hist_thread).start();
        
        //É豸ʱ¼äͬ²½Ïß³Ì
        Device_Timing_Thread time_thread = new Device_Timing_Thread();
        new Thread(time_thread).start();
        
        
        //ÆûÂÖ·¢µç»úÊý¾Ý½âÎö³ÌÐò
        SteamTurbineUDPServer_Thread steam_thread = new SteamTurbineUDPServer_Thread(GB_MysqlConnPool,devices,SteamTurCfgs,m_AppConfig);
        new Thread(steam_thread).start();
        /*******************************************************************/
        
        while(true) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        /*********************************************************************************/
    }
    
    public static void checkingMySQLServerStart(){
        //MysqlServer_Port = 3306;
        System.out.println("IP£º"+m_AppConfig.getMysqlServerIp()+"port"+MysqlServer_Port);            
        //³õʼ»¯Á¬½Ó³ØÖеĸ÷ÖÖ²ÎÊýÐÅÏ¢        m_AppConfig.getMysqlServerIp()
        GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port, 5);
        while(true){
            Connection conn = null;
            try {
                System.out.println(" ¿ªÊ¼¼ì²âÊý¾Ý¿âÁ¬½Ó "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
                conn =  GB_MysqlConnPool.getConn();
                if(conn != null){
                    System.out.println("¼ì²âÊý¾Ý¿âÁ¬½Ó³É¹¦");
                    break;
                }
            } catch (Exception e) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
                System.out.println(" MySQL_FBSDEV not Start ... ");
            } finally {
                if(conn != null) {
                    try {
                        conn.close();
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}