whyclj
2020-09-10 2993af45f257be3a1e76545f886bbe6a3b0bc9af
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package com.electrical.TwoKW;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
 
import com.sql.MysqlConnPool;
import com.sql.Sql_Mysql;
 
public class Electrical_2KWTask_SQL {
    
    /**
     * ³õʼ»¯Êý¾Ý¿â±í
     * @param pool
     */
    public static void init(MysqlConnPool pool) {
        createDB_Electric2MWSystem(pool);
        
        createTb_electric2MW_inf(pool);
        
        //initTb_electric2MW_inf(pool);
        
        createTb_electric2MW_rt(pool);
        
        createTb_electric2MW_control(pool);
        
        
        createTb_electric2MW_state(pool);
        
    }
    
    /**
     * ³õʼ»¯¸ºÔØÐÅÏ¢±í
     * @param pool
     */
    public static void initTb_electric2MW_inf(MysqlConnPool pool) {
        String sql_str= " replace INTO " + Sql_Mysql.Tb_electric2MW_inf + "(electric2KW_id,electric2KW_ip,electric2KW_name,electric2KW_type) VALUES(6001,'127.0.0.1','2MW','1'),(6002,'127.0.0.1','2MW','1')";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * ´´½¨2MWµçԴϵͳÊý¾Ý¿â
     * @param pool
     */
    public static void createDB_Electric2MWSystem(MysqlConnPool pool) {
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute("CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_Electric2MWSystem);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    /**
     * ´´½¨2MWÐÅÏ¢±í
     * @param pool
     */
    public static void createTb_electric2MW_inf(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_electric2MW_inf + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric2KW_id int(11) NOT NULL DEFAULT '5001' COMMENT 'µçÔ´id'," + 
                "  electric2KW_ip varchar(255) NOT NULL DEFAULT '127.0.0.1' COMMENT 'µçÔ´ip'," + 
                "  electric2KW_name varchar(255) NOT NULL DEFAULT 'A×é' COMMENT 'µçÔ´Ãû³Æ'," + 
                "  electric2KW_type int(11) NOT NULL DEFAULT '2' COMMENT 'µçÔ´ÀàÐÍ'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)," + 
                "  UNIQUE KEY electric2KW_id_key (electric2KW_id) USING BTREE  " + 
                ") 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();
        }
    }
    /**
     * ´´½¨2MWʵʱÐÅÏ¢±í
     * @param pool
     */
    public static void createTb_electric2MW_rt(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_electric2MW_rt + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric2KW_id int(11) NOT NULL DEFAULT '5001' COMMENT 'µçÔ´id'," + 
                "  upper_pulse_block int(11) NOT NULL DEFAULT '0' COMMENT 'ÉÏλ»úÂö³å·âËø'," + 
                "  consvolcurrstatus int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹºãÁ÷ģʽ״̬'," + 
                "  constantvolflag int(11) NOT NULL DEFAULT '0' COMMENT '4²¢»ò2´®2²¢ºãѹ±ê־λ'," + 
                "  main_circuit_connmode int(11) NOT NULL DEFAULT '0' COMMENT 'Ö÷µç·Á¬½Óģʽ'," + 
                "  remote_start int(11) NOT NULL DEFAULT '0' COMMENT 'Ô¶³ÌÆô¶¯'," + 
                "  fault_reset int(11) NOT NULL DEFAULT '0' COMMENT '¹ÊÕϸ´Î»'," + 
                "  conscurrswitch int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷Çл»'," + 
                "  constantvol float NOT NULL DEFAULT '0' COMMENT 'A»ú×é4²¢»ò2´®2²¢ºãѹ'," + 
                "  volset_confirm int(11) NOT NULL DEFAULT '0' COMMENT 'µçѹ¸ø¶¨È·ÈÏ'," + 
                "  currset_confirm int(11) NOT NULL DEFAULT '0' COMMENT 'µçÁ÷¸ø¶¨È·ÈÏ'," + 
                "  remote_stop int(11) NOT NULL DEFAULT '0' COMMENT 'Ô¶³ÌÍ£Ö¹'," + 
                "  start_screen_set int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯´¥ÃþÆÁ¸ø¶¨'," + 
                "  start_upper_set int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯ÉÏλ»ú¸ø¶¨'," + 
                "  consvolswitch int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹÇл»'," + 
                "  othermode int(11) NOT NULL DEFAULT '0' COMMENT '4²¢»ò2´®2²¢ÒÔÍâģʽ'," + 
                "  consvol_distribution int(11) NOT NULL DEFAULT '0' COMMENT 'ËÄ´®ºãѹµçѹ·ÖÅäλ'," + 
                "  local_remote_control int(11) NOT NULL DEFAULT '0' COMMENT '¾ÍµØÔ¶³Ì¿ØÖÆ×´Ì¬'," +
                
                "  pulse_blocking int(11) NOT NULL DEFAULT '0' COMMENT 'Âö³å·âËø'," + 
                
                "  curve_charge_mode int(11) NOT NULL DEFAULT '0' COMMENT 'ÇúÏß³äµçģʽ״̬'," + 
                "  start_curve_charge_mode int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯ÇúÏß³äµçģʽ'," + 
                "  stop_curve_charge_mode int(11) NOT NULL DEFAULT '0' COMMENT 'Í£Ö¹ÇúÏß³äµçģʽ'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num)," + 
                "  UNIQUE KEY electric2KW_id_key (electric2KW_id) USING BTREE  " + 
                ") 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();
        }
    }
    
    /**
     * ´´½¨2MWʵʱÐÅϢ״̬±í
     * @param pool
     */
    public static void createTb_electric2MW_state(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_electric2MW_state + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  electric2KW_id int(11) NOT NULL," + 
                "  brachdcvol float NOT NULL DEFAULT '0' COMMENT '·ÖÖ±Á÷µçѹ'," + 
                "  brachdccurr float NOT NULL DEFAULT '0' COMMENT '·ÖÖ±Á÷µçÁ÷'," + 
                "  alldcvol float NOT NULL DEFAULT '0' COMMENT '×ÜÖ±Á÷µçѹ'," + 
                "  alldccurr float NOT NULL DEFAULT '0' COMMENT '×ÜÖ±Á÷µçÁ÷'," + 
                "  stopchargevol_one float NOT NULL DEFAULT '0' COMMENT 'µÚ1½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_two float NOT NULL DEFAULT '0' COMMENT 'µÚ2½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_three float NOT NULL DEFAULT '0' COMMENT 'µÚ3½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_four float NOT NULL DEFAULT '0' COMMENT 'µÚ4½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_five float NOT NULL DEFAULT '0' COMMENT 'µÚ5½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  controlangle float NOT NULL DEFAULT '0' COMMENT '¿ØÖƽÇ'," + 
                "  localgivevol float NOT NULL DEFAULT '0' COMMENT 'µ±Ç°¸ø¶¨µçѹ'," + 
                "  volset float NOT NULL DEFAULT '0' COMMENT 'µçѹÉ趨ֵ'," + 
                "  localgivecurr float NOT NULL DEFAULT '0' COMMENT 'µ±Ç°¸ø¶¨µçÁ÷'," + 
                "  currset float NOT NULL DEFAULT '0' COMMENT 'µçÁ÷É趨ֵ'," + 
                "  chargecurr_one float NOT NULL DEFAULT '0' COMMENT 'µÚ1½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_two float NOT NULL DEFAULT '0' COMMENT 'µÚ2½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_three float NOT NULL DEFAULT '0' COMMENT 'µÚ3½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_four float NOT NULL DEFAULT '0' COMMENT 'µÚ4½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_five float NOT NULL DEFAULT '0' COMMENT 'µÚ5½×¶Î³äµçµçÁ÷Öµ'," + 
                "  consvolmode_chargecurr float NOT NULL DEFAULT '0' COMMENT 'תΪºãѹģʽ³äµçµçѹֵ'," + 
                "  note varchar(255) NOT NULL DEFAULT '' COMMENT '±¸ÓÃ'," + 
                "  PRIMARY KEY (num)," + 
                "  KEY index_electric2KW_id (electric2KW_id) USING BTREE" + 
                ") 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();
        }
    }
    
    
    
    
    /**
     * ´´½¨2MW¿ØÖÆÐÅÏ¢±í
     * @param pool
     */
    public static void createTb_electric2MW_control(MysqlConnPool pool) {
        String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_electric2MW_control + " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric2KW_id int(11) NOT NULL DEFAULT '5001' COMMENT 'µçÔ´id'," + 
                "  consvolmode_chargecurr float NOT NULL DEFAULT '0' COMMENT 'תΪºãѹģʽ³äµçµçѹֵ'," + 
                "  chargecurr_five float NOT NULL DEFAULT '0' COMMENT 'µÚ5½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_four float NOT NULL DEFAULT '0' COMMENT 'µÚ4½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_three float NOT NULL DEFAULT '0' COMMENT 'µÚ3½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_two float NOT NULL DEFAULT '0' COMMENT 'µÚ2½×¶Î³äµçµçÁ÷Öµ'," + 
                "  chargecurr_one float NOT NULL DEFAULT '0' COMMENT 'µÚ1½×¶Î³äµçµçÁ÷Öµ'," + 
                "  currset float NOT NULL DEFAULT '0' COMMENT 'µçÁ÷É趨ֵ'," + 
                "  volset float NOT NULL DEFAULT '0' COMMENT 'µçѹÉ趨ֵ'," + 
                "  stopchargevol_five float NOT NULL DEFAULT '0' COMMENT 'µÚ5½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_four float NOT NULL DEFAULT '0' COMMENT 'µÚ4½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_three float NOT NULL DEFAULT '0' COMMENT 'µÚ3½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_two float NOT NULL DEFAULT '0' COMMENT 'µÚ2½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  stopchargevol_one float NOT NULL DEFAULT '0' COMMENT 'µÚ1½×¶Î³äµçÖÕÖ¹µçѹ'," + 
                "  upper_pulse_block int(11) NOT NULL DEFAULT '0' COMMENT 'ÉÏλ»úÂö³å·âËø'," + 
                "  remote_start int(11) NOT NULL DEFAULT '0' COMMENT 'Ô¶³ÌÆô¶¯'," + 
                "  fault_reset int(11) NOT NULL DEFAULT '0' COMMENT '¹ÊÕϸ´Î»'," + 
                "  conscurrswitch int(11) NOT NULL DEFAULT '0' COMMENT 'ºãÁ÷Çл»'," + 
                "  constantvol int(11) NOT NULL DEFAULT '0' COMMENT '4²¢»ò2´®2²¢ºãѹ'," + 
                "  volset_confirm int(11) NOT NULL DEFAULT '0' COMMENT 'µçѹ¸ø¶¨È·ÈÏ'," + 
                "  currset_confirm int(11) NOT NULL DEFAULT '0' COMMENT 'µçÁ÷¸ø¶¨È·ÈÏ'," + 
                "  remote_stop int(11) NOT NULL DEFAULT '0' COMMENT 'Ô¶³ÌÍ£Ö¹'," + 
                "  start_screen_set int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯´¥ÃþÆÁ¸ø¶¨'," + 
                "  start_upper_set int(11) NOT NULL DEFAULT '0' COMMENT 'Æô¶¯ÉÏλ»ú¸ø¶¨'," + 
                "  consvolswitch int(11) NOT NULL DEFAULT '0' COMMENT 'ºãѹÇл»'," + 
                "  othermode int(11) NOT NULL," + 
                "  consvol_distribution int(11) NOT NULL DEFAULT '0' COMMENT 'ËÄ´®ºãѹµçѹ·ÖÅäλ'," + 
                "  PRIMARY KEY (num)," + 
                "  UNIQUE KEY electric2KW_id_key (electric2KW_id) USING BTREE" + 
                ") 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();
        }
    }
 
    /**
     * ²éѯËùÓеÄ2mwµçԴϵͳ
     * @param pool
     * @param electric
     */
    public static void queryAllElectrical2MW(MysqlConnPool pool,List<Electric_inf_2kw> einfs) {
        String sql_str = " select * from " + Sql_Mysql.Tb_electric2MW_inf+ " order by electric2KW_id asc ";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str);
            while(res.next()) {
                Electric_inf_2kw einf=new Electric_inf_2kw();
                einf.setElectric2KW_id(res.getInt("electric2kw_id"));
                einf.setElectric2KW_ip(res.getString("electric2kw_ip"));
                einf.setElectric2KW_name(res.getString("electric2kw_name"));
                einf.setElectric2KW_type(res.getInt("electric2kw_type"));
                einfs.add(einf);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    
    //²åÈë»ò¸üÐÂ2mwµçԴϵͳʵʱÐÅÏ¢±í
    public static void replace_electric2MW_rt(MysqlConnPool pool,Electric_Rt_2kw ert) {
        String sql_str = " replace into "+ Sql_Mysql.Tb_electric2MW_rt+"(electric2KW_id)  "
                + "  values("+ert.electric2KW_id+")";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    //²åÈë»ò¸üÐÂ2mwµçԴϵͳÐÅÏ¢±í
    public static void replace_electric2MW_inf(MysqlConnPool pool,Electric_inf_2kw einf) {
        String sql_str = " replace into "+ Sql_Mysql.Tb_electric2MW_inf+"(electric2KW_id)  "
                + "  values("+einf.electric2KW_id+")";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    //²åÈë»ò¸üÐÂ2mwµçÔ´¿ØÖÆÐÅÏ¢±í
    public static void replace_electric2MW_Control(MysqlConnPool pool,Electric_Control_Single_2kw econtrol) {
        String sql_str = " replace into "+ Sql_Mysql.Tb_electric2MW_control+"(electric2KW_id)  "
                + "  values("+econtrol.electric2KW_id+")";
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
 
    //¸üÐÂ2mwµçԴʵʱÐÅÏ¢±í
    public static void update_Electric_Rt_2KW(MysqlConnPool pool,Electric_Rt_2kw ert) {
        String sql_str = " UPDATE "+ Sql_Mysql.Tb_electric2MW_rt  +""
                + " SET upper_pulse_block = "+ert.upper_pulse_block+","
                + " consvolcurrstatus = "+ert.consvolcurrstatus+","
                + " constantvolflag = "+ert.constantvolflag+","
                + " main_circuit_connmode = "+ert.main_circuit_connmode+","
                + " remote_start = "+ert.remote_start+","
                + " fault_reset = "+ert.fault_reset+","
                + " conscurrswitch = "+ert.conscurrswitch+","
                + " constantvol = "+ert.constantvol+","
                + " volset_confirm = "+ert.volset_confirm+","
                + " currset_confirm = "+ert.currset_confirm+","
                + " remote_stop = "+ert.remote_stop+","
                + " start_screen_set = "+ert.start_screen_set+","
                + " start_upper_set = "+ert.start_upper_set+","
                + " consvolswitch = "+ert.consvolswitch+","
                + " othermode = "+ert.othermode+","
                + " consvol_distribution = "+ert.consvol_distribution+","
                + " local_remote_control = "+ert.local_remote_control+","
                + " curve_charge_mode = "+ert.curve_charge_mode+","
                + " start_curve_charge_mode = "+ert.start_curve_charge_mode+","
                + " stop_curve_charge_mode = "+ert.stop_curve_charge_mode+" "
                + " WHERE electric2KW_id = " + ert.electric2KW_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    //¸üÐÂ2mwµçÔ´¿ØÖÆÐÅÏ¢±í
    public static void update_Electric_Control_2KW(MysqlConnPool pool,Electric_Control_Single_2kw econ) {
        String sql_str = " UPDATE "+ Sql_Mysql.Tb_electric2MW_control  +""
                + " SET consvolmode_chargecurr = "+econ.consvolmode_chargecurr+","
                + " chargecurr_five = "+econ.chargecurr_five+","
                + " chargecurr_four = "+econ.chargecurr_four+","
                + " chargecurr_three = "+econ.chargecurr_three+","
                + " chargecurr_two = "+econ.chargecurr_two+","
                + " chargecurr_one = "+econ.chargecurr_one+","
                + " currset = "+econ.currset+","
                + " volset = "+econ.volset+","
                + " stopchargevol_five = "+econ.stopchargevol_five+","
                + " stopchargevol_four = "+econ.stopchargevol_four+","
                + " stopchargevol_three = "+econ.stopchargevol_three+","
                + " stopchargevol_two = "+econ.stopchargevol_two+","
                + " stopchargevol_one = "+econ.stopchargevol_one+" "
                + " WHERE electric2KW_id = " + econ.electric2KW_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
}