lxw
2020-07-11 9db52f2f2dd3665fe9da1ae5657e0167c3a34d40
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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
package com.fgkj.dao.impl;
 
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import com.fgkj.actions.ActionUtil;
import com.fgkj.dao.BaseDAO;
import com.fgkj.dao.CallBack;
import com.fgkj.dao.DAOHelper;
import com.fgkj.db.DBUtil;
import com.fgkj.db.IDatabaseName;
import com.fgkj.dto.BattInf;
import com.fgkj.dto.Batt_Maint_Dealarm;
import com.fgkj.dto.Batt_maint_inf;
import com.fgkj.dto.Batt_maint_process;
import com.fgkj.dto.Batt_maintenance_inf;
import com.fgkj.dto.Batttestdata_inf;
import com.fgkj.dto.Page;
import com.fgkj.dto.User_inf;
 
public class Batt_maint_infImpl implements BaseDAO,CallBack{
    
    public Batt_maint_infImpl() {
        DAOHelper.sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }
 
    public List getResults(ResultSet rs) {
        List list = new ArrayList<BattInf>();
        int id=0;
        try {
            while (rs.next()) {
                Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
                BattInf binf = new BattInf();
                Page p=new Page();
                
                binf.setBattGroupId(rs.getInt("battGroupId"));
                if(id==rs.getInt("battGroupId")){
                    continue;
                }else{
                    id=rs.getInt("battGroupId");
                }
                binf.setStationName(rs.getString("stationName"));
                binf.setBattGroupName(rs.getString("battGroupName"));
                
                /*Batt_maintenance_inf minf=new Batt_maintenance_inf();
                if (rs.getString("maintenance_time") != null)
                    minf.setMaintenance_time(DAOHelper.sdf.parse(rs
                            .getString("maintenance_time")));
 
                */
                Batt_maint_inf mainf=new Batt_maint_inf();
                mainf.setNum(rs.getInt("num"));
                mainf.setUsr_id(rs.getInt("usr_id"));
                
                
                mainf.setFault_type_id(rs.getInt("fault_type_id"));
                mainf.setFault_level(rs.getInt("fault_level"));
                mainf.setFault_caption(rs.getString("fault_caption"));
                
                if(rs.getString("record_time")!=null)
                mainf.setRecord_time(DAOHelper.sdf.parse(rs.getString("record_time")));
                
                if(rs.getString("maint_time_limit")!=null)
                mainf.setMaint_time_limit(DAOHelper.sdf.parse(rs.getString("maint_time_limit")));
                
                mainf.setMaint_type_id(rs.getInt("maint_type_id"));
                mainf.setMaint_result(rs.getString("maint_result"));
                mainf.setMaint_done(rs.getInt("maint_done"));
                
                if(rs.getString("maint_done_time")!=null)
                mainf.setMaint_done_time(DAOHelper.sdf.parse(rs.getString("maint_done_time")));
                
                
                mainf.setMaint_close(rs.getInt("maint_close"));
                mainf.setMaster_id(rs.getInt("master_id"));
                
                mainf.setMaster_audit(rs.getInt("master_audit"));
                mainf.setCopy_uids(rs.getString("copy_uids"));//数据库存储时用的字符串
                
                mainf.setAppoint_uid(rs.getInt("appoint_uid"));
                
                bmd.setBinf(binf);
            //    bmd.setMinf(minf);
                bmd.setPage(p);
                bmd.setMainf(mainf);
                
                list.add(bmd);
 
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return list;
    }
 
    public boolean add(Object obj) {
        Batt_maint_inf binf=(Batt_maint_inf) obj;
        String sql="insert into db_battinf.tb_batt_maint_inf(BattGroupId,usr_id,fault_type_id,fault_type,fault_level,fault_cation," +
                "fault_time,record_uid,record_time,maint_time_limit,maint_type_id,maint_type,maint_result," +
                "maint_done,maint_done_time,maint_close,master_id,master_audit,copy_uids,appoint_check,remark) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Boolean bl=DAOHelper.executeUpdate(DBUtil.getConn(), sql, new Object[]{binf.getBattGroupId(),binf.getUsr_id(),binf.getFault_type_id(),
            binf.getFault_type(),binf.getFault_level(),binf.getFault_caption(),binf.getFault_time(),binf.getRecord_uid(),binf.getRecord_time(),binf.getMaint_time_limit(),
            binf.getMaint_type_id(),binf.getMaint_type(),binf.getMaint_result(),binf.getMaint_done(),binf.getMaint_done_time(),binf.getMaint_close(),binf.getMaster_id(),
            binf.getMaster_audit(),binf.getCopy_uids(),binf.getAppoint_uid(),binf.getMaster_check(),binf.getRemark()});
        return bl;
    }
 
     //2.1 电池维护记录查询(编辑记录)<故障类型和排除方法对应问题?>
    public boolean update(Object obj) {
        Batt_maint_inf mainf = (Batt_maint_inf) obj;
        String sql = "update db_battinf.tb_batt_maint_inf set usr_id=?,fault_type_id=?,fault_level=?,fault_caption=?,"
                + "record_time=?,maint_time_limit=?,maint_type_id=?,"
                + "maint_done=?,maint_done_time=?,maint_result=?,maint_close=?,master_audit=?,copy_uids=?,appoint_uid=? where num=?";
        Boolean bl = DAOHelper.executeUpdate(
            DBUtil.getConn(),
            sql,
            new Object[] {  
                mainf.getUsr_id(),
                mainf.getFault_type_id(),
                mainf.getFault_level(),
                mainf.getFault_caption(),
                mainf.getFault_time(), 
                mainf.getMaint_time_limit(),
                mainf.getMaint_type_id(),
                mainf.getMaint_done(),
                mainf.getMaint_done_time(),
                mainf.getMaint_result(),
                mainf.getMaint_close(),
                mainf.getMaster_audit(), 
                mainf.getCopy_uids(),
                mainf.getAppoint_uid(),
                mainf.getNum() });
        return bl;
    }
    //2.1 电池维护记录查询(删除记录)
    public boolean del(Object obj) {
        Batt_maint_inf mainf = (Batt_maint_inf) obj;
        String sql = "delete from db_battinf.tb_batt_maint_inf where num=?";
        Boolean bl = DAOHelper.executeUpdate(
                DBUtil.getConn(), sql,
                new Object[] { mainf.getNum()});
        return bl;
    }
 
    // 3.1 根据battgroupid查维护数据信息
    public List serchByCondition(Object obj) {
        Batt_Maint_Dealarm bmd = (Batt_Maint_Dealarm) obj;
        List list = null;
        BattInf binf = bmd.getBinf();
        Batt_maint_inf mainf = bmd.getMainf();
        Batttestdata_inf tdata = bmd.getTdata();
        User_inf uinf=bmd.getUinf();
        String sql="";
        String baseSql="select distinct(db_battinf.tb_batt_maint_inf.battgroupid),StationName,BattGroupName "
                + ",db_battinf.tb_batt_maint_inf.num,usr_id,fault_type_id,fault_level,fault_caption,db_battinf.tb_batt_maint_inf.record_time,maint_time_limit,maint_type_id"
                + ",maint_result,maint_done,maint_done_time,maint_close,master_id,master_audit"
                + ",copy_uids,appoint_uid  "
                + "from db_battinf.tb_batt_maint_inf "
                + "left outer join db_battinf.tb_battinf on db_battinf.tb_battinf.BattgroupId=db_battinf.tb_batt_maint_inf.BattGroupId "
                + "left outer join db_batt_testdata.tb_batttestdata_inf on db_battinf.tb_batt_maint_inf.BattGroupId=db_batt_testdata.tb_batttestdata_inf.BattGroupId " +
                "left outer join db_user.tb_user_battgroup_baojigroup_battgroup on db_user.tb_user_battgroup_baojigroup_battgroup.battgroupid=db_battinf.tb_batt_maint_inf.BattGroupId " +
                "left outer join db_user.tb_user_battgroup_baojigroup_usr on db_user.tb_user_battgroup_baojigroup_battgroup.baoji_group_id= db_user.tb_user_battgroup_baojigroup_usr.baoji_group_id " +
                "left outer join db_user.tb_user_inf on db_user.tb_user_inf.uId=db_user.tb_user_battgroup_baojigroup_usr.uid " +
                "where to_days(battproductdate)>=to_days(?) and to_days(battproductdate)<=to_days(?) and to_days(battinusedate)>=to_days(?) and to_days(battinusedate)<=to_days(?)";
         //用于维护区
        String station1SqlT=" and stationname1!=? ";//全部
        String station1SqlF=" and stationname1=? ";
        if(binf.getStationName1().equals("")){
            baseSql+=station1SqlT;
        }else{
            baseSql+=station1SqlF;
        }
        //用于机房站点
        String stationSqlT=" and stationname!=? ";//全部
        String stationSqlF=" and stationname=? ";
        if(binf.getStationName().equals("")){
            baseSql+=stationSqlT;
        }else{
            baseSql+=stationSqlF;
        }
        //用于电池类型
        String producerSqlT=" and battproducer!=? ";//全部
        String producerSqlF=" and battproducer=? ";
        if(binf.getBattProducer().equals("")){
            baseSql+=producerSqlT;
        }else{
            baseSql+=producerSqlF;
        }    
        //用于电池测试记录条件:
        //放电/充电单个/有在线监测记录
        String testSqlH="and db_battinf.tb_batt_maint_inf.BattGroupId in(select distinct(db_batt_testdata.tb_batttestdata_inf.BattGroupId ) from db_batt_testdata.tb_batttestdata_inf where db_batt_testdata.tb_batttestdata_inf.test_type=? and to_days(record_time)>=to_days(?) and to_days(record_time)<=to_days(?)) ";
        //内阻/电导
        String testSqlF="and db_battinf.tb_batt_maint_inf.BattGroupId in(select distinct(db_batt_testdata.tb_battresdata_inf.BattGroupId ) from db_batt_testdata.tb_battresdata_inf where db_batt_testdata.tb_battresdata_inf.test_type=? and to_days(record_time)>=to_days(?) and to_days(record_time)<=to_days(?)) ";
        //充电或者放电都行
        String testSqlT="and db_battinf.tb_batt_maint_inf.BattGroupId in(select distinct(db_batt_testdata.tb_batttestdata_inf.BattGroupId ) from db_batt_testdata.tb_batttestdata_inf where db_batt_testdata.tb_batttestdata_inf.test_type in(?,2,3) and to_days(record_time)>=to_days(?) and to_days(record_time)<=to_days(?))  ";
        //无记录
        String testSqlN="and db_battinf.tb_batt_maint_inf.BattGroupId not in(select distinct(db_batt_testdata.tb_batttestdata_inf.BattGroupId ) from db_batt_testdata.tb_batttestdata_inf where db_batt_testdata.tb_batttestdata_inf.test_type in(?,2,3) and to_days(record_time)>=to_days(?) and to_days(record_time)<=to_days(?)) " ;
        //全部
        String testSqlA="and db_battinf.tb_batt_maint_inf.BattGroupId!=(select count(distinct(db_batt_testdata.tb_batttestdata_inf.BattGroupId )) from db_batt_testdata.tb_batttestdata_inf where db_batt_testdata.tb_batttestdata_inf.test_type in(?,2,3) and to_days(record_time)>=to_days(?) and to_days(record_time)<=to_days(?)) " ;
        if(tdata.getTest_type()==2){
            baseSql+=testSqlH;
        }else if(tdata.getTest_type()==3){
            baseSql+=testSqlH;
        }else if(tdata.getTest_type()==9){//有在线监测记录
            baseSql+=testSqlH;
        }else if(tdata.getTest_type()==5){
            baseSql+=testSqlF;
        }else if(tdata.getTest_type()==3000){//充电或放电
            baseSql+=testSqlT;
        }else if(tdata.getTest_type()==4000){//无记录
            baseSql+=testSqlN;
        }else if(tdata.getTest_type()==0){
            baseSql+=testSqlA;
        }
        //选取蓄电池组条件
        String idSqlT=" and db_battinf.tb_battinf.battgroupid!=?  ";
        String idSqlF=" and db_battinf.tb_battinf.battgroupid=?  ";
        if(binf.getBattGroupId()==0){
            baseSql+=idSqlT;
        }else{
            baseSql+=idSqlF;
        }
        //选取系统类型
        String nameSqlT=" and BattGroupName1 like ? ";
        String nameSqlF=" and BattGroupName1 not like '%开关电源系统%' and BattGroupName1 not like '%UPS系统%' and BattGroupName1 not like ? ";
        if(binf.getBattGroupName1().equals("其他")){
            baseSql+=nameSqlF;
        }else{
            baseSql+=nameSqlT;
        }
        //用于单体电压
        String volSqlT=" and monVolStd!=? ";//全部
        String volSqlF=" and monVolStd=?" ;
        if(binf.getMonVolStd()==0){
            baseSql+=volSqlT;
        }else{
            baseSql+=volSqlF;
        }
        //用于电池容量
        String capSqlT=" and monCapStd!=? ";//全部
        String capSqlF=" and monCapStd=?" ;
        if(binf.getMonCapStd()==0){
            baseSql+=capSqlT;
        }else{
            baseSql+=capSqlF;
        }
        //包机人
        String userSqlF=" and db_user.tb_user_inf.uname=? and db_user.tb_user_inf.ubaojiusr=1 ";
        if(uinf.getUName().equals("0")){
            baseSql=baseSql;
        }else{
            baseSql+=userSqlF;
        }
        //用于测试类型
        //全部
        String start_typeA=" ";
        //拉闸放电
        String start_typeF=" and test_starttype<5 and test_type not in(2,9) and  test_starttype!=2 ";
        //核对性放电
        String start_typeT=" and test_starttype>=5 or (test_type not in(2,9)  and  test_starttype=2)  ";
        if(tdata.getTest_starttype()==0){
            baseSql+=start_typeA;
        }else if(tdata.getTest_starttype()==1){
            baseSql+=start_typeF;
        }else if(tdata.getTest_starttype()==2){
            baseSql+=start_typeT;
        }
        //用于电池维护记录条件
        //有维护记录
        String maintSqlT=" and  db_battinf.tb_battinf.BattGroupId in(select db_battinf.tb_batt_maint_inf.battgroupid from db_battinf.tb_batt_maint_inf where to_days(maint_done_time)>=to_days(?) and to_days(maint_done_time)<=to_days(?)) " ;
        //无维护记录
        String maintSqlF=" and  db_battinf.tb_battinf.BattGroupId not in(select db_battinf.tb_batt_maint_inf.battgroupid from db_battinf.tb_batt_maint_inf where to_days(maint_done_time)>=to_days(?) and to_days(maint_done_time)<=to_days(?)) " ;
        //全部
        String maintSqlA=" and  db_battinf.tb_battinf.BattGroupId!=(select count(distinct(db_battinf.tb_batt_maint_inf.battgroupid )) from db_battinf.tb_batt_maint_inf where to_days(maint_done_time)>=to_days(?) and to_days(maint_done_time)<=to_days(?)) " ;
                        
        if(mainf.getRemark().equals("0")){
            baseSql+=maintSqlF;
        }else if(mainf.getRemark().equals("1")){
            baseSql+=maintSqlT;
        }else if(mainf.getRemark().equals("100")){
            baseSql+=maintSqlA;
        }
        String endSql=" order by StationName1 asc,db_battinf.tb_battinf.BattgroupId asc,test_starttime asc ";
        
        sql=baseSql+endSql;
        //System.out.println(sql);
        if(uinf.getUName().equals("0")){
            list = DAOHelper.executeQuery(
                    sql,
                    DBUtil.getConn(),
                    new Object[] {
                            binf.getBattProductDate(),
                            binf.getBattProductDate1(),
                            binf.getBattInUseDate(),
                            binf.getBattInUseDate1(),
                            binf.getStationName1(),
                            binf.getStationName(),
                            binf.getBattProducer(),
                            
                            tdata.getTest_type(),
                            tdata.getRecord_time(),
                            tdata.getRecord_time1(),
                            binf.getBattGroupId(),
                            "%"+binf.getBattGroupName1()+"%",
                            binf.getMonVolStd(),
                            binf.getMonCapStd(),
                            mainf.getMaint_done_time(),
                            mainf.getMaint_done_time1()
                            },
                    new CallBack() {
                        
                        public List getResults(ResultSet rs) {
                            List list = new ArrayList<BattInf>();
                            try {
                                while (rs.next()) {
                                    Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
                                    BattInf binf = new BattInf();
                                    Page p=new Page();
                                    binf.setBattGroupId(rs.getInt("battGroupId"));
                                    binf.setStationName(rs.getString("stationName"));
                                    binf.setBattGroupName(rs.getString("battGroupName"));
                                    Batt_maint_inf mainf=new Batt_maint_inf();
                                    mainf.setNum(rs.getInt("num"));
                                    mainf.setUsr_id(rs.getInt("usr_id"));
                                    
                                    
                                    mainf.setFault_type_id(rs.getInt("fault_type_id"));
                                    mainf.setFault_level(rs.getInt("fault_level"));
                                    mainf.setFault_caption(rs.getString("fault_caption"));
                                    
                                    if(rs.getString("record_time")!=null)
                                    mainf.setRecord_time(DAOHelper.sdf.parse(rs.getString("record_time")));
                                    
                                    if(rs.getString("maint_time_limit")!=null)
                                    mainf.setMaint_time_limit(DAOHelper.sdf.parse(rs.getString("maint_time_limit")));
                                    
                                    mainf.setMaint_type_id(rs.getInt("maint_type_id"));
                                    mainf.setMaint_result(rs.getString("maint_result"));
                                    mainf.setMaint_done(rs.getInt("maint_done"));
                                    
                                    if(rs.getString("maint_done_time")!=null)
                                    mainf.setMaint_done_time(DAOHelper.sdf.parse(rs.getString("maint_done_time")));
                                    
                                    
                                    mainf.setMaint_close(rs.getInt("maint_close"));
                                    mainf.setMaster_id(rs.getInt("master_id"));
                                    
                                    mainf.setMaster_audit(rs.getInt("master_audit"));
                                    mainf.setCopy_uids(rs.getString("copy_uids"));//数据库存储时用的字符串
                                    
                                    mainf.setAppoint_uid(rs.getInt("appoint_uid"));
                                    
                                    bmd.setBinf(binf);
                                //    bmd.setMinf(minf);
                                    bmd.setPage(p);
                                    bmd.setMainf(mainf);
                                    
                                    list.add(bmd);
 
                                }
                            } catch (SQLException e) {
                                e.printStackTrace();
                            } catch (ParseException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            
                            return list;
                        }
                    });
        }else{
            list = DAOHelper.executeQuery(
                    sql,
                    DBUtil.getConn(),
                    new Object[] {
                            binf.getBattProductDate(),
                            binf.getBattProductDate1(),
                            binf.getBattInUseDate(),
                            binf.getBattInUseDate1(),
                            binf.getStationName1(),
                            binf.getStationName(),
                            binf.getBattProducer(),
                            
                            tdata.getTest_type(),
                            tdata.getRecord_time(),
                            tdata.getRecord_time1(),
                            binf.getBattGroupId(),
                            "%"+binf.getBattGroupName1()+"%",
                            binf.getMonVolStd(),
                            binf.getMonCapStd(),
                            uinf.getUName(),
                            mainf.getMaint_done_time(),
                            mainf.getMaint_done_time1()
                            },
                    new CallBack() {
                        
                        public List getResults(ResultSet rs) {
                            List list = new ArrayList<BattInf>();
                            try {
                                while (rs.next()) {
                                    Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
                                    BattInf binf = new BattInf();
                                    Page p=new Page();
                                    
                                    binf.setBattGroupId(rs.getInt("battGroupId"));
                                    binf.setStationName(rs.getString("stationName"));
                                    binf.setBattGroupName(rs.getString("battGroupName"));
                                    Batt_maint_inf mainf=new Batt_maint_inf();
                                    mainf.setNum(rs.getInt("num"));
                                    mainf.setUsr_id(rs.getInt("usr_id"));
                                    
                                    
                                    mainf.setFault_type_id(rs.getInt("fault_type_id"));
                                    mainf.setFault_level(rs.getInt("fault_level"));
                                    mainf.setFault_caption(rs.getString("fault_caption"));
                                    
                                    if(rs.getString("record_time")!=null)
                                    mainf.setRecord_time(DAOHelper.sdf.parse(rs.getString("record_time")));
                                    
                                    if(rs.getString("maint_time_limit")!=null)
                                    mainf.setMaint_time_limit(DAOHelper.sdf.parse(rs.getString("maint_time_limit")));
                                    
                                    mainf.setMaint_type_id(rs.getInt("maint_type_id"));
                                    mainf.setMaint_result(rs.getString("maint_result"));
                                    mainf.setMaint_done(rs.getInt("maint_done"));
                                    
                                    if(rs.getString("maint_done_time")!=null)
                                    mainf.setMaint_done_time(DAOHelper.sdf.parse(rs.getString("maint_done_time")));
                                    
                                    
                                    mainf.setMaint_close(rs.getInt("maint_close"));
                                    mainf.setMaster_id(rs.getInt("master_id"));
                                    
                                    mainf.setMaster_audit(rs.getInt("master_audit"));
                                    mainf.setCopy_uids(rs.getString("copy_uids"));//数据库存储时用的字符串
                                    
                                    mainf.setAppoint_uid(rs.getInt("appoint_uid"));
                                    
                                    bmd.setBinf(binf);
                                //    bmd.setMinf(minf);
                                    bmd.setPage(p);
                                    bmd.setMainf(mainf);
                                    
                                    list.add(bmd);
 
                                }
                            } catch (SQLException e) {
                                e.printStackTrace();
                            } catch (ParseException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                            
                            return list;
                        }
                    });
        }
        
        List<Batt_Maint_Dealarm> listd=new ArrayList();
        /*for(int i=0;i<list.size();i++){
            System.out.println(((Batt_Maint_Dealarm)list.get(i)).getBinf().getBattGroupId());
        }*/
        int index=0;
        //System.out.println(list.size());
        for(int i=(bmd.getPage().getPageCurr()-1)*bmd.getPage().getPageSize();i<bmd.getPage().getPageSize()*bmd.getPage().getPageCurr()&&i<list.size();i++){
            listd.add((Batt_Maint_Dealarm) list.get(i));
            //system.out.println(list.get(i));
            ((Batt_Maint_Dealarm)listd.get(index++)).getPage().setPageAll(list.size());
        }
        return listd;
 
    }
 
 
    //1.1,1.2根据battgroupid查时间
    public List serchByInfo(Object obj) {
        Batt_maint_inf mainf = (Batt_maint_inf) obj;
    //    System.out.println(mainf.getBattGroupId());
        String sql="select distinct(battgroupid),maint_done_time from db_battinf.tb_batt_maint_inf where battgroupid=? order by battgroupid ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{mainf.getBattGroupId()}, new CallBack() {
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                        Batt_maint_inf mainf=new Batt_maint_inf();
                        mainf.setBattGroupId(rs.getInt("battGroupId"));
                        mainf.setMaint_done_time(DAOHelper.sdf.parse(rs.getString("maint_done_time")));
                        list.add(mainf);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ParseException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
 
    //3.2 电池故障处理统计查询
    public List statistical(Object obj){
        Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm) obj;
        BattInf binf=bmd.getBinf();
        Batt_maint_inf mainf=bmd.getMainf();
        String baseSql="";
        List list=DAOHelper.executeQuery(baseSql,DBUtil.getConn(), null, new Batt_maint_infImpl());
        return list;
    }
 
    //0.3查询所有的维护记录
    public List search() {
        //Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm);
        //System.out.println(bmd+"***********");
        String sql = "select distinct(tb_batt_maint_inf.battgroupid),tb_batt_maint_inf.usr_id,fault_type_id,fault_level,fault_caption,record_time" +
                ",maint_time_limit,maint_type_id,maint_result,maint_done_time,maint_close" +
                ",master_id,master_audit,copy_uids,appoint_uid " +
                ",batt_maint_rec_id,tb_batt_maint_process.usr_id,work_caption,work_caption_time" +
                ",uname" +
                ",stationname,battgroupname  " +
                "from db_battinf.tb_batt_maint_inf,db_battinf.tb_batt_maint_process,db_user.tb_user_inf,db_battinf.tb_battinf  " +
                "where  tb_batt_maint_inf.usr_id=tb_batt_maint_process.usr_id " +
                "and  tb_batt_maint_inf.battgroupid=tb_battinf.BattGroupId " +
                "and tb_batt_maint_inf.usr_id=db_user.tb_user_inf.uId " +
                "order by work_caption_time desc ";
        //System.out.println(sql);
        List list = DAOHelper.executeQuery(sql,
                DBUtil.getConn(), null,
                new CallBack() {
                    
                    public List getResults(ResultSet rs) {
                        List list=new ArrayList();
                        try {
                            while(rs.next()){
                            Batt_Maint_Dealarm bmd=new Batt_Maint_Dealarm();
                            Batt_maint_inf mainf=new Batt_maint_inf();
                            mainf.setUsr_id(rs.getInt("usr_id"));
                            mainf.setBattGroupId(rs.getInt("battGroupId"));
                            mainf.setFault_type_id(rs.getInt("fault_type_id"));
                            mainf.setFault_level(rs.getInt("fault_level"));
                            mainf.setFault_caption(rs.getString("fault_caption"));
                            //System.out.println("-----"+rs.getString("record_time")+"-----");
                            if (rs.getString("record_time") != null && rs.getString("record_time").length()>0){
                                //System.out.println(rs.getString("record_time"));
                                mainf.setRecord_time(rs.getTimestamp("record_time"));
        
                                //mainf.setRecord_time(rs.getDate("record_time"));
                                //System.out.println("-----"+rs.getString("maint_time_limit")+"-----");
                            }
                            if (rs.getString("maint_time_limit") != null && rs.getString("maint_time_limit").length()>0){
                                mainf.setMaint_time_limit(rs.getTimestamp("maint_time_limit"));
        
                            }    //mainf.setMaint_time_limit(rs.getDate("maint_time_limit"));
                            mainf.setMaint_type_id(rs.getInt("maint_type_id"));
                            mainf.setMaint_result(rs.getString("maint_result"));
                            //System.out.println("-----"+rs.getString("maint_done_time")+"-----");
                            if (rs.getString("maint_done_time") != null && rs.getString("maint_done_time").length()>0){
                                //System.out.println(rs.getString("maint_done_time"));
                                mainf.setMaint_done_time(rs.getTimestamp("maint_done_time"));
                                //System.out.println(mainf.getMaint_done_time());
                            }    //mainf.setMaint_done_time(rs.getDate("maint_done_time"));
                            mainf.setMaint_close(rs.getInt("maint_close"));
                            mainf.setMaster_id(rs.getInt("master_id"));
                            mainf.setMaster_audit(rs.getInt("master_audit"));
                            mainf.setCopy_uids(rs.getString("copy_uids"));// 数据库存储时用的字符串
                            mainf.setAppoint_uid(rs.getInt("appoint_uid"));
                            
                            Batt_maint_process mprocess=new Batt_maint_process();
                            mprocess.setUname(rs.getString("uname"));
                            mprocess.setBatt_maint_rec_id(rs.getInt("batt_maint_rec_id"));
                            mprocess.setUsr_id(rs.getInt("usr_id"));
                            mprocess.setWork_caption(rs.getString("work_caption"));
                            if(rs.getString("work_caption_time")!=null && rs.getString("work_caption_time").length()>0){
                                mprocess.setWork_caption_time(rs.getTimestamp("work_caption_time"));
                                //mprocess.setWork_caption_time(rs.getDate("work_caption_time"));
                            }
                            
                            BattInf binf=new BattInf();
                            binf.setBattGroupName(rs.getString("battGroupName"));
                            binf.setStationName(rs.getString("stationName"));
                            
                            Page page=new Page();
                            bmd.setBinf(binf);
                            bmd.setMainf(mainf);
                            bmd.setMprocess(mprocess);
                            bmd.setPage(page);
                            list.add(bmd);
                            }
                        } catch (SQLException e) {
                            e.printStackTrace();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return list;
                    }
                });
//        List<Batt_Maint_Dealarm> listd=new ArrayList();
        /*for(int i=0;i<list.size();i++){
            System.out.println(((Batt_Maint_Dealarm)list.get(i)).getBinf().getBattGroupId());
        }*/
//        int index=0;
        //System.out.println(list.size()+"&&&&&&&&&&&&777777");
//        for(int i=(bmd.getPage().getPageCurr()-1)*bmd.getPage().getPageSize();i<bmd.getPage().getPageSize()*bmd.getPage().getPageCurr()&&i<list.size();i++){
//            listd.add((Batt_Maint_Dealarm) list.get(i));
//            //system.out.println(list.get(i));
//            ((Batt_Maint_Dealarm)listd.get(index++)).getPage().setPageAll(list.size());
//        }
        return list;
 
    }
 
    //0.4查询所有故障的电池组
    public List searchAll() {
        String sql="select distinct(battgroupid),usr_id,fault_type_id,fault_level,fault_caption,record_time" +
                ",maint_time_limit,maint_type_id,maint_result,maint_done_time,maint_close" +
                ",master_id,master_audit,copy_uids,appoint_uid " +
                "from db_battinf.tb_batt_maint_inf " +
                "order by maint_done_time desc ";
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), null, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                    Batt_maint_inf mainf=new Batt_maint_inf();
                    mainf.setUsr_id(rs.getInt("usr_id"));
                    mainf.setBattGroupId(rs.getInt("battGroupId"));
                    mainf.setFault_type_id(rs.getInt("fault_type_id"));
                    mainf.setFault_level(rs.getInt("fault_level"));
                    mainf.setFault_caption(rs.getString("fault_caption"));
                    if (rs.getString("record_time") != null)
                        mainf.setRecord_time(rs.getTimestamp("record_time"));
                    if (rs.getString("maint_time_limit") != null)
                        mainf.setMaint_time_limit(rs.getTimestamp("maint_time_limit"));
                    mainf.setMaint_type_id(rs.getInt("maint_type_id"));
                    mainf.setMaint_result(rs.getString("maint_result"));
                    if (rs.getString("maint_done_time") != null)
                        mainf.setMaint_done_time(rs.getTimestamp("maint_done_time"));
                    mainf.setMaint_close(rs.getInt("maint_close"));
                    mainf.setMaster_id(rs.getInt("master_id"));
                    mainf.setMaster_audit(rs.getInt("master_audit"));
                    mainf.setCopy_uids(rs.getString("copy_uids"));// 数据库存储时用的字符串
                    mainf.setAppoint_uid(rs.getInt("appoint_uid"));
 
                    list.add(mainf);
                    }
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
 
    //0.4/0.8根据城市查询所有故障的电池组(故障率和维护率)
    public List searchByStationName(Object obj) {
        Batt_Maint_Dealarm bmd=(Batt_Maint_Dealarm) obj;
        BattInf binf=bmd.getBinf();
        Batt_maint_inf mainf=bmd.getMainf();
        String sql="";
        String baseSql="select distinct(tb_batt_maint_inf.battgroupid),usr_id,fault_type_id,fault_level,fault_caption,record_time,maint_time_limit,maint_type_id,maint_result,maint_done_time,maint_close,master_id,master_audit,copy_uids,appoint_uid " +
                "from db_battinf.tb_batt_maint_inf,db_battinf.tb_battinf   " +
                "where tb_batt_maint_inf.battgroupid=tb_battinf.battgroupid   " +
                "and stationname like ? " ;
        //是否已修复
        String maintSqlT=" and maint_done!=? ";        //全部
        String maintSqlF=" and maint_done=? ";        //1求维护率
        if(mainf.getMaint_done()==100){                //100求故障率
            baseSql+=maintSqlT;
        }else{
            baseSql+=maintSqlF;
        }
        String endSql=" order by maint_done_time desc ";
        sql=baseSql+endSql;
        
        //System.out.println(sql);
        
        List list=DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{"%"+binf.getStationName()+"%",mainf.getMaint_done()}, new CallBack() {
            
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while(rs.next()){
                    Batt_maint_inf mainf=new Batt_maint_inf();
                    mainf.setUsr_id(rs.getInt("usr_id"));
                    mainf.setBattGroupId(rs.getInt("battGroupId"));
                    mainf.setFault_type_id(rs.getInt("fault_type_id"));
                    mainf.setFault_level(rs.getInt("fault_level"));
                    mainf.setFault_caption(rs.getString("fault_caption"));
                    if (rs.getString("record_time").length()>0)
                        mainf.setRecord_time(rs.getTimestamp(("record_time")));
                    if (rs.getString("maint_time_limit").length()>0)
                        mainf.setMaint_time_limit(rs.getTimestamp("maint_time_limit"));
                    mainf.setMaint_type_id(rs.getInt("maint_type_id"));
                    mainf.setMaint_result(rs.getString("maint_result"));
                    if (rs.getString("maint_done_time").length()>0)
                        mainf.setMaint_done_time(rs.getTimestamp("maint_done_time"));
                    mainf.setMaint_close(rs.getInt("maint_close"));
                    mainf.setMaster_id(rs.getInt("master_id"));
                    mainf.setMaster_audit(rs.getInt("master_audit"));
                    mainf.setCopy_uids(rs.getString("copy_uids"));// 数据库存储时用的字符串
                    mainf.setAppoint_uid(rs.getInt("appoint_uid"));
 
                    list.add(mainf);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
        return list;
    }
    
    //根据电池组id查询电池的维护记录
    public List searchByBattgroupId(Object obj) {
        Batt_maint_inf bmi=(Batt_maint_inf)obj;
        String sql="select num,BattGroupId,usr_id,fault_type_id,fault_type,fault_level,fault_caption," +
                   "fault_time,record_uid,record_time,maint_time_limit,maint_type_id,maint_type,maint_result," +
                   "maint_done,maint_done_time,maint_close,master_id,master_audit,copy_uids,appoint_uid,master_check,remark " +
                   "from db_battinf.tb_batt_maint_inf where BattGroupId=?";
        return DAOHelper.executeQuery(sql, DBUtil.getConn(), new Object[]{bmi.getBattGroupId()}, new CallBack() {
            public List getResults(ResultSet rs) {
                List list=new ArrayList();
                try {
                    while (rs.next()) {
                        Batt_maint_inf b=new Batt_maint_inf();
                        b.setNum(rs.getInt("num"));
                        b.setBattGroupId(rs.getInt("BattGroupId"));
                        b.setUsr_id(rs.getInt("usr_id"));
                        b.setFault_type_id(rs.getInt("fault_type_id"));
                        b.setFault_type(rs.getString("fault_type"));
                        b.setFault_level(rs.getInt("fault_level"));
                        b.setFault_caption(rs.getString("fault_caption"));
                        b.setFault_time(rs.getTimestamp("fault_time"));
                        b.setRecord_uid(rs.getInt("record_uid"));
                        b.setRecord_time(rs.getTimestamp("record_time"));
                        b.setMaint_time_limit(rs.getTimestamp("maint_time_limit"));
                        b.setMaint_type_id(rs.getInt("maint_type_id"));
                        b.setMaint_type(rs.getString("maint_type"));
                        b.setMaint_result(rs.getString("maint_result"));
                        b.setMaint_done(rs.getInt("maint_done"));
                        b.setMaint_done_time(rs.getTimestamp("maint_done_time"));
                        b.setMaint_close(rs.getInt("maint_close"));
                        b.setMaster_id(rs.getInt("master_id"));
                        b.setCopy_uids(rs.getString("copy_uids"));
                        b.setAppoint_uid(rs.getInt("appoint_uid"));
                        b.setMaster_check(rs.getString("master_check"));
                        b.setRemark(rs.getString("remark")); 
                        list.add(b);
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                return list;
            }
        });
    }
 
    public static void main(String[] args) throws ParseException {
        
        Batt_maint_infImpl bimpl=new Batt_maint_infImpl();
        BattInfImpl biml =new BattInfImpl();
        BattInf binf = new BattInf();
        
         
        binf.setStationName("");
        binf.setStationName1("一枢纽");
        //binf.setBattGroupName("");
        binf.setBattGroupId(0);
        binf.setBattGroupName1("");
        binf.setBattProducer("光宇");
        binf.setMonCapStd(0f);
        binf.setMonVolStd(0f);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = sdf.parse("2000-01-01");
        Date date2 = sdf.parse("2016-07-14");
        binf.setBattProductDate(ActionUtil.getSimpDate(date1));
        binf.setBattProductDate1(ActionUtil.getSimpDate(date2));
        binf.setBattInUseDate(ActionUtil.getSimpDate(date1));
        binf.setBattInUseDate1(ActionUtil.getSimpDate(date2));
 
 
        Batt_maint_inf mainf = new Batt_maint_inf();
        mainf.setRemark("100");
        mainf.setMaint_done_time(ActionUtil.getSimpDate(date1));
        mainf.setMaint_done_time1(ActionUtil.getSimpDate(date2));
 
        Batttestdata_inf tdata = new Batttestdata_inf();
        tdata.setTest_type(0);
        tdata.setTest_starttype(0);
        tdata.setRecord_time(ActionUtil.getSimpDate(date1));
        tdata.setRecord_time1(ActionUtil.getSimpDate(date2));
        
        User_inf uinf=new User_inf();
        uinf.setUName("0");
        
        Page p=new Page();
        p.setPageCurr(1);
        p.setPageSize(1);
        
        Batt_Maint_Dealarm bmd = new Batt_Maint_Dealarm();
        bmd.setBinf(binf);
        bmd.setMainf(mainf);
        bmd.setTdata(tdata);
        bmd.setPage(p);
        bmd.setUinf(uinf);
        
        //List<Batt_Maint_Dealarm> list = bimpl.serchByCondition(bmd);
//        for (Batt_Maint_Dealarm b : list) {
//            System.out.println(b.getMainf());
//        }
        
    }
 
 
}