whyclj
2020-08-11 5163e499c41b6e8567fcfd690e7a9140c8f8277f
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package com.electrical.FourKW;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class Electrical_Task_SQL {
    
    
    
    /**
     * ²éѯËùÓеÄÉ豸¼Ç¼
     * @param pool
     * @param electric
     */
    public static void queryAllElectric(MysqlConnPool pool,List<Electric_inf> electrics) {
        String sql_str = " select * from " + Sql_Mysql.Tb_Electric_Inf + " order by electric_id;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str);
            Electric_inf elect = null;
            while(res.next()) {
                elect = new Electric_inf(res.getInt("electric_id"));
                elect.setElectric_name(res.getString("electric_name"));
                elect.setElectric_type(res.getInt("electric_type"));
                elect.setElectric_ip(res.getString("electric_ip"));
                electrics.add(elect);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    
    /**
     * ³õʼ»¯Êý¾Ý¿â±í
     * @param pool
     */
    public static void init(MysqlConnPool pool) {
        
        createDB_ElectricSystem(pool);
        
        createTb_Electric_inf(pool);
        
        createTb_Electric_Switch(pool);
        
        createTb_Electric_State(pool);
        
        createTb_Electric_State(pool);
        
        createTb_Electric_Rt(pool);
        
        createTb_Electric_Power(pool);
        
        createTb_Electric_Control_Single(pool);
        
    }
    
    
    
    
    /**
     * ´´½¨4KWµçÔ´Êý¾Ý¿â
     * @param pool
     */
    public static void createDB_ElectricSystem(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_ElectricSystem);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
    
    
    
    /**
     * ´´½¨µçÔ´ÐÅÏ¢±í
     * @param pool
     */
    public static void createTb_Electric_inf(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Electric_Inf+" (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric_id int(11) NOT NULL DEFAULT '3001' COMMENT 'É豸id'," + 
                "  electric_name varchar(255) NOT NULL DEFAULT '' COMMENT 'µçÔ´Ãû³Æ'," + 
                "  electric_type int(11) NOT NULL DEFAULT '0' COMMENT 'µçÔ´ÀàÐÍ(±¸ÓÃ)'," + 
                "  electric_ip varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT 'µçÔ´É豸ip(ÖØÒª)'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)," + 
                "  KEY electric_id_key (electric_id)" + 
                ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     * ´´½¨µçÔ´×Ü¿ª¹Ø×´Ì¬±í
     * @param pool
     */
    public static void createTb_Electric_Switch(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_Switch + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  km1_switchon_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM1ºÏÕ¢Ö¸Áî'," + 
                "  km1_switchoff_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM1·ÖÕ¢Ö¸Áî'," + 
                "  km2_switchon_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM2ºÏÕ¢Ö¸Áî'," + 
                "  km2_switchoff_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM2·ÖÕ¢Ö¸Áî'," + 
                "  km3_switchon_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM3ºÏÕ¢Ö¸Áî'," + 
                "  km3_switchoff_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM3·ÖÕ¢Ö¸Áî'," + 
                "  km4_switchon_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM4ºÏÕ¢Ö¸Áî'," + 
                "  km4_switchoff_one int(11) NOT NULL DEFAULT '0' COMMENT 'Ò»ºÅת»»¿ª¹Ø¹ñKM4·ÖÕ¢Ö¸Áî'," + 
                "  km1_switchon_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM1ºÏÕ¢Ö¸Áî'," + 
                "  km1_switchoff_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM1·ÖÕ¢Ö¸Áî'," + 
                "  km2_switchon_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM2ºÏÕ¢Ö¸Áî'," + 
                "  km2_switchoff_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM2·ÖÕ¢Ö¸Áî'," + 
                "  km3_switchon_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM3ºÏÕ¢Ö¸Áî'," + 
                "  km3_switchoff_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM3·ÖÕ¢Ö¸Áî'," + 
                "  km4_switchon_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM4ºÏÕ¢Ö¸Áî'," + 
                "  km4_switchoff_two int(11) NOT NULL DEFAULT '0' COMMENT '¶þºÅת»»¿ª¹Ø¹ñKM4·ÖÕ¢Ö¸Áî'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     * ´´½¨µçԴ״̬±í
     * @param pool
     */
    public static void createTb_Electric_State(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_State + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric_id int(11) NOT NULL DEFAULT '3001' COMMENT 'É豸id'," + 
                "  case_trip_output int(11) NOT NULL DEFAULT '0' COMMENT '»úÏäÌøÕ¢Êä³ö'," + 
                "  fault_reset_signal int(11) NOT NULL DEFAULT '0' COMMENT '¹ÊÕϸ´Î»ÐźÅ'," + 
                "  high_vol_switch_status int(11) NOT NULL DEFAULT '0' COMMENT '¸ßѹ¿ª¹Ø×´Ì¬'," + 
                "  stop_button int(11) NOT NULL DEFAULT '0' COMMENT '¼±Í£°´Å¥'," + 
                "  main_cabinet_fan_status int(11) NOT NULL DEFAULT '0' COMMENT 'Ö÷¹ñ·ç»ú״̬'," + 
                "  trans_cabinet_door_lock int(11) NOT NULL DEFAULT '0' COMMENT '±äѹÆ÷¹ñÃÅÁ¬Ëø'," + 
                "  trans_cabinet_overtem_alarm int(11) NOT NULL DEFAULT '0' COMMENT '±äѹÆ÷³¬Î±¨¾¯'," + 
                "  trans_cabinet_overtem_trip int(11) NOT NULL DEFAULT '0' COMMENT '±äѹÆ÷³¬ÎÂÌøÕ¢'," + 
                "  qs1_state int(11) NOT NULL DEFAULT '0' COMMENT 'QS1״̬'," + 
                "  qs2_state int(11) NOT NULL DEFAULT '0' COMMENT 'QS2״̬'," + 
                "  switch_cabinet_door_status int(11) NOT NULL DEFAULT '0' COMMENT 'ת»»¿ª¹Ø¹ñÃÅ״̬'," + 
                "  alldcvol float NOT NULL DEFAULT '0' COMMENT '×ÜÖ±Á÷µçѹ'," + 
                "  alldccurr float NOT NULL DEFAULT '0' COMMENT '×ÜÖ±Á÷µçÁ÷'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)," + 
                "  KEY electric_id_key (electric_id)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     * ´´½¨µçԴ״̬±í
     * @param pool
     */
    public static void createTb_Electric_Rt(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_Rt + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric_id int(11) NOT NULL DEFAULT '3001' COMMENT 'É豸id'," + 
                "  upsetcurr float NOT NULL DEFAULT '0' COMMENT 'ÉÏλ»úÉ趨µçÁ÷'," + 
                "  upsetvol float NOT NULL DEFAULT '0' COMMENT 'ÉÏλ»úÉ趨µçѹ'," + 
                "  convolcontrol int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ¿ØÖÆ'," + 
                "  concurrcontrol int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷¿ØÖÆ'," + 
                "  othermodes int(11) NOT NULL DEFAULT '0' COMMENT 'ÆäËûģʽÔËÐÐ'," + 
                "  parallelmodes int(11) NOT NULL DEFAULT '0' COMMENT '²¢ÁªÎÈѹÔËÐÐ'," + 
                "  startposition int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯Î»'," + 
                "  stopposition int(11) NOT NULL DEFAULT '0' COMMENT 'ֹͣλ'," + 
                "  resetposition int(11) NOT NULL DEFAULT '0' COMMENT '¸´Î»'," + 
                "  fanstart int(11) NOT NULL DEFAULT '0' COMMENT '·ç»úÆô¶¯'," + 
                "  fanstop int(11) NOT NULL DEFAULT '0' COMMENT '·ç»úÍ£Ö¹'," + 
                "  dcvol float NOT NULL DEFAULT '0' COMMENT 'Ö±Á÷µçѹ '," + 
                "  dccurr float NOT NULL DEFAULT '0' COMMENT 'Ö±Á÷µçÁ÷'," + 
                "  controlangle int(11) NOT NULL DEFAULT '0' COMMENT '¿ØÖƽÇ'," + 
                "  loopflag int(11) NOT NULL DEFAULT '0' COMMENT '¿ª±Õ»·±ê־루0¿ª»·£¬1±Õ»·£©'," + 
                "  remoteflag int(11) NOT NULL DEFAULT '0' COMMENT '¾ÍµØÔ¶³Ì±ê־루0Ô¶³Ì£¬1¾ÍµØ£©'," + 
                "  orderflag int(11) NOT NULL DEFAULT '0' COMMENT 'ÕýÐòÄæÐò±ê־루0ÕýÐò£¬1ÄæÐò£©'," + 
                "  consvolcurrflag int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹºãÁ÷±ê־루0ºãѹ£¬1ºãÁ÷£©'," + 
                "  powerstartflag int(11) NOT NULL DEFAULT '0' COMMENT 'µçÔ´Æô¶¯±ê־루0Í£Ö¹£¬1Æô¶¯£© '," + 
                "  workmodelflag int(11) NOT NULL DEFAULT '0' COMMENT '¹¤×÷ģʽ±ê־루0ÆäËûģʽ£¬1²¢ÁªÎÈѹ£©'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)," + 
                "  KEY electric_id_key (electric_id)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    
    /**
     * ´´½¨µçÔ´¿ØÖÆ×´Ì¬±í
     * @param pool
     */
    public static void createTb_Electric_Power(MysqlConnPool pool) {
        String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_Power + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  start_a int(11) NOT NULL DEFAULT '0' COMMENT 'AÌׯô¶¯'," + 
                "  stop_a int(11) NOT NULL DEFAULT '0' COMMENT 'AÌ×Í£Ö¹'," + 
                "  start_b int(11) NOT NULL DEFAULT '0' COMMENT 'BÌׯô¶¯'," + 
                "  stop_b int(11) NOT NULL DEFAULT '0' COMMENT 'BÌ×Í£Ö¹'," + 
                "  start_c int(11) NOT NULL DEFAULT '0' COMMENT 'CÌׯô¶¯'," + 
                "  stop_c int(11) NOT NULL DEFAULT '0' COMMENT 'CÌ×Í£Ö¹'," + 
                "  start_d int(11) NOT NULL DEFAULT '0' COMMENT 'DÌׯô¶¯'," + 
                "  stop_d int(11) NOT NULL DEFAULT '0' COMMENT 'DÌ×Í£Ö¹'," + 
                "  abconn_start int(11) NOT NULL DEFAULT '0' COMMENT 'AÌ×BÌײ¢ÁªÔËÐÐÆô¶¯'," + 
                "  abconn_stop int(11) NOT NULL DEFAULT '0' COMMENT 'AÌ×BÌײ¢ÁªÔËÐÐÍ£Ö¹'," + 
                "  cdconn_start int(11) NOT NULL DEFAULT '0' COMMENT 'CÌ×DÌײ¢ÁªÔËÐÐÆô¶¯'," + 
                "  cdconn_stop int(11) NOT NULL DEFAULT '0' COMMENT 'CÌ×DÌײ¢ÁªÔËÐÐÍ£Ö¹'," + 
                "  allconn_start int(11) NOT NULL DEFAULT '0' COMMENT 'ËÄÌײ¢ÁªÔËÐÐÆô¶¯'," + 
                "  allconn_stop int(11) NOT NULL DEFAULT '0' COMMENT 'ËÄÌײ¢ÁªÔËÐÐÍ£Ö¹'," + 
                "  abconn_flag int(11) NOT NULL DEFAULT '0' COMMENT 'AB²¢´®Áª±ê־λ'," + 
                "  cdconn_flag int(11) NOT NULL DEFAULT '0' COMMENT 'CD²¢´®Áª±ê־λ'," + 
                "  abconn_volset int(11) NOT NULL DEFAULT '0' COMMENT 'AB²¢Áªµçѹ¸ø¶¨'," + 
                "  abconn_currset int(11) NOT NULL DEFAULT '0' COMMENT 'AB²¢ÁªµçÁ÷¸ø¶¨'," + 
                "  cdconn_volset int(11) NOT NULL DEFAULT '0' COMMENT 'CD²¢Áªµçѹ¸ø¶¨'," + 
                "  cdconn_currset int(11) NOT NULL DEFAULT '0' COMMENT 'CD²¢ÁªµçÁ÷¸ø¶¨'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     * ´´½¨µçÔ´¿ØÖÆ×´Ì¬±í
     * @param pool
     */
    public static void createTb_Electric_Control_Single(MysqlConnPool pool) {
        String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_Control_Single + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric_id int(11) NOT NULL DEFAULT '3001' COMMENT 'µçÔ´id'," + 
                "  upsetcurr float NOT NULL DEFAULT '0' COMMENT 'ÉÏλ»úÉ趨µçÁ÷'," + 
                "  upsetvol float NOT NULL DEFAULT '0' COMMENT 'ÉÏλ»úÉ趨µçѹ'," + 
                "  convolcontrol int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹ¿ØÖÆ'," + 
                "  concurrcontrol int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷¿ØÖÆ'," + 
                "  othermodes int(11) NOT NULL DEFAULT '0' COMMENT 'ÆäËûģʽÔËÐÐ'," + 
                "  parallelmodes int(11) NOT NULL DEFAULT '0' COMMENT '²¢ÁªÎÈѹÔËÐÐ'," + 
                "  startposition int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯Î»'," + 
                "  stopposition int(11) NOT NULL DEFAULT '0' COMMENT 'ֹͣλ'," + 
                "  resetposition int(11) NOT NULL DEFAULT '0' COMMENT '¸´Î»'," + 
                "  fanstart int(11) NOT NULL DEFAULT '0' COMMENT '·ç»úÆô¶¯'," + 
                "  fanstop int(11) NOT NULL DEFAULT '0' COMMENT '·ç»úÍ£Ö¹'," + 
                "  dcvol float NOT NULL DEFAULT '0' COMMENT 'Ö±Á÷µçѹ'," + 
                "  dccurr float NOT NULL DEFAULT '0' COMMENT 'Ö±Á÷µçÁ÷'," + 
                "  controlangle float NOT NULL DEFAULT '0' COMMENT '¿ØÖƽÇ'," + 
                "  PRIMARY KEY (num)" + 
                ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}