whyclxw
2020-09-21 c5fb5d154c7db16424c28d02d22214a6444548a6
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
package com.electrical.TwoKW;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
 
import com.base.Com;
import com.modbus.data.MyModbusMaster;
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);
        
        createTb_Device_ConnectState(pool);
        
        createTb_Electric_Alarm(pool);
        
        createTb_Electric_Alarm_History(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 'Âö³å·âËø'," + 
                "  dc_voltage_state 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)," + 
                "  UNIQUE 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 DEFAULT '0' COMMENT '4²¢»ò2´®2²¢ÒÔÍâģʽ'," + 
                "  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();
        }
    }
    
    /**
     * ´´½¨É豸Á¬½Ó״̬±í
     * @param pool
     */
    private static void createTb_Device_ConnectState(MysqlConnPool pool) {
        String sql_str = " CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Device_ConnectState+" (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT," + 
                "  dev_id int(11) NOT NULL DEFAULT '0' COMMENT 'É豸id'," + 
                "  connect_en int(11) NOT NULL DEFAULT '0' COMMENT 'Á¬½Ó״̬[0:ͨѶ¹ÊÕÏ£»1ͨѶÕý³£]'," + 
                "  record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¼Ç¼ʱ¼ä'," + 
                "  note varchar(255) NOT NULL DEFAULT '' COMMENT '±¸ÓÃ×Ö¶Î'," + 
                "  PRIMARY KEY (num)," + 
                "  UNIQUE KEY index_dev_id (dev_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_state(MysqlConnPool pool,Electric_State_2kw state) {
        String sql_str = " replace into "+ Sql_Mysql.Tb_electric2MW_state+"(electric2KW_id)  "
                + "  values("+state.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+","
                
                + " pulse_blocking = "+ert.pulse_blocking+","                //Âö³å·âËø
                + " dc_voltage_state = "+ert.dc_voltage_state+","            //¸ßѹ¿ª¹Ø×´Ì¬
                
                + " 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();
        }
    }
    
    /* ´´½¨µçÔ´¹ÊÕϱí
     * @param pool
     */
    public static void createTb_Electric_Alarm(MysqlConnPool pool) {
        String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_2MW_alarm+ " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric_id int(11) NOT NULL DEFAULT '4001' COMMENT 'É豸id'," + 
                "  alarm_id int(11) NOT NULL DEFAULT '10001' COMMENT '¸æ¾¯id'," + 
                "  alarm_starttime datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¸æ¾¯¿ªÊ¼Ê±¼ä'," + 
                "  alarm_endtime datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¸æ¾¯½áÊøÊ±¼ä'," + 
                "  alarm_confirm int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯È·ÈÏ'," + 
                "  alarm_confirmtime datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¸æ¾¯È·ÈÏʱ¼ä'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num),"+
                "  index  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_Alarm_History(MysqlConnPool pool) {
        String sql_str = " CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Tb_Electric_2MW_alarm_history+ " (" + 
                "  num bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Ö÷¼ü'," + 
                "  electric_id int(11) NOT NULL DEFAULT '4001' COMMENT 'É豸id'," + 
                "  alarm_id int(11) NOT NULL DEFAULT '10001' COMMENT '¸æ¾¯id'," + 
                "  alarm_starttime datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¸æ¾¯¿ªÊ¼Ê±¼ä'," + 
                "  alarm_endtime datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¸æ¾¯½áÊøÊ±¼ä'," + 
                "  alarm_confirm int(11) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯È·ÈÏ'," + 
                "  alarm_confirmtime datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '¸æ¾¯È·ÈÏʱ¼ä'," + 
                "  note varchar(255) NOT NULL DEFAULT ''," + 
                "  PRIMARY KEY (num),"+
                "  index  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();
        }
    }
    
    
    //¸üÐÂ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+","
                
                + " upper_pulse_block = "+econ.upper_pulse_block+","
                + " remote_start = "+econ.remote_start+","
                + " fault_reset = "+econ.fault_reset+","
                + " conscurrswitch = "+econ.conscurrswitch+","
                + " constantvol = "+econ.constantvol+","
                + " volset_confirm = "+econ.chargecurr_five+","
                + " currset_confirm = "+econ.currset_confirm+","
                + " remote_stop = "+econ.remote_stop+","
                + " start_screen_set = "+econ.start_screen_set+","
                + " start_upper_set = "+econ.start_upper_set+","
                + " consvolswitch = "+econ.consvolswitch+","
                + " othermode = "+econ.othermode+","
                + " consvol_distribution = "+econ.consvol_distribution+","
 
                + " 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();
        }
    }
 
    /**
     * ¸üÐÂÄ£ÄâÁ¿×´Ì¬±í
     * @param conn_pool
     * @param state
     */
    public static void update_Electric_State_2KW(MysqlConnPool conn_pool, Electric_State_2kw state) {
        String sql_str = " UPDATE "+Sql_Mysql.Tb_electric2MW_state +
                " Set brachdcvol= " + state.brachdcvol +
                ",brachdccurr=" + state.brachdccurr +
                ",alldcvol=" + state.alldcvol +
                ",alldccurr=" + state.alldccurr +
                ",stopchargevol_one=" + state.stopchargevol_one +
                ",stopchargevol_two=" + state.stopchargevol_two +
                ",stopchargevol_three=" + state.stopchargevol_three + 
                ",stopchargevol_four=" + state.stopchargevol_four +
                ",stopchargevol_five=" + state.stopchargevol_five +
                ",controlangle=" + state.controlangle +
                ",localgivevol=" + state.localgivevol +
                ",volset=" + state.volset +
                ",localgivecurr=" + state.localgivecurr +
                ",currset=" + state.currset +
                ",chargecurr_one=" + state.chargecurr_one +
                ",chargecurr_two=" + state.chargecurr_two +
                ",chargecurr_three=" + state.chargecurr_three +
                ",chargecurr_four=" + state.chargecurr_four +
                ",chargecurr_five=" + state.chargecurr_five +
                ",consvolmode_chargecurr=" +state.consvolmode_chargecurr+ 
                " Where electric2KW_id = " + state.electric2KW_id;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *    ²éѯµ¥µã¿ØÖƱí
     * @param conn_pool
     * @param control
     */
    public static void queryElectric_Control_2KW(MysqlConnPool conn_pool,Electric_Control_Single_2kw control) {
        String sql_str = "SELECT * FROM "+Sql_Mysql.Tb_electric2MW_control+" Where electric2KW_id = " + control.electric2KW_id;
        ResultSet res = null;
        Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
        try {
            //System.out.println(sql_str);
            res = sql.sqlMysqlQuery(sql_str);
            if(res.next()) {
                control.setUpper_pulse_block(res.getInt("upper_pulse_block"));                //ÉÏλ»úÂö³å·âËø
                control.setRemote_start(res.getInt("remote_start"));                            //Ô¶³ÌÆô¶¯
                control.setFault_reset(res.getInt("fault_reset"));                            //¹ÊÕϸ´Î»
                control.setConscurrswitch(res.getInt("conscurrswitch"));                        //ºãÁ÷Çл»
                control.setConstantvol(res.getInt("constantvol"));                            //4²¢»ò2´®2²¢ºãѹ
                control.setVolset_confirm(res.getInt("volset_confirm"));                        //µçѹ¸ø¶¨È·ÈÏ
                control.setCurrset_confirm(res.getInt("currset_confirm"));                        //µçÁ÷¸ø¶¨È·ÈÏ
                control.setRemote_stop(res.getInt("remote_stop"));                            //Ô¶³ÌÍ£Ö¹
                control.setStart_screen_set(res.getInt("start_screen_set"));;                    //Æô¶¯´¥ÃþÆÁ¸ø¶¨
                control.setStart_upper_set(res.getInt("start_upper_set"));;                        //Æô¶¯ÉÏλ»ú¸ø¶¨
                control.setConsvolswitch( res.getInt("consvolswitch"));;                            //ºãѹÇл»
                control.setOthermode(res.getInt("othermode"));;                                    //4²¢»ò2´®2²¢ÒÔÍâģʽ
                control.setConsvol_distribution(res.getInt("consvol_distribution"));;            //ËÄ´®ºãѹµçѹ·ÖÅäλ
              
                control.setConsvolmode_chargecurr(res.getFloat("consvolmode_chargecurr")); ;    // 'תΪºãѹģʽ³äµçµçѹֵ',
                control.setChargecurr_one(res.getFloat("chargecurr_one")); ;                    // 'µÚ1½×¶Î³äµçµçÁ÷Öµ',
                control.setChargecurr_two(res.getFloat("chargecurr_two")); ;                    // 'µÚ2½×¶Î³äµçµçÁ÷Öµ',
                control.setChargecurr_three(res.getFloat("chargecurr_three")); ;                // 'µÚ3½×¶Î³äµçµçÁ÷Öµ',
                control.setChargecurr_four(res.getFloat("chargecurr_four")); ;                    // 'µÚ4½×¶Î³äµçµçÁ÷Öµ',
                control.setChargecurr_five(res.getFloat("chargecurr_five")); ;                    // 'µÚ5½×¶Î³äµçµçÁ÷Öµ',
                control.setCurrset(res.getFloat("currset")); ;                                    // 'µçÁ÷É趨ֵ',
             
                control.setVolset(res.getFloat("volset")); ;                                    // 'µçѹÉ趨ֵ',
                control.setStopchargevol_one(res.getFloat("stopchargevol_one")); ;                // 'µÚ1½×¶Î³äµçÖÕÖ¹µçѹ',
                control.setStopchargevol_two(res.getFloat("stopchargevol_two")); ;                // 'µÚ2½×¶Î³äµçÖÕÖ¹µçѹ',
                control.setStopchargevol_three( res.getFloat("stopchargevol_three")); ;            // 'µÚ3½×¶Î³äµçÖÕÖ¹µçѹ',
                control.setStopchargevol_four(res.getFloat("stopchargevol_four")); ;            // 'µÚ4½×¶Î³äµçÖÕÖ¹µçѹ',
                control.setStopchargevol_five(res.getFloat("stopchargevol_five")); ;            // 'µÚ5½×¶Î³äµçÖÕÖ¹µçѹ',
                //System.err.println(control);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            sql.close_con();
        }
    }
    
    /**
     * ¸üе±Ç°×´Ì¬±í
     * @param pool
     * @param control
     */
    public static void updateElectrical_2KW_Control(MysqlConnPool pool,Electric_Control_Single_2kw control) {
        String sql_str = " update " + Sql_Mysql.Tb_electric2MW_control + 
                " Set consvolmode_chargecurr=" + control.consvolmode_chargecurr +
                ",chargecurr_five=" + control.chargecurr_five +
                ",chargecurr_four=" + control.chargecurr_four +
                ",chargecurr_three=" + control.chargecurr_three +
                ",chargecurr_two=" + control.chargecurr_two +
                ",chargecurr_one=" + control.chargecurr_one +
                ",currset=" + control.currset +
                ",volset=" + control.volset +
                ",stopchargevol_five=" + control.stopchargevol_five +
                ",stopchargevol_four=" + control.stopchargevol_four +
                ",stopchargevol_three=" + control.stopchargevol_three +
                ",stopchargevol_two=" + control.stopchargevol_two +
                ",stopchargevol_one=" + control.stopchargevol_one +
                ",upper_pulse_block=" + control.upper_pulse_block +
                ",remote_start=" + control.remote_start +
                ",fault_reset=" + control.fault_reset +
                ",conscurrswitch=" + control.conscurrswitch +
                ",constantvol=" + control.constantvol +
                ",volset_confirm=" + control.volset_confirm +
                ",currset_confirm=" + control.currset_confirm +
                ",remote_stop=" + control.remote_stop +
                ",start_screen_set=" + control.start_screen_set +
                ",start_upper_set=" + control.start_upper_set +
                ",consvolswitch=" + control.consvolswitch +
                ",othermode=" + control.othermode +
                ",consvol_distribution=" +control.consvol_distribution +
                "Where electric2KW_id=" +control.electric2KW_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        try {
            sql.sqlMysqlExecute(sql_str);
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            sql.close_con();
        }
    }
    
    /**
     *     ²åÈë»ò¸üе±Ç°É豸µÄÁ¬½Ó״̬
     * @param pool
     * @param dev_id
     * @param master
     */
    public static void insertOrUpdateDeviceConnectState(MysqlConnPool pool,int dev_id,MyModbusMaster master) {
        String sql_str_sel = " SELECT * FROM "+Sql_Mysql.Tb_Device_ConnectState+" WHERE dev_id = " + dev_id;
        String sql_str_ins = " INSERT INTO "+Sql_Mysql.Tb_Device_ConnectState+"(dev_id,connect_en,record_time) values("+dev_id+","+master.getConnectState()+",'"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"');";
        String sql_str_upd = " UPDATE "+Sql_Mysql.Tb_Device_ConnectState+" SET connect_en = "+master.getConnectState()+",record_time='"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)+"' WHERE dev_id = " + dev_id;
        Sql_Mysql sql = new Sql_Mysql(pool.getConn());
        ResultSet res = null;
        try {
            res = sql.sqlMysqlQuery(sql_str_sel);
            if(res.next()) {
                sql.sqlMysqlExecute(sql_str_upd);
            }else {
                sql.sqlMysqlExecute(sql_str_ins);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            if(res != null) {
                try {
                    res.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                sql.close_con();
            }
        }
    }
 
    //¸üÐÂ2MWµçÔ´¹ÊÕÏÊý¾Ý¿â
    public static void insertOrUpdateEle_alarmTable(MysqlConnPool conn_pool, List<Electric_2MW_alarm> list) {
        if(list!=null&&list.size()>0) {
            for (Electric_2MW_alarm ealarm : list) {
                String sql_str_sel = " select * from " + Sql_Mysql.Tb_Electric_2MW_alarm + " where electric_id = " + ealarm.getElectric_id()+" and alarm_id="+ealarm.getAlarm_id();
                String sql_str_ins = " INSERT INTO " + Sql_Mysql.Tb_Electric_2MW_alarm + "(electric_id,alarm_id,alarm_starttime,alarm_endtime,alarm_confirm,alarm_confirmtime) "
                                    +" VALUES("+ealarm.electric_id+","+ealarm.alarm_id+",'"+Com.getDateTimeFormat(ealarm.alarm_starttime,Com.DTF_YMDhms)+"','"+Com.getDateTimeFormat(ealarm.getAlarm_endtime(),Com.DTF_YMDhms)+"',"+ealarm.alarm_confirm+",'"+Com.getDateTimeFormat(ealarm.alarm_confirmtime,Com.DTF_YMDhms)+"');";
                String sql_str_update= " update " + Sql_Mysql.Tb_Electric_2MW_alarm + 
                                       " set alarm_starttime='"+Com.getDateTimeFormat(ealarm.alarm_starttime,Com.DTF_YMDhms)+
                                       "',alarm_endtime='"+Com.getDateTimeFormat(ealarm.getAlarm_endtime(),Com.DTF_YMDhms)+
                                       "',alarm_confirm="+ealarm.alarm_confirm+
                                     //",alarm_confirmtime='"+Com.getDateTimeFormat(ealarm.getAlarm_confirmtime(),Com.DTF_YMDhms)+"'"+
                                       "  where electric_id="+ealarm.electric_id+
                                       "  and alarm_id="+ealarm.alarm_id;
    
                ResultSet res = null;
                Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
                try {
                    res = sql.sqlMysqlQuery(sql_str_sel);
                    if(res.next()) {
                        //¸üе±Ç°¿ØÖÆ×´Ì¬
                        sql.sqlMysqlExecute(sql_str_update);
                    }else {
                        sql.sqlMysqlExecute(sql_str_ins);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    if(res != null) {
                        try {
                            res.close();
                        } catch (SQLException e) {
                            e.printStackTrace();
                        }
                    }
                    sql.close_con();
                }
            }
            
        }
    }
}