whyclxw
2025-03-21 0a46022762d6dd13dce54ae43dd8ff3bebe9688d
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
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
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.dto.*;
import com.whyc.dto.paramter.GroupTestCapPar;
import com.whyc.dto.result.GroupTestCapRes;
import com.whyc.dto.result.ReportBattTestDTO;
import com.whyc.mapper.*;
import com.whyc.pojo.*;
import com.whyc.util.ActionUtil;
import com.whyc.util.MessageUtils;
import com.whyc.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import java.time.Year;
import java.util.*;
import java.util.stream.Collectors;
 
@Service
public class BatttestdataInfService {
 
    @Resource
    private BatttestdataInfMapper mapper;
 
    @Resource
    private BattTestDataStopMapper stopMapper;
 
    @Resource
    private BattParamLowMapper battParamLowMapper;
 
    @Resource
    AlarmParamMapper alarmParamMapper;
 
    @Resource
    BattInfMapper binfMapper;
 
    @Resource
    BattalarmDataMapper alarmDataMapper;
 
    @Autowired
    private PageParamService pageParamService;
 
    @Autowired
    private SubTablePageInfoService subService;
 
    @Resource
    private BaoJiGroupMapper baoJiGroupMapper;
 
 
    //在线监测-历史监控-获取充放电记录
    public Response searchBattTestInfDataById(int battGroupId, int fbsDeviceId) {
        //查询出 4种类型的过滤时间值
        List<PageParam> pageParamList = pageParamService.getList2ByCategoryId(14);
        String lang = ActionUtil.getLang();
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("BattGroupId", battGroupId);
        wrapper.eq("data_available", 1);
        wrapper.orderByDesc("test_starttime");
        int judgeNum = mapper.judge(battGroupId);
        if (judgeNum > 0) {
            List<BatttestdataInf> list = mapper.selectList(wrapper);
            //过滤
            list = list.stream().filter(data->{
                Integer testType = data.getTestType();
                Integer testStarttype = data.getTestStarttype();
                Integer testDatatype = data.getTestDatatype();
                Integer testTimeLong = data.getTestTimelong();
                if (testType == 3) {
                    // 测试类型为放电
                    if (testStarttype == 3) {
                        //核容放电
                        if(testTimeLong>=pageParamList.get(0).getStatus()*60){
                            return true;
                        }else{
                            return false;
                        }
                    } else {
                        if (testDatatype==1) {
                            //停电放电
                            return true;
                        } else {
                            //监测放电
                            if(testTimeLong>=pageParamList.get(2).getStatus()*60){
                                return true;
                            }else{
                                return false;
                            }
                        }
                    }
                } else if (testType == 2) {
                    // 测试类型为充电
                    if (testStarttype == 3) {
                        //核容充电
                        if(testTimeLong>=pageParamList.get(1).getStatus()*60){
                            return true;
                        }else{
                            return false;
                        }
                    } else {
                        //监测充电
                        if(testTimeLong>=pageParamList.get(3).getStatus()*60){
                            return true;
                        }else{
                            return false;
                        }
                    }
                }else{
                    return true;
                }
            }).collect(Collectors.toList());
            list.stream().forEach(tinf -> {
                //放电终止原因
                if (fbsDeviceId / 10000 == 61850) {
                    //61850设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6185(tinf.getTestStoptype()));
                }else if(fbsDeviceId / 10000 == 61852) {
                    //61852设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_61852(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 4016) {
                    //6度设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_4016(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 9110) {
                    //假负载设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_9110(tinf.getTestStoptype()));
                } else if ((fbsDeviceId / 100000 == 9120) || (fbsDeviceId / 100000 == 9140)) {
                    // 逆变设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_9120(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 8059) {
                    //一体机设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_8059(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 6087) {
                    //电操核容设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6087(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 4830) {
                    //FBO4830设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_4830(tinf.getTestStoptype()));
                } else if (fbsDeviceId / 100000 == 4831) {
                    //FBO4831设备放电停止原因
                    tinf.setTestStoptypeReason(MessageUtils.getMessageSocket(BattTestData.getStopType_4831(tinf.getTestStoptype()), lang));
                } else if (fbsDeviceId / 100000 == 4815) {
                    //FBO4815设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_4815(tinf.getTestStoptype()));
                }  else if (fbsDeviceId / 100000 == 6001) {
                    //6001设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6001(tinf.getTestStoptype()));
                }else if ((fbsDeviceId / 10000 == 61853)||(fbsDeviceId / 100000 == 6186)||(fbsDeviceId / 100000 == 6286)) {
                    //61853设备放电停止原因
                    tinf.setTestStoptypeReason(BattTestData.getStopType_61853(tinf.getTestStoptype()));
                }else if((fbsDeviceId / 100000 == 6183)||(fbsDeviceId / 100000 == 6184)){
                    tinf.setTestStoptypeReason(BattTestData.getStopType_6183_4(tinf.getTestStoptype()));
                }else {
                    tinf.setTestStoptypeReason(BattTestData.getStopType(tinf.getTestStarttype(), tinf.getTestStoptype()));
                }
            });
            PageInfo pageInfo=new PageInfo(list);
            return new Response().set(1,pageInfo);
        }else{
            return new Response().set(0);
        }
    }
 
    //最后一次核容放电数据
    public Response searchBattLastHrDataById(int battGroupId, int devId, String lang) {
        PageHelper.startPage(1, 1);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("BattGroupId", battGroupId);
        wrapper.eq("data_available", 1);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last(" and (test_stoptype in (3, 4, 6) or (test_stoptype = 2 and test_timelong >= 7200)) ORDER BY test_starttime DESC ");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        List<BattTestDataStop> list = new ArrayList<BattTestDataStop>();
        if (tinf != null) {
            //放电终止原因
            if (devId / 10000 == 61850) {
                //61850设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6185(tinf.getTestStoptype()));
            }else if(devId / 10000 == 61852) {
                //61852设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_61852(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4016) {
                //6度设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4016(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9110) {
                //假负载设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9110(tinf.getTestStoptype()));
            } else if ((devId / 100000 == 9120) || (devId / 100000 == 9140)) {
                // 逆变设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9120(tinf.getTestStoptype()));
            } else if (devId / 100000 == 8059) {
                //一体机设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_8059(tinf.getTestStoptype()));
            } else if(devId / 100000 == 6087) {
                //电操核容设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6087(tinf.getTestStoptype()));
            }else if (devId / 100000 == 4830) {
                // FBO4830设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4830(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4831) {
                // FBO4830设备放电停止原因
                tinf.setTestStoptypeReason(MessageUtils.getMessageSocket(BattTestData.getStopType_4831(tinf.getTestStoptype()), lang));
            } else if (devId / 100000 == 4815) {
                //FBO4815设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4815(tinf.getTestStoptype()));
            } else if (devId / 100000 == 6001) {
                //6001设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6001(tinf.getTestStoptype()));
            } else if ((devId / 10000 == 61853)|| (devId / 100000 == 6186)|| (devId / 100000 == 6286)) {
                //61853设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_61853(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9149) {
                //FBO9149设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9149(tinf.getTestStoptype()));
            }else if (devId / 100000 == 9150) {
                //山东定制9150设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9150(tinf.getTestStoptype()));
            }else if((devId / 100000 == 6183)||(devId / 100000 == 6184)){
                tinf.setTestStoptypeReason(BattTestData.getStopType_6183_4(tinf.getTestStoptype()));
            }else {
                tinf.setTestStoptypeReason(BattTestData.getStopType(tinf.getTestStarttype(), tinf.getTestStoptype()));
            }
            //list = stopMapper.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            list = subService.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            tinf.setBatttestdataList(list);
        }
        return new Response().setII(1, tinf != null ? true : false, tinf, "");
    }
 
    //最后一次核容放电数据
    public Response searchBattLastHrDataByIdDbs(int battGroupId, int devId, String lang) {
        PageHelper.startPage(1, 1);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("BattGroupId", battGroupId);
        wrapper.eq("data_available", 1);
        wrapper.eq("test_type", 3);
        wrapper.eq("test_starttype", 3);
        wrapper.last(" and (test_stoptype in (3, 4, 6) or (test_stoptype = 2 and test_timelong >= 7200)) ORDER BY test_starttime DESC ");
        BatttestdataInf tinf = mapper.selectOne(wrapper);
        List<BattTestDataStop> list = new ArrayList<BattTestDataStop>();
        if (tinf != null) {
            //放电终止原因
            if (devId / 10000 == 61850) {//dbs为多宝山专用
                //61850设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6185DBS(tinf.getTestStoptype()));
            }else if(devId / 10000 == 61852) {
                //61852设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_61852(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4016) {
                //6度设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4016(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9110) {
                //假负载设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9110(tinf.getTestStoptype()));
            } else if ((devId / 100000 == 9120) || (devId / 100000 == 9140)) {
                // 逆变设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9120(tinf.getTestStoptype()));
            } else if (devId / 100000 == 8059) {
                //一体机设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_8059(tinf.getTestStoptype()));
            } else if(devId / 100000 == 6087) {
                //电操核容设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6087(tinf.getTestStoptype()));
            }else if (devId / 100000 == 4830) {
                // FBO4830设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4830(tinf.getTestStoptype()));
            } else if (devId / 100000 == 4831) {
                // FBO4830设备放电停止原因
                tinf.setTestStoptypeReason(MessageUtils.getMessageSocket(BattTestData.getStopType_4831(tinf.getTestStoptype()), lang));
            } else if (devId / 100000 == 4815) {
                //FBO4815设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_4815(tinf.getTestStoptype()));
            } else if (devId / 100000 == 6001) {
                //6001设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_6001(tinf.getTestStoptype()));
            } else if ((devId / 10000 == 61853)|| (devId / 100000 == 6186)|| (devId / 100000 == 6286)) {
                //61853设备放电停止原因和6186
                tinf.setTestStoptypeReason(BattTestData.getStopType_61853(tinf.getTestStoptype()));
            } else if (devId / 100000 == 9149) {
                //FBO9149设备放电停止原因
                tinf.setTestStoptypeReason(BattTestData.getStopType_9149(tinf.getTestStoptype()));
            } else {
                tinf.setTestStoptypeReason(BattTestData.getStopType(tinf.getTestStarttype(), tinf.getTestStoptype()));
            }
            //list = stopMapper.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            list = subService.getTestDataStop(tinf.getBattGroupId(), tinf.getTestStarttime());
            tinf.setBatttestdataList(list);
        }
        return new Response().setII(1, tinf != null ? true : false, tinf, "");
    }
 
    //报表分析使用
    public List<BatttestdataInf> searchByTestType(BatttestdataInf tinf){
        List<BatttestdataInf> list = mapper.searchByTestType(tinf);
        float cap = 0f;//实际容量
        float restcap = 0f;//剩余容量
        for (BatttestdataInf binf : list) {
            int hourRate = BattCapFactory.GetHourRate(tinf.getTestCap(), binf.getTestCurr());
            cap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, binf.getTestCap(), binf.getMaxMonvol(), binf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Real);
            restcap = (float) BattCapFactory.GetMonomerCap(tinf.getTestCap(), hourRate, binf.getTestCap(), binf.getMaxMonvol(), binf.getMinMonvol(), tinf.getGroupVol(), BattCapFactory.CapType_Rest);
            binf.setGroupVol(cap);
            ;
            binf.setMonVol(restcap);
        }
        return list;
    }
 
    //1.4电池组性能评估(根据电池组id查询所有的放电记录求出放电总次数,最高历史容量,最低历史容量,平均容量,最新测试容量)
    public Map<String, Object> searchDischargeTest(Integer battGroupId, float monCapStd, float monVolStd, Date recordStartTime, Date recordEndTime,int wj) {
        List<BatttestdataInf> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        if(wj==0){//本年
            list=mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
            if( list.size()==0){
                map.put("wj", "N");
            }else{
                map.put("wj", "J");
            }
        }else if(wj==1){//往年
            list = mapper.searchDischargeTest_WJ(battGroupId, recordStartTime);
            if( list.size()==0){
                map.put("wj", "N");
            }else{
                map.put("wj", "W");
            }
        }else if(wj==-1){//全部
            list=mapper.searchDischargeTest(battGroupId, recordStartTime, recordEndTime);
            if( list.size()==0){
                list = mapper.searchDischargeTest_WJ(battGroupId, recordStartTime);
                if( list.size()==0){
                    map.put("wj", "N");
                }else{
                    map.put("wj", "W");
                }
            }else{
                map.put("wj", "J");
            }
        }
        List<BatttestdataInf> testList = new LinkedList<>();
        int sum = 0;//总测试次数
        float cap = 0f;//实际容量
        float allCap = 0f;//总容量
        float maxCap = 0f;//最高容量
        float minCap = 10000f;//最低容量
        float avgCap = 0f;//平均容量
        float lastCap = 0f;//最近测试容量
        for (int i = 0; i < list.size(); i++) {
            BatttestdataInf binf = list.get(i);
            int hourRate = BattCapFactory.GetHourRate(monCapStd, binf.getTestCurr());
            cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, binf.getTestCap(), binf.getMaxMonvol(), binf.getMinMonvol(), monVolStd, BattCapFactory.CapType_Real);
            binf.setRealCap(cap);
            testList.add(binf);
            if (sum == 0) {
                lastCap = cap;
            }
            if (maxCap <= cap) {
                maxCap = cap;//最大
            }
            if (minCap >= cap) {
                minCap = cap;//最小
            }
            allCap += cap;
            sum++;
        }
        if (sum != 0) {
            avgCap = allCap / sum;//平均容量
        } else {
            avgCap = 0;
            minCap = 0;
        }
        map.put("battGroupid", battGroupId);
        map.put("sum", sum);
        map.put("maxCap", maxCap);
        map.put("avgCap", avgCap);
        map.put("minCap", minCap);
        map.put("lastCap", lastCap);
        map.put("testList", testList);
        return map;
    }
 
    public Response searchBattLifeNow(int pageNum,int pageSize,Battinf binf){
        PageHelper.startPage(pageNum,pageSize);
        List<BattState> list = mapper.searchBattLifeNow(binf);
        PageInfo<BattState> pageInfo = new PageInfo<>(list);
        return new Response().set(1,pageInfo,"查询成功");
    }
 
    public Response searchBattLife(int pageNum,int pageSize,Battinf binf){
        //PageHelper.startPage(pageNum,pageSize);
        List<ReportBattTestDTO> list = mapper.searchBattLife(binf);
        float param = 0;//容量有效参数
        double STDAH = 0;//标存容量
        BattParamLow capLow=new BattParamLow();
        capLow.setLowType(BattCapFactory.CapType_type);;
        capLow.setLowNametype(BattCapFactory.CapType_name);
        capLow.setLowMethod(BattCapFactory.CapType_method);
        List<BattParamLow> listC = battParamLowMapper.serchByLow(capLow);
        if (listC!=null && listC.size()>0){
            param = listC.get(listC.size()-1).getLowValue();
        }
        int flag=0;//该次放电是否有效判断
        List<ReportBattTestDTO> listE=new ArrayList();//存放放电有效的测试
        //当前页记录列表
        LinkedList<ReportBattTestDTO> data = new LinkedList<>();
        //对结果进行分页
        Page page = new Page();
        if (list!=null &&list.size()>0){
            for(int i=0;i<list.size();i++){
                if (list.get(i).getBinf().getMonCapStd() != null) {
                    STDAH = list.get(i).getBinf().getMonCapStd();
                }
                float testCap=list.get(i).getTdata().getTestCap();//此次放电量统计
                //System.out.println(list.get(i).getTdata().getBattGroupId()+"  "+list.get(i).getTdata().getTest_record_count()+"   "+testCap+"  "+param+"  "+STDAH);
                flag=BattCapFactory.Judge(testCap, param, STDAH);
                if(flag==1){
                    if(listE.size()>0){
                        int tdata_battgroupid=list.get(i).getTdata().getBattGroupId();
                        int e_battgroupid=listE.get(listE.size()-1).getTdata().getBattGroupId();
                        if(tdata_battgroupid!=e_battgroupid){
                            listE.add(list.get(i));
                        }else{
                            continue;
                        }
                    }else{
                        listE.add(list.get(i));
                    }
                    flag=0;
                }
            }
 
            page.setPageCurr(pageNum);
            page.setPageSize(pageSize);
            //总页数
            page.setPageAll(listE.size());
            if(listE.size()>pageSize*pageNum) {
                for (int i = (pageNum-1)*pageSize; i < pageSize*pageNum; i++) {
                    data.add(listE.get(i));
                }
            }else {
                int a1 = (pageNum - 1) * pageSize;
                int a2 = (listE.size() - ((pageNum - 1) * pageSize));
                for (int i = (pageNum - 1) * pageSize; i < listE.size(); i++) {
                    data.add(listE.get(i));
                }
            }
        }
        page.setData(data);
        return new Response().set(1, page, "查询成功");
    }
 
    //统计时间段内设备的测试容量
    public Response searchGroupTestCap(GroupTestCapPar groupCapPar) {
        PageHelper.startPage(groupCapPar.getPageCurr(), groupCapPar.getPageSize());
        List<GroupTestCapRes> list = mapper.searchGroupTestCap(groupCapPar);
        PageInfo pageInfo = new PageInfo(list);
        return new Response().setII(1, list.size() > 0 ? true : false, pageInfo, "统计时间段内设备的测试容量");
    }
 
    //管理员首页头部信息加入
    public int getYearAnalysis(int userId) {
        //Map<String, Integer> map = new HashMap<>();
        //本年已核容放电电池组数
        int hrdisNum = mapper.getHrQuarterZC(userId);
        //本年已停电放电电池组数
        //int jcdisNum = mapper.getJcQuarter(userId);
        //map.put("hrdisNum", hrdisNum);
        // map.put("jcdisNum", jcdisNum);
        return hrdisNum;
    }
 
    //获取本年已核容电池组
    public Response getHrYeardisBatt() {
        UserInf uinf = ActionUtil.getUser();
        String userId = uinf.getUId().toString();
        List<Battinf> list = mapper.getHrYeardisBatt(userId);
        return new Response().setII(1, list.size() > 0, list, "获取本年已核容电池组");
    }
 
    //获取实时停电放电电池组
    public Response getJcdisBatt() {
        UserInf uinf = ActionUtil.getUser();
        String userId = uinf.getUId().toString();
        List<Battinf> list = mapper.getJcdisBatt(userId);
        for (Battinf binf : list) {
            int battgroupId = 0;
            battgroupId = binfMapper.searchBattGroupId(binf.getStationId());
            binf.setBattGroupId(battgroupId);
        }
        return new Response().setII(1, list.size() > 0, list, "获取本年已核容电池组");
    }
 
    //测试信息
    @Transactional
    public Response getTestdataInfAnalysis(int userId) {
        try {
            Map<String, Object> map = new HashMap<>();
            //本月数据
            List<BatttestdataInf> listMonth = mapper.selectMonth(userId);
            map.put("month", analysisTestData(listMonth));
            //本季度
            List<BatttestdataInf> listQuarter = mapper.selectQuarter(userId);
            map.put("quarter", analysisTestData(listQuarter));
            //本年
            List<BatttestdataInf> listYear = mapper.selectYear(userId);
            map.put("year", analysisTestData(listYear));
            return new Response().setII(1, true, map, "测试信息");
        } catch (Exception e) {
            return new Response().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    /*管理员首页统计测试信息
    if (testType == 3) {
        // 测试类型为放电
        if (testStarttype == 3) {
            核容放电
        } else {
            if (testDatatype==1) {
                停电放电 1
            } else {
                监测放电  0
            }
        }
    } else if (testType == 2) {
        // 测试类型为充电
        if (testStarttype == 3) {
            核容充电
        } else {
            监测充电
        }
    }*/
    public Map<String, Integer> analysisTestData(List<BatttestdataInf> list) {
        List<PageParam> pageParamList = pageParamService.getList2ByCategoryId(14);
        Map<String, Integer> map = new HashMap<>();
        int hrdisNum = 0;//核容放电
        int jcdisNum = 0;//监测放电
        int jcchNum = 0;//监测充电
        int dddisNum = 0;//停电放电
        int hrchNum = 0;//核容充电
        if (list != null && list.size() > 0) {
            for (BatttestdataInf tinf : list) {
                if (tinf.getTestType() == 3) {
                    // 测试类型为放电
                    if (tinf.getTestStarttype() == 3) {
                        if ((tinf.getTestStoptype() == 3 || tinf.getTestStoptype() == 4 || tinf.getTestStoptype() == 6) ||
                                (tinf.getTestStoptype() == 2 && tinf.getTestTimelong() >= 7200)) {
                            hrdisNum += 1;
                        }
                    } else {
                        if (tinf.getTestDatatype() == 1) {
                            dddisNum += 1;
                        }
                        if (tinf.getTestDatatype() == 0) {
                            if(tinf.getTestTimelong()>=pageParamList.get(2).getStatus()*60) {
                                jcdisNum += 1;
                            }
                        }
                    }
                } else if (tinf.getTestType() == 2) {
                    // 测试类型为充电
                    if (tinf.getTestStarttype() == 3) {
                        hrchNum += 1;
                    } else {
                        if(tinf.getTestTimelong()>=pageParamList.get(3).getStatus()*60) {
                            jcchNum += 1;
                        }
                    }
                }
            }
        }
 
        map.put("hrdisNum", hrdisNum);
        map.put("hrchNum", hrchNum);
        map.put("jcdisNum", jcdisNum);
        map.put("dddisNum", dddisNum);
        map.put("jcchNum", jcchNum);
        return map;
    }
 
    //查询今天所有正在放电的机房总数
    public int getPlanStaticToday(int userId) {
        int num = mapper.getPlanStaticToday(userId);
        return num;
    }
 
    //本年度核容放电电池组(testdate_inf中test_type=3,test_startType=3)
    public int getHrQuarter(int userId) {
        //本年度
        int hrQuarter = mapper.getHrQuarter(userId);
        return hrQuarter;
    }
 
    /*领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止
                并且放电时间超过2小时*/
    public int getHrQuarterZC(int userId) {
        int hrQuarter = mapper.getHrQuarterZC(userId);
        return hrQuarter;
    }
 
    //山西晋源特定接口
    public int getHrQuarterZCJY() {
        int hrQuarter = mapper.getHrQuarterZCJY();
        return hrQuarter;
    }
 
 
    //蓄电池组优劣分析(用蓄电池组组后评估的统计)
    public Response getGroupAnalysis(int userId) {
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //小于capAlarm
            int alarmNum = 0;
            //小于capChange
            int changeNum = 0;
            //放电正常
            int goodSum = 0;
            //未正常
            int noHrDisNum = 0;
 
            //去年的数据----------------
            //小于capAlarm
            int oldalarmNum = 0;
            //小于capChange
            int oldchangeNum = 0;
            //放电正常
            int oldgoodSum = 0;
            //未正常
            int oldnoHrDisNum = 0;
 
            //0.查询所有的电池组
            List<Battinf> binfList = binfMapper.getBinfList(userId);
            if (binfList != null && binfList.size() > 0) {
                for (Battinf binf : binfList) {
                    //实际容量
                    float cap = 0f;
                    //实际容量去年
                    float oldcap = 0f;
                    int battgroupId = binf.getBattGroupId();
                    float monCapStd = binf.getMonCapStd();
                    float monVolstd = binf.getMonVolStd();
                    //放电次数
                    int disNum = 0;
                    int olddisNum = 0;
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(本年度)
                    BatttestdataInf inf = mapper.getGroupAnalysisQB(battgroupId);
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(上一年度)
                    BatttestdataInf oldinf = mapper.getGroupAnalysisQBOld(battgroupId);
                    if (inf != null) {
                        disNum = 1;
                        int hourRate = BattCapFactory.GetHourRate(monCapStd, inf.getTestCurr());
                        cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    if(oldinf!=null){
                        olddisNum=1;
                        int oldhourRate = BattCapFactory.GetHourRate(monCapStd, oldinf.getTestCurr());
                        oldcap = (float) BattCapFactory.GetMonomerCap(monCapStd, oldhourRate, oldinf.getTestCap(), oldinf.getMaxMonvol(), oldinf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    //查询电池告警(劣化:内阻过高重要,电压过低重要;损坏:内阻过高紧急,电压过低紧急)
                    List listALmSH = alarmDataMapper.getAlm(battgroupId, 3);
                    List listALmLH = alarmDataMapper.getAlm(battgroupId, 2);
                    //先判断是否损坏
                    if ((disNum != 0 && cap < capChange * monCapStd) || (listALmSH != null && listALmSH.size() > 0)) {
                        if (disNum == 0) {
                            noHrDisNum += 1;
                        }
                        changeNum = changeNum + 1;
                    }//在判断是否劣化
                    else if (
                            (disNum != 0 && cap <= capAlarm * monCapStd && cap >= capChange * monCapStd
                            )
                                    || (listALmLH != null && listALmLH.size() > 0)) {
                        if (disNum == 0) {
                            noHrDisNum += 1;
                        }
                        alarmNum = alarmNum + 1;
                    }//再判断是否放电正常
                    else if (disNum != 0 && cap > capAlarm * monCapStd) {
                        if (disNum == 0) {
                            noHrDisNum += 1;
                        }
                        goodSum = goodSum + 1;
                    } else {
                        noHrDisNum += 1;
                    }
                    //去年-----------------的数据
                    //先判断是否损坏
                    if ((olddisNum != 0 && oldcap < capChange * monCapStd) || (listALmSH != null && listALmSH.size() > 0)) {
                        if (olddisNum == 0) {
                            oldnoHrDisNum += 1;
                        }
                       oldchangeNum = oldchangeNum + 1;
                    }//在判断是否劣化
                    else if (
                            (olddisNum != 0 && oldcap <= capAlarm * monCapStd && oldcap >= capChange * monCapStd
                            )
                                    || (listALmLH != null && listALmLH.size() > 0)) {
                        if (olddisNum == 0) {
                            oldnoHrDisNum += 1;
                        }
                        oldalarmNum = oldalarmNum + 1;
                    }//再判断是否放电正常
                    else if (olddisNum != 0 && oldcap > capAlarm * monCapStd) {
                        if (olddisNum == 0) {
                            oldnoHrDisNum += 1;
                        }
                        oldgoodSum = oldgoodSum + 1;
                    } else {
                        oldnoHrDisNum += 1;
                    }
                }
            }
            Map<String, Integer> numMap = new HashMap<>();
            numMap.put("alarmNum", alarmNum);
            numMap.put("changeNum", changeNum);
            //总电池组(分类)
            int groupNum = binfMapper.geGroupCount(userId);
            numMap.put("groupNum", groupNum);
            /*//已放电电池组数
            int inDischargeNum = binfMapper.searchInDischarge(userId);*/
            //蓄电池优良(已经放电数-告警数)
            numMap.put("goodSum", goodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            //int hrDisNum = mapper.getHrQuarterZC(userId);
            numMap.put("noHrDisNum", noHrDisNum);
           //去年----------------------------统计
            Map<String, Integer> oldnumMap = new HashMap<>();
            oldnumMap.put("alarmNum", oldalarmNum);
            oldnumMap.put("changeNum", oldchangeNum);
            //总电池组(分类)
            oldnumMap.put("groupNum", groupNum);
            //蓄电池优良(已经放电数-告警数)
            oldnumMap.put("goodSum", oldgoodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            oldnumMap.put("noHrDisNum", oldnoHrDisNum);
 
            return new Response().setIII(1, true, numMap,oldnumMap, "蓄电池组优劣分析");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    //蓄电池组优劣分析(用蓄电池组组后评估的统计)
    public Response getGroupAnalysis2(int userId) {
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //获取当前年
            int year = Year.now().getValue();
            Date nowDateStart=ThreadLocalUtil.parse(year+"-01-01 00:00:00",1);
            Date nowDateEnd=ThreadLocalUtil.parse(year+"-12-31 23:59:59",1);
            Date oldDateStart=ThreadLocalUtil.parse((year-1)+"-01-01 00:00:00",1);
            Date oldDateEnd=ThreadLocalUtil.parse((year-1)+"-12-31 23:59:59",1);
            //小于capAlarm
            int alarmNum = 0;
            //小于capChange
            int changeNum = 0;
            //放电正常
            int goodSum = 0;
            //未正常
            int noHrDisNum = 0;
 
            //去年的数据----------------
            //小于capAlarm
            int oldalarmNum = 0;
            //小于capChange
            int oldchangeNum = 0;
            //放电正常
            int oldgoodSum = 0;
            //未正常
            int oldnoHrDisNum = 0;
 
            //0.查询所有的电池组
            List<Battinf> binfList = binfMapper.getBinfList(userId);
            if (binfList != null && binfList.size() > 0) {
                for (Battinf binf : binfList) {
                    //实际容量
                    float cap = 0f;
                    float oldcap = 0f;
 
                    //放电次数
                    int disNum = 0;
                    int olddisNum = 0;
 
                    int battgroupId = binf.getBattGroupId();
                    float monCapStd = binf.getMonCapStd();
                    float monVolstd = binf.getMonVolStd();
 
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(本年度)
                    BatttestdataInf inf = mapper.getGroupAnalysisQB_WJ(battgroupId,nowDateStart,nowDateEnd);
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(上一年度)
                    BatttestdataInf oldinf = mapper.getGroupAnalysisQB_WJ(battgroupId,oldDateStart,oldDateEnd);
                    if (inf != null) {
                        disNum=1;
                        int hourRate = BattCapFactory.GetHourRate(monCapStd, inf.getTestCurr());
                        cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    if(oldinf!=null){
                        olddisNum=1;
                        int oldhourRate = BattCapFactory.GetHourRate(monCapStd, oldinf.getTestCurr());
                        oldcap = (float) BattCapFactory.GetMonomerCap(monCapStd, oldhourRate, oldinf.getTestCap(), oldinf.getMaxMonvol(), oldinf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    //查询电池告警内阻告警
                    List listALmRes = alarmDataMapper.getAlm2(battgroupId);
                        //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----本年度
                        if( (disNum==0) ){
                            noHrDisNum+=1;
                        }
                        //优秀:本年度已放电,且容量健康,无内阻告警(预告警(重要),告警(紧急))
                        if( (disNum>0)&&(cap > capAlarm * monCapStd)&&(listALmRes.size()<=0)){
                            goodSum+=1;
                        }
                        /*劣化:本年度未放电,内阻告警(预告警(重要),告警(紧急))
                         *容量小于劣化阈值,大于损坏阈值,内阻告警(预告警,告警)
                         *     容量小于劣化阈值,内阻正常
                         *     容量正常,内阻告警(预告警,告警)
                         */
                        if (((disNum==0)&&(listALmRes.size()>0))
                                ||((disNum>0)&&(cap <= capAlarm * monCapStd && cap >= capChange * monCapStd)&&(listALmRes.size()>0))
                                ||((disNum>0)&&(cap <= capAlarm * monCapStd)&&(listALmRes.size()<=0))
                                ||(disNum>0)&&(cap > capAlarm * monCapStd)&&(listALmRes.size()>0)){
                            alarmNum+=1;
                        }
                        //损坏:容量低,内阻告警
                        if((disNum>0)&&(cap< capChange * monCapStd)&&(listALmRes.size()>0)){
                            changeNum+=1;
                        }
 
                        //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----其他年度
                        if( (olddisNum==0) ){
                            oldnoHrDisNum+=1;
                        }
                        //优秀:本年度已放电,且容量健康,无内阻告警(预告警(重要),告警(紧急))
                        if( (olddisNum>0)&&(oldcap > capAlarm * monCapStd)&&(listALmRes.size()<=0)){
                            oldgoodSum+=1;
                        }
                        /*劣化:本年度未放电,内阻告警(预告警(重要),告警(紧急))
                         *容量小于劣化阈值,大于损坏阈值,内阻告警(预告警,告警)
                         *     容量小于劣化阈值,内阻正常
                         *     容量正常,内阻告警(预告警,告警)
                         */
                        if (((olddisNum==0)&&(listALmRes.size()>0))
                                ||((olddisNum>0)&&(oldcap <= capAlarm * monCapStd && oldcap >= capChange * monCapStd)&&(listALmRes.size()>0))
                                ||((olddisNum>0)&&(oldcap <= capAlarm * monCapStd)&&(listALmRes.size()<=0))
                                ||(olddisNum>0)&&(oldcap > capAlarm * monCapStd)&&(listALmRes.size()>0)){
                            oldalarmNum+=1;
                        }
                        //损坏:容量低,内阻告警
                        if((olddisNum>0)&&(oldcap< capChange * monCapStd)&&(listALmRes.size()>0)){
                            oldchangeNum+=1;
                        }
                    }
 
            }
            Map<String, Integer> numMap = new HashMap<>();
            numMap.put("alarmNum", alarmNum);
            numMap.put("changeNum", changeNum);
            //总电池组(分类)
            int groupNum = binfMapper.geGroupCount(userId);
            numMap.put("groupNum", groupNum);
            /*//已放电电池组数
            int inDischargeNum = binfMapper.searchInDischarge(userId);*/
            //蓄电池优良(已经放电数-告警数)
            numMap.put("goodSum", goodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            //int hrDisNum = mapper.getHrQuarterZC(userId);
            numMap.put("noHrDisNum", noHrDisNum);
            //去年----------------------------统计
            Map<String, Integer> oldnumMap = new HashMap<>();
            oldnumMap.put("alarmNum", oldalarmNum);
            oldnumMap.put("changeNum", oldchangeNum);
            //总电池组(分类)
            oldnumMap.put("groupNum", groupNum);
            //蓄电池优良(已经放电数-告警数)
            oldnumMap.put("goodSum", oldgoodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            oldnumMap.put("noHrDisNum", oldnoHrDisNum);
 
            return new Response().setIII(1, true, numMap,oldnumMap, "蓄电池组优劣分析");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    //蓄电池组优劣分析(用蓄电池组组后评估的统计)
    public Response getGroupAnalysis3(int userId) {
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //获取当前年
            int year = Year.now().getValue();
            Date nowDateStart=ThreadLocalUtil.parse(year+"-01-01 00:00:00",1);
            Date nowDateEnd=ThreadLocalUtil.parse(year+"-12-31 23:59:59",1);
            Date oldDateStart=ThreadLocalUtil.parse((year-1)+"-01-01 00:00:00",1);
            Date oldDateEnd=ThreadLocalUtil.parse((year-1)+"-12-31 23:59:59",1);
            //小于capAlarm
            int alarmNum = 0;
            //小于capChange
            int changeNum = 0;
            //放电正常
            int goodSum = 0;
            //未正常
            int noHrDisNum = 0;
 
            //去年的数据----------------
            //小于capAlarm
            int oldalarmNum = 0;
            //小于capChange
            int oldchangeNum = 0;
            //放电正常
            int oldgoodSum = 0;
            //未正常
            int oldnoHrDisNum = 0;
 
            //0.查询所有的电池组
            List<Battinf> binfList = binfMapper.getBinfList(userId);
            if (binfList != null && binfList.size() > 0) {
                for (Battinf binf : binfList) {
                    //实际容量
                    float cap = 0f;
                    float oldcap = 0f;
 
                    //放电次数
                    int disNum = 0;
                    int olddisNum = 0;
 
                    int battgroupId = binf.getBattGroupId();
                    float monCapStd = binf.getMonCapStd();
                    float monVolstd = binf.getMonVolStd();
 
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(本年度)
                    BatttestdataInf inf = mapper.getGroupAnalysisQB_WJ(battgroupId,nowDateStart,nowDateEnd);
                    //1.查出符合条件的电池组(核容数据)按照时间倒叙排序的第一个(上一年度)
                    BatttestdataInf oldinf = mapper.getGroupAnalysisQB_WJ(battgroupId,oldDateStart,oldDateEnd);
                    if (inf != null) {
                        disNum=1;
                        int hourRate = BattCapFactory.GetHourRate(monCapStd, inf.getTestCurr());
                        cap = (float) BattCapFactory.GetMonomerCap(monCapStd, hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    if(oldinf!=null){
                        olddisNum=1;
                        int oldhourRate = BattCapFactory.GetHourRate(monCapStd, oldinf.getTestCurr());
                        oldcap = (float) BattCapFactory.GetMonomerCap(monCapStd, oldhourRate, oldinf.getTestCap(), oldinf.getMaxMonvol(), oldinf.getMinMonvol(), monVolstd, BattCapFactory.CapType_Real);
                    }
                    //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----本年度
                    if( (disNum==0) ){
                        noHrDisNum+=1;
                    }
                    //优秀:本年度已放电,且容量健康)
                    if( (disNum>0)&&(cap > capAlarm * monCapStd)){
                        goodSum+=1;
                    }
                    /*劣化:
                     *容量小于劣化阈值,大于损坏阈值
                     */
                    if (((disNum>0)&&(cap <= capAlarm * monCapStd && cap >= capChange * monCapStd))){
                        alarmNum+=1;
                    }
                    //损坏:容量低
                    if((disNum>0)&&(cap< capChange * monCapStd)){
                        changeNum+=1;
                    }
 
                    //未放电:本年度未放电,且无内阻告警<13,14>(预告警(重要),告警(紧急))-----其他年度
                    if( (olddisNum==0) ){
                        oldnoHrDisNum+=1;
                    }
                    //优秀:本年度已放电,且容量健康)
                    if( (olddisNum>0)&&(oldcap > capAlarm * monCapStd)){
                        oldgoodSum+=1;
                    }
                    /*劣化
                     *容量小于劣化阈值,大于损坏阈值
                     *
                     */
                    if (((olddisNum>0)&&(oldcap <= capAlarm * monCapStd && oldcap >= capChange * monCapStd))){
                        oldalarmNum+=1;
                    }
                    //损坏:容量低
                    if((olddisNum>0)&&(oldcap< capChange * monCapStd)){
                        oldchangeNum+=1;
                    }
                }
 
            }
            Map<String, Integer> numMap = new HashMap<>();
            numMap.put("alarmNum", alarmNum);
            numMap.put("changeNum", changeNum);
            //总电池组(分类)
            int groupNum = binfMapper.geGroupCount(userId);
            numMap.put("groupNum", groupNum);
            /*//已放电电池组数
            int inDischargeNum = binfMapper.searchInDischarge(userId);*/
            //蓄电池优良(已经放电数-告警数)
            numMap.put("goodSum", goodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            //int hrDisNum = mapper.getHrQuarterZC(userId);
            numMap.put("noHrDisNum", noHrDisNum);
            //去年----------------------------统计
            Map<String, Integer> oldnumMap = new HashMap<>();
            oldnumMap.put("alarmNum", oldalarmNum);
            oldnumMap.put("changeNum", oldchangeNum);
            //总电池组(分类)
            oldnumMap.put("groupNum", groupNum);
            //蓄电池优良(已经放电数-告警数)
            oldnumMap.put("goodSum", oldgoodSum);
             /*本年度已核容放电电池组(testdate_inf中test_type=3,test_startType=3)
             int hrDisNum = testInfService.getHrQuarter(userId);
            * 修改为:领导层本年度已放数 仅需要统计放电正常停止的 正常停止的条件如下:
                stop_type:
                2-放电时间到终止并且放电时间超过2小时
                3-放电容量到终止
                4-单体电压下限到终止
                6-组端电压下限到终止*/
            oldnumMap.put("noHrDisNum", oldnoHrDisNum);
 
            return new Response().setIII(1, true, numMap,oldnumMap, "蓄电池组优劣分析");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
    //获取本年已核容放电电池组最新一次数据详情
    public Response getHrYeardisBattInfo() {
        int userId = Integer.parseInt(ActionUtil.getUser().getUId().toString());
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //1.查出符合条件的电池组(核容数据)按照时间倒叙排序
            List<BatttestdataInf> list = mapper.getGroupAnalysis(userId);
            //2.分组取出每个电池组的最新一笔数据(取电池组放电数据的第一个)
            List<BatttestdataInf> infoList = new ArrayList<>();
            String battGroupId = "0";
            if (list != null && list.size() > 0) {
                for (BatttestdataInf inf : list) {
                    if (!battGroupId.equals(inf.getBattGroupId().toString())) {
                        int hourRate = BattCapFactory.GetHourRate(inf.getMonCapStd(), inf.getTestCurr());
                        float cap = (float) BattCapFactory.GetMonomerCap(inf.getMonCapStd(), hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), inf.getMonVolStd(), BattCapFactory.CapType_Real);
                        inf.setRealCap(cap);
                        infoList.add(inf);
                        battGroupId = inf.getBattGroupId().toString();
                    }
                }
            }
 
            return new Response().setII(1, true, infoList, "获取本年已核容放电电池组最新一次数据详情");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    //获取本年已核容放电电池组最新一次数据详情(正常)
    public Response getHrYeardisBattInfoZC() {
        int userId = Integer.parseInt(ActionUtil.getUser().getUId().toString());
        String lang = ActionUtil.getLang();
        try {
            //0.查询劣化(告警)和损坏(更换)的阈值
            QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
            alarmWrapper.and(wrapper -> {
                return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
            });
            alarmWrapper.orderByAsc("alm_id");
            List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
            float capAlarm = 0f;
            float capChange = 0f;
            if (paramList != null && paramList.size() > 0) {
                capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
                capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
            } else {
                capAlarm = 0.8f;
                capChange = 0.6f;
            }
            //1.查出符合条件的电池组(核容数据)按照时间倒叙排序
            List<BatttestdataInf> list = mapper.getGroupAnalysisZC(userId);
            //2.分组取出每个电池组的最新一笔数据(取电池组放电数据的第一个)
            List<BatttestdataInf> infoList = new ArrayList<>();
            String battGroupId = "0";
            if (list != null && list.size() > 0) {
                for (BatttestdataInf inf : list) {
                    if (!battGroupId.equals(inf.getBattGroupId().toString())) {
                        int hourRate = BattCapFactory.GetHourRate(inf.getMonCapStd(), inf.getTestCurr());
                        float cap = (float) BattCapFactory.GetMonomerCap(inf.getMonCapStd(), hourRate, inf.getTestCap(), inf.getMaxMonvol(), inf.getMinMonvol(), inf.getMonVolStd(), BattCapFactory.CapType_Real);
                        inf.setRealCap(cap);
                        //放电终止原因
                        if (inf.getFBSDeviceId() / 10000 == 61850) {
                            //61850设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_6185(inf.getTestStoptype()));
                        }else if(inf.getFBSDeviceId() / 10000 == 61852) {
                            //61852设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_61852(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 4016) {
                            //6度设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_4016(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 9110) {
                            //假负载设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_9110(inf.getTestStoptype()));
                        } else if ((inf.getFBSDeviceId() / 100000 == 9120) || (inf.getFBSDeviceId() / 100000 == 9140)) {
                            // 逆变设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_9120(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 8059) {
                            //一体机设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_8059(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 6087) {
                            //电操核容设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_6087(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 4830) {
                            //FBO4830设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_4830(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 4831) {
                            //FBO4831设备放电停止原因
                            inf.setTestStoptypeReason(MessageUtils.getMessageSocket(BattTestData.getStopType_4831(inf.getTestStoptype()), lang));
                        } else if (inf.getFBSDeviceId() / 100000 == 4815) {
                            //FBO4815设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_4815(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 6001) {
                            //6001设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_6001(inf.getTestStoptype()));
                        } else if ((inf.getFBSDeviceId() / 10000 == 61853)||(inf.getFBSDeviceId() / 100000 == 6186)||(inf.getFBSDeviceId() / 100000 == 6286)) {
                            //61853设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_61853(inf.getTestStoptype()));
                        } else if (inf.getFBSDeviceId() / 100000 == 9149) {
                            //FBO4815设备放电停止原因
                            inf.setTestStoptypeReason(BattTestData.getStopType_9149(inf.getTestStoptype()));
                        } else {
                            inf.setTestStoptypeReason(BattTestData.getStopType(inf.getTestStarttype(), inf.getTestStoptype()));
                        }
                        infoList.add(inf);
                        battGroupId = inf.getBattGroupId().toString();
                    }
                }
            }
 
            return new Response().setII(1, true, infoList, "获取本年已核容放电电池组最新一次数据详情正常");
        } catch (Exception e) {
            return new Response<>().set(1, false, "发生异常:" + e.getCause());
        }
    }
 
    //本年度上一次正常核容的放电记录编号
    public Response searchHrYear(int battGroupId) {
        BatttestdataInf tinf = mapper.searchHrYear(battGroupId);
        int testNumber = 0;
        if (tinf != null) {
            testNumber = tinf.getNum();
        }
        return new Response().setII(1, true, testNumber, "本年度上一次正常核容的放电记录编号");
    }
    //能效统计
    public Response getEnergyStatistics(int year) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        List<GroupTestCapRes> list=mapper.getEnergyStatistics(date1,date2);
        Map<Integer,Integer> sCountMap=new HashMap<>();
        Map<Integer,String> sCapMap=new HashMap<>();
        for (int i=0;i<year;i++){
            sCountMap.put(lastYear+i,0);
            sCapMap.put(lastYear+i,"0");
        }
        Map<Integer, List<GroupTestCapRes>> yearMap = list.stream().collect(Collectors.groupingBy(GroupTestCapRes::getYearTime));
        for (Integer yearTime : yearMap.keySet()) {
            sCountMap.put(yearTime,yearMap.get(yearTime).size());
            List<GroupTestCapRes> groupList=yearMap.get(yearTime);
            Double sum = groupList.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
            sCapMap.put(yearTime,String.format("%.3f",sum));
        }
        return new Response().setIII(1, true, sCountMap,sCapMap, "能效统计");
    }
 
    //能效统计分班组
    public Response getEnergyStatisticsInBaojiGroup(int year) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        //1.查询出所有的班组
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("discharge_plan_flag",1);
        List<BaoJiGroup> listbj=baoJiGroupMapper.selectList(wrapper);
        List<EnergyStatisticDto> listeg=new ArrayList<>();
        if(listbj!=null&&listbj.size()>0){
            for (BaoJiGroup bj:listbj) {
                EnergyStatisticDto egDto=new EnergyStatisticDto();
                egDto.setBaoJiGroup(bj);
                Long bjGroupId=bj.getBaoJiGroupId();
                List<GroupTestCapRes> list=mapper.getEnergyStatisticsInBaojiGroup(date1,date2,bjGroupId);
                Map<Integer,Integer> sCountMap=new HashMap<>();
                Map<Integer,String> sCapMap=new HashMap<>();
                for (int i=0;i<year;i++){
                    sCountMap.put(lastYear+i,0);
                    sCapMap.put(lastYear+i,"0");
                }
                egDto.setSCountMap(sCountMap);
                Map<Integer, List<GroupTestCapRes>> yearMap = list.stream().collect(Collectors.groupingBy(GroupTestCapRes::getYearTime));
                for (Integer yearTime : yearMap.keySet()) {
                    sCountMap.put(yearTime,yearMap.get(yearTime).size());
                    List<GroupTestCapRes> groupList=yearMap.get(yearTime);
                    Double sum = groupList.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
                    sCapMap.put(yearTime,String.format("%.3f",sum));
                }
                egDto.setSCapMap(sCapMap);
                listeg.add(egDto);
            }
        }
        return new Response().setII(1, true, listeg, "能效统计分班组");
    }
    //能效统计分班组
    public Response getEnergyStatisticsInBaojiGroupWithOutYear(int year) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        //1.查询出所有的班组
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("discharge_plan_flag",1);
        List<BaoJiGroup> listbj=baoJiGroupMapper.selectList(wrapper);
        Map<String,Integer> sCountMap=new HashMap<>();
        Map<String,String> sCapMap=new HashMap<>();
        if(listbj!=null&&listbj.size()>0){
            for (BaoJiGroup bj:listbj) {
                Long bjGroupId=bj.getBaoJiGroupId();
                List<GroupTestCapRes> list=mapper.getEnergyStatisticsInBaojiGroup(date1,date2,bjGroupId);
                sCountMap.put(bj.getBaoJiGroupName(),list.size());
                Double sum = list.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
                sCapMap.put(bj.getBaoJiGroupName(),String.format("%.3f",sum));
            }
        }
        return new Response().setIII(1, true, sCountMap,sCapMap, "能效统计");
    }
 
    //能效统计--南京websocket首页
    public Response getEnergyStatistics_nj(int year,int userId) {
        Calendar calendar = Calendar.getInstance();
        int nowYear= calendar.get(Calendar.YEAR);
        int lastYear=nowYear-year+1;
        Date date1 = ThreadLocalUtil.parse(lastYear+"-01-01 00:00:00",1 );
        Date date2 = ThreadLocalUtil.parse(nowYear+"-12-31 23:59:59",1 );
        List<GroupTestCapRes> list=mapper.getEnergyStatistics_nj(date1,date2,userId);
        Map<Integer,Integer> sCountMap=new HashMap<>();
        Map<Integer,String> sCapMap=new HashMap<>();
        for (int i=0;i<year;i++){
            sCountMap.put(lastYear+i,0);
            sCapMap.put(lastYear+i,"0");
        }
        Map<Integer, List<GroupTestCapRes>> yearMap = list.stream().collect(Collectors.groupingBy(GroupTestCapRes::getYearTime));
        for (Integer yearTime : yearMap.keySet()) {
            sCountMap.put(yearTime,yearMap.get(yearTime).size());
            List<GroupTestCapRes> groupList=yearMap.get(yearTime);
            Double sum = groupList.stream().collect(Collectors.summingDouble(GroupTestCapRes::getTestCap));
            sCapMap.put(yearTime,String.format("%.3f",sum));
        }
        return new Response().setIII(1, true, sCountMap,sCapMap, "能效统计");
    }
    //1.获取当前最大的放电信息testRecordCount
    public BatttestdataInf getMaxRecord(int battGroupId) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("battGroupId",battGroupId);
        wrapper.last("limit 1");
        wrapper.orderByDesc("test_record_count");
        BatttestdataInf tinf=mapper.selectOne(wrapper);
        return tinf;
    }
    //3.将tinf补齐
    public void insertTinf(BatttestdataInf tinf) {
        mapper.insert(tinf);
    }
}