whyclxw
7 天以前 3f10a987545e11d75b72408d6d4bac0e3ab1851e
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
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
package com.whyc.service;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.constant.BattCapperformanceEnum;
import com.whyc.constant.PwrCapperformanceEnum;
import com.whyc.constant.StopReasonEnum;
import com.whyc.dto.Real.TestDataDto;
import com.whyc.dto.Response;
import com.whyc.dto.Statistic.*;
import com.whyc.factory.BattCapFactory;
import com.whyc.mapper.BatttestdataInfMapper;
import com.whyc.pojo.db_batt_testdata.BatttestdataId;
import com.whyc.pojo.db_batt_testdata.BatttestdataInf;
import com.whyc.pojo.db_param.AppParam;
import com.whyc.pojo.db_ram_db.BattRtdata;
import com.whyc.pojo.db_ram_db.BattRtstate;
import com.whyc.pojo.db_station.BattInf;
import com.whyc.pojo.db_station.PowerInf;
import com.whyc.pojo.db_user.Baojigroup;
import com.whyc.util.ActionUtil;
import com.whyc.util.DateUtil;
import com.whyc.util.PageInfoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.*;
 
@Service
public class BatttestdataInfService {
    @Autowired(required = false)
    private BatttestdataInfMapper mapper;
 
    @Autowired(required = false)
    private BattRtstateService rtstateService;
 
    @Autowired(required = false)
    private BattRtdataService rtdataService;
 
    @Autowired(required = false)
    private BattInfService battInfService;
 
    @Autowired(required = false)
    private BatttestdataIdService battTestdataIdService;
 
    @Autowired(required = false)
    private AppParamService appParamService;
 
    @Autowired(required = false)
    private BaojigroupService bjService;
 
    @Autowired(required = false)
    private PowerInfService powerInfService;
 
    @Autowired(required = false)
    private PwrdevHistorydataIdService pwrHisdataIdService;
 
 
 
 
    //获取最后一次测试数据并计算剩余容量
    public Float getLastTestDataRestCap(Integer battgroupId) {
        //获取放电记录
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("battgroup_id",battgroupId);
        wrapper.orderByDesc("test_starttime");
        wrapper.last("limit 1");
        BatttestdataInf tinf=mapper.selectOne(wrapper);
        if(tinf!=null){
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float restcap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
            return restcap;
        }else{
            return 0f;
        }
    }
    //蓄电池核容信息统计
    public Response getBattTinfStatistic(BattTinfStic stic) {
        PageHelper.startPage(stic.getPageNum(), stic.getPageSize());
        List<BatttestdataInf> list=mapper.getBattTinfStatistic(stic);
        if(list!=null&&list.size()>0){
            for (BatttestdataInf tinf:list) {
                //剩余容量和剩余时间计算
                int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
                Float restCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
                Float realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                tinf.setRestCap(restCap);
                tinf.setRealCap(realCap);
                tinf.setRestTime(0f);
                //获取电池组实时数据
                BattRtstate battRtstate=rtstateService.getBattRealInfo(tinf.getBattgroupId());
                //获取电池组信息
                BattInf binf=battInfService.getBinfByBattgroupId(tinf.getBattgroupId());
                //实时组端电流,剩余容量,标称容量
                if(battRtstate!=null){
                    Float restTime= BattCapFactory.getTheoryTime(battRtstate.getLoadCurr(), restCap, binf.getMoncapstd());
                    tinf.setRestTime(restTime);
                }
                //保留5位小数
                String precentCap = String.format("%.5f",(restCap/binf.getMoncapstd()*100));
                tinf.setPrecentCap(precentCap);
            }
        }
 
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0,pageInfo,"蓄电池核容信息统计");
    }
    //获取上一次标准核容信息(标准核容的界定为单测核容时间达 2小时及以上的核容测试)
    public BatttestdataInf getLastStandardTestData(Integer battgroupId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
        wrapper.last("limit 1");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        tinf.setTestStoptypeReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
        return tinf;
    }
 
    //获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
    protected BatttestdataInf getLastStandardTestDataByTime(Integer battgroupId, Date testStartTime, Date testEndTime) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("battgroup_id", battgroupId);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        if(testStartTime!=null){
            wrapper.gt("test_starttime",testStartTime);
        }
        if(testEndTime!=null){
            wrapper.lt("test_starttime",testEndTime);
        }
        wrapper.last("  and test_timelong >= 7200 ORDER BY test_starttime DESC ");
        wrapper.last("limit 1");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        return tinf;
    }
    /*单节数量统计
      1筛选满足条件的电池组,找最近一次标准核容放电记录的最后一笔数据
      2再按照公式计算单体实际容量,
      3然后找到判断优秀,劣化,损坏的参数,得到结果。
      4浮充电压图,需要显示单体+实时数据的单体电压,单体内阻
    */
    public Map getMonStatistic(MonStic stic) {
        Map<String,Object> map=new HashMap<>();
        List<SticMonRes> goodlist=new ArrayList();
        List<SticMonRes> badlist=new ArrayList();
        List<SticMonRes> damagelist=new ArrayList();
        map.put("goodlist",goodlist);
        map.put("badlist",badlist);
        map.put("damagelist",damagelist);
        map.put("goodlistNum",0);
        map.put("badlistNum",0);
        map.put("damagelistNum",0);
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        List<BattInf> binfList=battInfService.getMonStatistic(stic);
        Float realCap=0f;
        if(binfList==null){
           return map;
        }
        for (BattInf binf:binfList) {
            BatttestdataInf tinf =getLastStandardTestData(binf.getBattgroupId());
            if(tinf==null){
                //将不满足条件的电池组的所有单体放入damage中
                setDamage(damagelist,binf);
                continue;
            }
            //找这次放电的最后一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
            if(idDataList==null||idDataList.size()==0){
                //将不满足条件的电池组的所有单体放入damage中
                setDamage(damagelist,binf);
                continue;
            }
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float moncapStd=binf.getMoncapstd();
            for (BatttestdataId data:idDataList) {//求单体的 实际容量,最小值就是单体的单体电压
                realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(),data.getMonVol() , tinf.getGroupVol(), BattCapFactory.CapType_Real);
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setMonNum(data.getMonNum());
                //获取单体的实时数据
                BattRtdata rtdata=rtdataService.getRtdataByNum(binf.getBattgroupId(),data.getMonNum());
                if(rtdata==null){
                    res.setMonVol(0f);
                    res.setMonRes(0f);
                }else{
                    res.setMonVol(rtdata.getMonVol());
                    res.setMonRes(rtdata.getMonRes());
                }
                if(realCap>=moncapStd*badValue){
                    goodlist.add(res);
                }
                if(realCap<=moncapStd*damageValue){
                    damagelist.add(res);
                }
                if((realCap>moncapStd*damageValue)&&(realCap<moncapStd*badValue)){
                    badlist.add(res);
                }
            }
        }
        map.put("goodlist",goodlist);
        map.put("badlist",badlist);
        map.put("damagelist",damagelist);
        map.put("goodlistNum",goodlist.size());
        map.put("badlistNum",badlist.size());
        map.put("damagelistNum",damagelist.size());
        return map;
 
    }
    //将不满足条件的电池组的所有单体放入damage中
    private void setDamage(List damagelist, BattInf binf) {
        //获取电池组的实时数据
        List<BattRtdata> rtdataList=rtdataService.getRtdataRealInfo(binf.getBattgroupId());
        if(rtdataList==null||rtdataList.size()==0){
            for (int i=0;i<binf.getMoncount();i++){
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setMonNum(i+1);
                res.setMonVol(0f);
                res.setMonRes(0f);
                damagelist.add(res);
            }
        }else {
            for (BattRtdata rtdata:rtdataList) {
                SticMonRes res=new SticMonRes();
                res.setBattgroupId(binf.getBattgroupId());
                res.setBattgroupName(binf.getBattgroupName());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setMonNum(rtdata.getMonNum());
                res.setMonVol(rtdata.getMonVol());
                res.setMonRes(rtdata.getMonRes());
                damagelist.add(res);
            }
        }
    }
    /*蓄电池组对比分析界面(同一品牌同一时间)
     *1.查询出符合条件的电池组信息
     * 2.计算电池组的预估剩余容量
     *3.判断性能和百分比
     * 4.分页
     */
    public Response getBattCompare15Statistic(BattCompareStic stic) {
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getBattCompare15Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticCompare15Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            SticCompare15Res res=new SticCompare15Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setDevName(binf.getDevName());
            res.setProduct(binf.getProduct());
            res.setInuseTime(binf.getInuseTime());
            res.setMonvolstd(binf.getMonvolstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                res.setRealCap(0f);
                res.setPrecentCap("0");
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
                continue;
            }
            //找这次放电的最后一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
            if(idDataList==null||idDataList.size()==0){
                res.setRealCap(0f);
                res.setPrecentCap("0");
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
                continue;
            }
            Float moncapStd=binf.getMoncapstd();
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float grouprealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
            //Float restCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
            res.setRealCap(grouprealCap);
            if(grouprealCap>=moncapStd*badValue){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
            }
            if(grouprealCap<=moncapStd*damageValue){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
            }
            if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
            }
            //保留5位小数
            String precentCap = String.format("%.5f",(grouprealCap/binf.getMoncapstd()*100));
            res.setPrecentCap(precentCap);
            List<Integer> monNums=new ArrayList<>();
            for (BatttestdataId data:idDataList) {//求单体的 实际容量,最小值就是单体的单体电压
                Float monrealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), data.getMonVol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                if (monrealCap <= moncapStd * damageValue) {//损坏的
                    monNums.add(data.getMonNum());
                }
            }
            res.setMonNums(monNums);
            if(stic.getPerformance()==null){
                reslist.add(res);
            }else{
                if(res.getCapperformance().equals(BattCapperformanceEnum.getValue(stic.getPerformance()))){
                    reslist.add(res);
                }
            }
 
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"蓄电池组对比分析界面(同一品牌同一时间)");
    }
 
    //蓄电池组对比分析界面(不同品牌同一时间)(1.2.16)
    public Response getBattCompare16Statistic(BattCompareStic stic) {
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getBattCompare16Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticCompare16Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            SticCompare16Res res=new SticCompare16Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setDevName(binf.getDevName());
            res.setProduct(binf.getProduct());
            res.setInuseTime(binf.getInuseTime());
            res.setMonvolstd(binf.getMonvolstd());
            res.setMoncapstd(binf.getMoncapstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                res.setRealCap(0f);
                res.setPrecentCap("0");
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
                res.setStopReason("--");
                continue;
            }
            res.setStopReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
            Float moncapStd=binf.getMoncapstd();
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float grouprealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
            //Float restCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
            res.setRealCap(grouprealCap);
            if(grouprealCap>=moncapStd*badValue){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
            }
            if(grouprealCap<=moncapStd*damageValue){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
            }
            if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
            }
            //保留5位小数
            String precentCap = String.format("%.5f",(grouprealCap/binf.getMoncapstd()*100));
            //评分的逻辑
            res.setScore(0f);
            res.setPrecentCap(precentCap);
            if(stic.getPerformance()==null){
                reslist.add(res);
            }else{
                if(res.getCapperformance().equals(BattCapperformanceEnum.getValue(stic.getPerformance()))){
                    reslist.add(res);
                }
            }
 
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"蓄电池组对比分析界面(不同品牌同一时间)");
    }
    //蓄电池组对比分析界面(同一品牌不同时间)(1.2.17)
    public Response getBattCompare17Statistic(BattCompareStic stic) {
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getBattCompare17Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticCompare17Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                //不存在放电记录则默认为实际预估容量全为0
                setSticCompare17Res(binf,reslist,stic.getPerformance());
                continue;
            }
            //找这次放电的最后一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
            if(idDataList==null||idDataList.size()==0){
                //不存在放电记录则默认为实际预估容量全为0
                setSticCompare17Res(binf,reslist,stic.getPerformance());
                continue;
            }
            Float moncapStd=binf.getMoncapstd();
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            for (BatttestdataId data:idDataList) {//求单体的 实际容量,最小值就是单体的单体电压
                SticCompare17Res res=new SticCompare17Res();
                res.setProvice(binf.getProvice());
                res.setCity(binf.getCity());
                res.setCountry(binf.getCountry());
                res.setStationName(binf.getStationName());
                res.setDevName(binf.getDevName());
                res.setBattgroupName(binf.getBattgroupName());
                res.setProduct(binf.getProduct());
                res.setInuseTime(binf.getInuseTime());
                res.setMonvolstd(binf.getMonvolstd());
                res.setMonNum(data.getMonNum());
                res.setStationId(binf.getStationId());
                res.setPowerId(binf.getPowerId());
                res.setDevId(binf.getDevId());
                res.setBattgroupId(binf.getBattgroupId());
                Float monrealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), data.getMonVol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                res.setMonrealCap(monrealCap);
                //保留5位小数
                String monprecentCap = String.format("%.5f",(monrealCap/binf.getMoncapstd()*100));
                res.setMonprecentCap(monprecentCap);
                if(monrealCap>=moncapStd*badValue){
                    res.setMoncapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
                }
                if (monrealCap <= moncapStd * damageValue) {//损坏的
                    res.setMoncapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
                }
                if((monrealCap>moncapStd*damageValue)&&(monrealCap<moncapStd*badValue)){
                    res.setMoncapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
                }
                if(stic.getPerformance()==null){
                    reslist.add(res);
                }else{
                    if(res.getMoncapperformance().equals(BattCapperformanceEnum.getValue(stic.getPerformance()))){
                        reslist.add(res);
                    }
                }
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"蓄电池组对比分析界面(同一品牌同一时间)");
    }
    //不存在放电记录则默认为实际预估容量全为0
    private void setSticCompare17Res( BattInf binf, List<SticCompare17Res> reslist,Integer performance) {
        for (int i=0;i<binf.getMoncount();i++){
            SticCompare17Res res=new SticCompare17Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setDevName(binf.getDevName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setProduct(binf.getProduct());
            res.setInuseTime(binf.getInuseTime());
            res.setMonvolstd(binf.getMonvolstd());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setDevId(binf.getDevId());
            res.setBattgroupId(binf.getBattgroupId());
            res.setMonNum(i+1);
            res.setMonrealCap(0f);
            res.setMonprecentCap("0");
            res.setMoncapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
            if(performance==null){
                reslist.add(res);
            }else{
                if(res.getMoncapperformance().equals(BattCapperformanceEnum.getValue(performance))){
                    reslist.add(res);
                }
            }
        }
    }
    //历史测试记录
    public Response getBattTinf(Integer battgroupId) {
        Map<String,  Object> map=new HashMap<>();
        List<TestDataDto> List1=new ArrayList<>();
        List<TestDataDto> List2=new ArrayList<>();
        List<TestDataDto> List3=new ArrayList<>();
        List<TestDataDto> List4=new ArrayList<>();
        List<TestDataDto> List5=new ArrayList<>();
        map.put("核容放电",List1);   //核容放电
        map.put("核容充电",List2);   //核容充电
        map.put("监测放电",List3);   //监测放电
        map.put("监测充电",List4);   //监测充电
        map.put("停电放电",List5);   //停电放电
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("battgroup_id",battgroupId);
        wrapper.orderByDesc("test_starttime");
        List<BatttestdataInf> list=mapper.selectList(wrapper);
        for (BatttestdataInf tinf:list) {
            TestDataDto dto=new TestDataDto();
            dto.setTestStarttime(tinf.getTestStarttime());
            dto.setBattgroupId(tinf.getBattgroupId());
            dto.setTestRecordCount(tinf.getTestRecordCount());
            dto.setRecordNum(tinf.getRecordNum());
            dto.setTestCap(tinf.getTestCap());
            dto.setTestTimeLong(tinf.getTestTimelong());
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float realCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
            dto.setRealCap(realCap);
            //实时获取电池组信息
            BattRtstate battRtstate = rtstateService.getBattRealInfo(tinf.getBattgroupId());
            //获取电池组信息
            BattInf binf = battInfService.getBinfByBattgroupId(tinf.getBattgroupId());
            dto.setMoncapstd(binf.getMoncapstd());
            dto.setMonCount(binf.getMoncount());
            dto.setMonvolstd(binf.getMonvolstd());
            if(battRtstate!=null){
                Float restTime= BattCapFactory.getTheoryTime(battRtstate.getLoadCurr(), realCap, binf.getMoncapstd());
                dto.setRestTime(restTime);
                dto.setFloatchartVol(battRtstate.getGroupVol());
            }else{
                dto.setRestTime(0f);
                dto.setFloatchartVol(0f);
            }
            //找这次放电的指定一笔数据
            List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),1);
            if(idDataList!=null&&idDataList.size()>0){
                BatttestdataId idData=idDataList.get(0);
                dto.setOnlineVol(idData.getOnlineVol());
                dto.setGroupCurr(idData.getTestCurr());
            }else {
                dto.setOnlineVol(0f);
                dto.setGroupCurr(0f);
            }
            if (tinf.getTestType() == 3) {
                // 测试类型为放电
                if (tinf.getTestStarttype() == 3) {
                    List1.add(dto);
                } else if(tinf.getTestStarttype() == 4){
                    List5.add(dto);
                }else {
                    List3.add(dto);
                }
            } else if (tinf.getTestType() == 2) {
                // 测试类型为充电
                if (tinf.getTestStarttype() == 3) {
                    List2.add(dto);
                } else {
                    List4.add(dto);
                }
            }
        }
        return new Response().setII(1,true,map,"历史测试记录");
    }
    //本年度已放电数量统计(1.2.5)<只查看已放电数据>
    public Response getDischr5Statistic(DisChargeStic stic) {
        //班组
        Map<String,  Object> bzmap=new HashMap<>();
        //性能
        Map<String,  Integer> xnmap=new HashMap<>();
        xnmap.put("优秀",0);
        xnmap.put("劣化",0);
        xnmap.put("损坏",0);
        xnmap.put("未放电",0);
        //查询出所有的班组并赋予初始值
        setBanZuDefault(bzmap);
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getDischr5Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticDischarge5Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            //查询电池组所在的班组
            String  groupName=bjService.getGroupName(binf.getPowerId());
            SticDischarge5Res res=new SticDischarge5Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setBattgroupId(binf.getBattgroupId());
            res.setDevId(binf.getDevId());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                continue;
            }
            if(!groupName.equals("none")){
                BanZu bz= (BanZu) bzmap.get(groupName);
                int dischargeNum=bz.getDischargeNum();
                bz.setDischargeNum(dischargeNum+1);
                bzmap.put(groupName,bz);
            }
            res.setTestStartTime(tinf.getTestStarttime());
            res.setTestTimelong(tinf.getTestTimelong());
            res.setTestCap(tinf.getTestCap());
            res.setStopReason(StopReasonEnum.getValue(tinf.getTestStoptype()));
            if (tinf.getTestType() == 3) {
                // 测试类型为放电
                if (tinf.getTestStarttype() == 3) {
                    res.setDischargeName("核容放电");
                } else if(tinf.getTestStarttype() == 4){
                    res.setDischargeName("停电放电");
                }else {
                    res.setDischargeName("监测放电");
                }
            }
            res.setTestRecordCount(tinf.getTestRecordCount());
            Float moncapStd=binf.getMoncapstd();
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
            Float grouprealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
            res.setRealCap(grouprealCap);
            //res.setDisChargeType(1);
            if(grouprealCap>=moncapStd*badValue){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
                int value=xnmap.get(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
                xnmap.put(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()),value+1);
            }
            if(grouprealCap<=moncapStd*damageValue){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
                int value=xnmap.get(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
                xnmap.put(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()),value+1);
            }
            if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
                int value=xnmap.get(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
                xnmap.put(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()),value+1);
            }
            reslist.add(res);
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setIIII(1,reslist.size()>0,pageInfo,bzmap,xnmap,"本年度已放电数量统计");
    }
 
    //查询出所有的班组并赋予初始值
    private void setBanZuDefault(Map<String, Object> map) {
        List<Baojigroup> banZuList=bjService.getGroupList();
        for (Baojigroup bj:banZuList) {
            BanZu bz=new BanZu();
            bz.setBaojiGroupId(bj.getBaojiGroupId());
            bz.setBaojiGroupName(bj.getBaojiGroupName());
            bz.setDischargeNum(0);
            bz.setNochargeNum(0);
            map.put(bj.getBaojiGroupName(),bz);
        }
    }
 
    //本年度未放电数量统计(1.2.6)
    public Response getDischr6Statistic(DisChargeStic stic) {
        //班组
        Map<String,  Object> bzmap=new HashMap<>();
        //查询出所有的班组并赋予初始值
        setBanZuDefault(bzmap);
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getDischr6Statistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<SticDischarge6Res> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            //查询电池组所在的班组
            String  groupName=bjService.getGroupName(binf.getPowerId());
            SticDischarge6Res res=new SticDischarge6Res();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setMoncapstd(binf.getMoncapstd());
            res.setMonvolstd(binf.getMonvolstd());
            res.setMoncount(binf.getMoncount());
            res.setProduct(binf.getProduct());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setBattgroupId(binf.getBattgroupId());
            res.setDevId(binf.getDevId());
            //获取电池组未放电记录(指定时间段的标准核容放电)
            getNoDischargeData(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime(),null,res);
            /*if(stic.getStopReasonType()==0){
                reslist.add(res);
            }else {
                if(res.getStopReasonType()==stic.getStopReasonType()){
                    reslist.add(res);
                }
            }*/
            reslist.add(res);
            if(!groupName.equals("none")){
                BanZu bz= (BanZu) bzmap.get(groupName);
                int nochargeNum=bz.getNochargeNum();
                bz.setNochargeNum(nochargeNum+1);
                bzmap.put(groupName,bz);
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setIII(1,reslist.size()>0,pageInfo,bzmap,"本年度未放电数量统计");
    }
    //2.获取电池组未放电记录(指定时间段的标准核容放电)
    private void getNoDischargeData(Integer battgroupId, Date testStartTime, Date testEndTime, List<Integer> typeList, SticDischarge6Res res) {
        List<BatttestdataInf> tinfList=mapper.getNoDischargeData(battgroupId,testStartTime,testEndTime,null);
        List<String> stopList=new ArrayList<>();
        if(tinfList!=null&&tinfList.size()>0){
            res.setErrorNum(tinfList.size());
            //res.setStopReasonType(1);
            for (int i=0;i<tinfList.size();i++) {
                BatttestdataInf tinf=tinfList.get(i);
                if(i==0){
                   res.setTestRecordCount(tinf.getTestRecordCount());
                   if (tinf.getTestType() == 3) {
                        // 测试类型为放电
                        if (tinf.getTestStarttype() == 3) {
                            res.setDischargeName("核容放电");
                        } else if(tinf.getTestStarttype() == 4){
                            res.setDischargeName("停电放电");
                        }else {
                            res.setDischargeName("监测放电");
                        }
                   }
                }
                String stopReason=StopReasonEnum.getValue(tinf.getTestStoptype());
                stopList.add(stopReason);
            }
            res.setStopList(stopList);
        }else {
            res.setErrorNum(0);
            res.setStopList(new ArrayList<>());
            //res.setStopReasonType(0);
        }
    }
    //获取核容停止原因类型(下拉)
    public Response getStopReasonType() {
        Map<String,Map<Integer,String>> map= StopReasonEnum.getOpInfo();
        return new Response().setII(1,true,map,"获取核容停止原因类型(下拉)");
    }
    //电池组电池性能统计(未放电,优秀,劣化,损坏)统计(1.2.8/9/10)
    public Response getPerformanceStatistic(PerformanceStic stic) {
        //获取核容优劣,损坏参数
        List<AppParam> paramList=appParamService.getHrParam();
        Float badValue=0f;
        Float damageValue=0f;
        if(paramList!=null){
            for (AppParam param:paramList) {
                if(param.getParamNamePsx().equals("batt_mon_deteriorate_val")){
                    badValue=param.getParamValue();
                }
                if(param.getParamNamePsx().equals("batt_mon_damage_val")){
                    damageValue=param.getParamValue();
                }
 
            }
        }
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getPerformanceStatistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<PerformanceRes> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            PerformanceRes res=new PerformanceRes();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setProduct(binf.getProduct());
            res.setInuseYear(ActionUtil.getDateYear(new Date())-ActionUtil.getDateYear(binf.getInuseTime())+1);
            res.setMonvolstd(binf.getMonvolstd());
            res.setMoncapstd(binf.getMoncapstd());
            res.setMoncount(binf.getMoncount());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setBattgroupId(binf.getBattgroupId());
            res.setDevId(binf.getDevId());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                res.setRealCap(0f);
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
            }else{
                //找这次放电的最后一笔数据
                List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
                if(idDataList==null||idDataList.size()==0){
                    res.setRealCap(0f);
                    res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_4.getStateId()));
                }else{
                    Float moncapStd=binf.getMoncapstd();
                    int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
                    Float grouprealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                    res.setRealCap(grouprealCap);
                    if(grouprealCap>=moncapStd*badValue){
                        res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_1.getStateId()));
                    }
                    if(grouprealCap<=moncapStd*damageValue){
                        res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_3.getStateId()));
                    }
                    if((grouprealCap>moncapStd*damageValue)&&(grouprealCap<moncapStd*badValue)){
                        res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
                    }
                }
            }
            if(res.getCapperformance().equals(BattCapperformanceEnum.getValue(stic.getPerformance()))){
                reslist.add(res);
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"电池组电池性能统计(未放电,优秀,劣化,损坏)统计(1.2.8/9/10)");
    }
    //电池组电池性能统计(劣化<按照单体电压+内阻统计>)统计(1.2.9)
    public Response getPerVolAndRes9Statistic(PerformanceStic stic) {
        //1查询符合条件的电池组
        List<BattInf> binfList=battInfService.getPerformanceStatistic(stic);
        if(binfList==null||binfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电池组");
        }
        List<PerformanceRes> reslist=new ArrayList<>();
        for (BattInf binf:binfList) {
            PerformanceRes res=new PerformanceRes();
            res.setProvice(binf.getProvice());
            res.setCity(binf.getCity());
            res.setCountry(binf.getCountry());
            res.setStationName(binf.getStationName());
            res.setBattgroupName(binf.getBattgroupName());
            res.setProduct(binf.getProduct());
            res.setInuseYear(ActionUtil.getDateYear(new Date())-ActionUtil.getDateYear(binf.getInuseTime())+1);
            res.setMonvolstd(binf.getMonvolstd());
            res.setMoncapstd(binf.getMoncapstd());
            res.setMoncount(binf.getMoncount());
            res.setStationId(binf.getStationId());
            res.setPowerId(binf.getPowerId());
            res.setBattgroupId(binf.getBattgroupId());
            res.setDevId(binf.getDevId());
            //2.获取电池组在给定时间段的放电记录(指定时间段的标准核容放电)
            BatttestdataInf tinf =getLastStandardTestDataByTime(binf.getBattgroupId(),stic.getTestStartTime(),stic.getTestEndTime());
            if(tinf==null){
                res.setRealCap(0f);
            }else{
                //找这次放电的最后一笔数据
                List<BatttestdataId> idDataList=battTestdataIdService.getLastDataByBattgroupId(tinf.getBattgroupId(),tinf.getTestRecordCount(),tinf.getRecordNum());
                if(idDataList==null||idDataList.size()==0){
                    res.setRealCap(0f);
                }else{
                    int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), tinf.getTestCurr());
                    Float grouprealCap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, tinf.getTestCap(), tinf.getMaxMonvol(), tinf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
                    res.setRealCap(grouprealCap);
                }
            }
            //查询当前电池组当前单体电压或者单体内阻低于其单体电压的下下限或高于上上限判定当前电池组劣化
            int flag = rtdataService.getVolAndRes(binf.getBattgroupId());
            if(flag==1){
                res.setCapperformance(BattCapperformanceEnum.getValue(BattCapperformanceEnum.BATTSTATE_2.getStateId()));
                reslist.add(res);
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"电池组电池性能统计(未放电,优秀,劣化,损坏)统计(1.2.8/9/10)");
    }
   //优良电源数量统计(1.2.7)
    public Response getPwr7Statistic(Pwr7Stic stic) throws NoSuchFieldException, IllegalAccessException {
        Date inuseTimeStart =new Date();
        if(stic.getInuseYear()==1){
            //投入使用时间条件筛选
            LocalDateTime startTime = LocalDateTime.now().minusYears(5);
            inuseTimeStart = DateUtil.convertToDate(startTime);
        }else{
            //投入使用时间条件筛选
            LocalDateTime startTime = LocalDateTime.now().minusYears(stic.getInuseYear());
            inuseTimeStart = DateUtil.convertToDate(startTime);
        }
        stic.setPwrInUseTime(inuseTimeStart);
        //1查询符合条件的电池组
        List<PowerInf> pinfList=powerInfService.getPwr7Statistic(stic);
        if(pinfList==null||pinfList.size()==0){
            return new Response().set(1,false,"当前用户未管理满足条件的电源");
        }
        List<SticPwr7Res> reslist=new ArrayList<>();
        for (PowerInf pinf:pinfList) {
            SticPwr7Res res = new SticPwr7Res();
            //查询电源所在的班组
            String groupName = bjService.getGroupName(pinf.getPowerId());
            if (stic.getGroupName() == null || groupName == stic.getGroupName()) {
                res.setProvice(pinf.getProvice());
                res.setCity(pinf.getCity());
                res.setCountry(pinf.getCountry());
                res.setStationName(pinf.getStationName());
                res.setPowerName(pinf.getPowerName());
                res.setCompany(pinf.getCompany());
                res.setStationType(pinf.getStationType());
                res.setGroupName(groupName);
                res.setInuseTime(pinf.getPowerInuseTime());
                Integer performance= pwrHisdataIdService.getPwrQuarter7(pinf.getPowerId(),pinf.getPowerType());
                res.setPerformanceName(PwrCapperformanceEnum.getValue(performance));
                if(stic.getPerformance()==null){
                    reslist.add(res);
                }else{
                    if(performance==stic.getPerformance()){
                        reslist.add(res);
                    }
                }
            }
        }
        PageInfo pageInfo=PageInfoUtils.list2PageInfo(reslist, stic.getPageNum(), stic.getPageSize());
        return new Response().setII(1,reslist.size()>0,pageInfo,"优良电源数量统计(1.2.7)");
    }
 
 
    public List<BatttestdataInf> getListByUserId(Integer userId) {
        return mapper.getListByUserId(userId);
    }
 
    public int getHrDisCount(Integer userId, Date startTime, Date endTime) {
        return mapper.getHrDisCount(userId, startTime, endTime);
    }
}