zf
2024-03-25 cd02923a7ce1ffa004b3abbb7af67ab6173dd99d
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
package com.gkhy.safePlatform.incidentManage.service.impl;
 
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
import com.gkhy.safePlatform.commons.enums.ResultCodes;
import com.gkhy.safePlatform.commons.exception.BusinessException;
import com.gkhy.safePlatform.commons.utils.BeanCopyUtils;
import com.gkhy.safePlatform.commons.utils.StringUtils;
import com.gkhy.safePlatform.commons.vo.ResultVO;
import com.gkhy.safePlatform.commons.vo.SearchResultVO;
import com.gkhy.safePlatform.incidentManage.entity.*;
import com.gkhy.safePlatform.incidentManage.enums.AccidentReportLevelEnum;
import com.gkhy.safePlatform.incidentManage.enums.AccidentResultCodes;
import com.gkhy.safePlatform.incidentManage.enums.DepartmentLevelEnum;
import com.gkhy.safePlatform.incidentManage.exception.AccidentException;
import com.gkhy.safePlatform.incidentManage.model.dto.resp.*;
import com.gkhy.safePlatform.incidentManage.query.AccidentReportCountQuery;
import com.gkhy.safePlatform.incidentManage.query.IncidentManageCountQuery;
import com.gkhy.safePlatform.incidentManage.query.db.AccidentReportCountDBQuery;
import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.req.IncidentManageCountRPCReq;
import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.resp.IncidentManageCountDetailRPCResp;
import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.resp.IncidentManageCountRPCResp;
import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.resp.IncidentManageRPCResp;
import com.gkhy.safePlatform.incidentManage.service.AccidentCountService;
import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentReportInfoService;
import com.gkhy.safePlatform.incidentManage.utils.TimeUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
@Service("accidentCountService")
public class AccidentCountServiceImpl implements AccidentCountService {
 
    @Autowired
    private AccidentReportInfoService accidentReportInfoService;
 
    @DubboReference(check = false)
    private AccountDepartmentService accountDepartmentService;
 
 
    @Override
    public SearchResultVO<IncidentManageRPCResp> getCountByDeptId(IncidentManageCountRPCReq query) {
        if (query.getYear() == null) {
            throw new AccidentException(AccidentResultCodes.YEAR_NULL);
        }
        IncidentManageRPCResp incidentManageCountRPCResp = new IncidentManageRPCResp();
        // 获取id对应的部门
        DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId());
        incidentManageCountRPCResp.setDeptId(depInfoRPCRespDTO.getDepId());
        incidentManageCountRPCResp.setDeptName(depInfoRPCRespDTO.getDepName());
        incidentManageCountRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel());
        incidentManageCountRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId());
 
        getSingleTimeData(incidentManageCountRPCResp, query);
 
        SearchResultVO searchResultVO = new SearchResultVO<>(
                false,
                null,
                null,
                null,
                null,
                incidentManageCountRPCResp,
                ResultCodes.OK
        );
        searchResultVO.setCount(1);
        return searchResultVO;
    }
 
    @Override
    public SearchResultVO<List<IncidentManageRPCResp>> getCountByDeptIds(IncidentManageCountRPCReq query) {
        if (query.getYear() == null) {
            throw new AccidentException(AccidentResultCodes.YEAR_NULL);
        }
        List<IncidentManageRPCResp> list = new ArrayList<>();
 
        // 获取该部门及其子部门的所有信息
        List<DepInfoRPCRespDTO> deptList = getDepListInfoByDepId(query.getDeptId());
 
        for (DepInfoRPCRespDTO depInfoRPCRespDTO : deptList) {
            IncidentManageRPCResp incidentManageCountRPCResp = new IncidentManageRPCResp();
            incidentManageCountRPCResp.setDeptId(depInfoRPCRespDTO.getDepId());
            incidentManageCountRPCResp.setDeptName(depInfoRPCRespDTO.getDepName());
            incidentManageCountRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel());
            incidentManageCountRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId());
 
            getSingleTimeData(incidentManageCountRPCResp, query);
            list.add(incidentManageCountRPCResp);
        }
        SearchResultVO searchResultVO = new SearchResultVO<>(
                false,
                null,
                null,
                null,
                null,
                list,
                ResultCodes.OK
        );
        if (!list.isEmpty()){
            searchResultVO.setCount(list.size());
        }
        return searchResultVO;
    }
 
    private void getSingleTimeData(IncidentManageRPCResp incidentManageRPCResp, IncidentManageCountRPCReq query) {
 
        List<IncidentManageCountRPCResp> resList = new ArrayList<>();
 
        List<AccidentReportCountRPC> accidentReportCountRPCList = new ArrayList<>();
        Long deptId = incidentManageRPCResp.getDeptId();
        String startTime;
        String endTime;
        Integer distType;
        if (query.getMonth() == null) {
            distType=1;
            // 查该年度12个月份的
            startTime = TimeUtils.getYearFirst(query.getYear());
            endTime = TimeUtils.getYearLast(query.getYear());
            accidentReportCountRPCList= accidentReportInfoService.getCountForRPCByDeptIdAndMonth(startTime, endTime, deptId);
 
        } else {
            distType=2;
            // 查该年度指定月份的
            startTime = TimeUtils.getMonthFirst(query.getYear(), query.getMonth());
            endTime = TimeUtils.getMonthLast(query.getYear(), query.getMonth());
            accidentReportCountRPCList = accidentReportInfoService.getCountForRPCByDeptIdAndDay(startTime, endTime, deptId);
        }
 
        // 拼装第一层时间(去重)
        Set<Integer> timeSET = accidentReportCountRPCList.stream().map(AccidentReportCountRPC::getTime).collect(Collectors.toSet());
        // 拼装第一层时间(排序)
        List<Integer> timeList = timeSET.stream().sorted().collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(timeSET)) {
            for (Integer integer : timeSET) {
                IncidentManageCountRPCResp incidentManageCountRPCResp = new IncidentManageCountRPCResp();
                incidentManageCountRPCResp.setTime(integer);
                incidentManageCountRPCResp.setYear(query.getYear());
                incidentManageCountRPCResp.setDistType(distType);
                if (distType==1){
                    incidentManageCountRPCResp.setMonth(integer);
                }
                if (distType==2){
                    incidentManageCountRPCResp.setMonth(query.getMonth());
                    incidentManageCountRPCResp.setDay(integer);
                }
 
                incidentManageCountRPCResp.setDetail(new ArrayList<>());
                resList.add(incidentManageCountRPCResp);
            }
        }
        // 拼装第二层事故详情
        if (!CollectionUtils.isEmpty(timeList)) {
            for (AccidentReportCountRPC accidentReportCountRPC : accidentReportCountRPCList) {
                for (IncidentManageCountRPCResp incidentManageCountRPCResp : resList) {
                    if (accidentReportCountRPC.getTime().equals(incidentManageCountRPCResp.getTime())) {
                        IncidentManageCountDetailRPCResp incidentManageCountDetailRPCResp = new IncidentManageCountDetailRPCResp();
 
                        incidentManageCountDetailRPCResp.setLevel(accidentReportCountRPC.getLevel());
                        incidentManageCountDetailRPCResp.setNum(accidentReportCountRPC.getNum());
                        incidentManageCountDetailRPCResp.setMinorInjuryNum(accidentReportCountRPC.getMinorInjuryNum());
                        incidentManageCountDetailRPCResp.setSeriousInjuryNum(accidentReportCountRPC.getSeriousInjuryNum());
                        incidentManageCountDetailRPCResp.setDeathNum(accidentReportCountRPC.getDeathNum());
                        incidentManageCountDetailRPCResp.setEconomicLoss(accidentReportCountRPC.getEconomicLoss());
                        incidentManageCountRPCResp.getDetail().add(incidentManageCountDetailRPCResp);
                    }
                }
            }
        }
        incidentManageRPCResp.setData(resList);
    }
 
    private DepInfoRPCRespDTO getDepInfoByDepId(Long deptId) {
        DepInfoRPCRespDTO dep = new DepInfoRPCRespDTO();
        try{
            ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(deptId);
            if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
                if (rpcResult.getData() != null) {
                    dep = (DepInfoRPCRespDTO) rpcResult.getData();
                }
            } else {
                throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
            }
        }catch (Exception e){
            throw new AccidentException(AccidentResultCodes.RPC_ERROR);
        }
 
        return dep;
    }
 
    private List<DepInfoRPCRespDTO> getDepListInfoByDepId(Long deptId) {
        List<DepInfoRPCRespDTO> depList = new ArrayList<>();
        ResultVO<List<DepInfoRPCRespDTO>> rpcResult = accountDepartmentService.listDepAndSubDepByDepId(deptId);
        if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
            if (rpcResult.getData() != null) {
                depList = (List<DepInfoRPCRespDTO>) rpcResult.getData();
            }
        } else {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }
        return depList;
    }
 
    @Override
    public ResultVO<List<AccidentReportCountRespDTO>> countAccidentReport(AccidentReportCountQuery query) {
 
        List<AccidentReportCount> list = new ArrayList<>();
        AccidentReportCountDBQuery dbQuery = new AccidentReportCountDBQuery();
        if (query.getType() == 1) {
            // 月
            int year = query.getYear();
            int month;
            if (query.getMonth() == 0) {
                Calendar date = Calendar.getInstance();
                month = date.get(Calendar.MONTH) + 1;
            } else {
                month = query.getMonth();
            }
            dbQuery.setStartTime(TimeUtils.getMonthFirst(year, month));
            dbQuery.setEndTime(TimeUtils.getMonthLast(year, month));
            list = accidentReportInfoService.selectByTimeAndType(dbQuery);
        }
        if (query.getType() == 2) {
            // 年
            int year = query.getYear();
            dbQuery.setStartTime(TimeUtils.getYearFirst(year));
            dbQuery.setEndTime(TimeUtils.getYearLast(year));
            list = accidentReportInfoService.selectByTimeAndType(dbQuery);
        }
 
        List<AccidentReportCountRespDTO> accidentReportCountRespDTOList = BeanCopyUtils.copyBeanList(list, AccidentReportCountRespDTO.class);
        return new ResultVO<>(ResultCodes.OK, accidentReportCountRespDTOList);
    }
 
    /**
     * 根据部门以及指定时间统计每月每种事故等级事故数量以及事故后顾相关数据量
     * @param query
     * @return
     */
    //@Override
    public StatisticsDeptLevelYearAccidentRespDTO getCountByDeptIdAndYear(IncidentManageCountQuery query) {
        if(null == query.getDeptId()){
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"部门不可为空");
        }
        if (null == query.getYear()) {
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"年份不可为空");
        }
        // 通过RPC获取id对应的部门数据
        DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId());
        //填充部门等级数据
        StatisticsDeptLevelYearAccidentRespDTO respDTO = new StatisticsDeptLevelYearAccidentRespDTO();
        respDTO.setDepLevel(depInfoRPCRespDTO.getDepLevel());
        respDTO.setYear(query.getYear());
 
        //开始时间结束时间
        String startTime = TimeUtils.getYearFirst(query.getYear());
        String endTime = TimeUtils.getYearLast(query.getYear());
        //获取指定部门指定时间下事故统计数据
        List<AccidentResultCountDO> countDOList = accidentReportInfoService.getAccidentCountByDeptIdAndTime(startTime, endTime, query.getDeptId());
 
        List<StatisticsDepLevelMonthAccidentRespDTO> monthAccidentRespDTOList = new ArrayList<>();
        //声明月份
        int allMonth = 12;
        //判断是否是当前年分
//        if(query.getYear().equals(TimeUtils.getCurrentYear())){
//            allMonth = TimeUtils.getCurrentMonth();
//        }
        //循环月份
        for (int i = 1;i <= allMonth;i++) {
            //填充月数据
            StatisticsDepLevelMonthAccidentRespDTO monthAccidentRespDTO = new StatisticsDepLevelMonthAccidentRespDTO();
            monthAccidentRespDTO.setMonth(i);
            monthAccidentRespDTO.setDepLevel(depInfoRPCRespDTO.getDepLevel());
            //过滤出该月份的所有数据
            int month = i;
            List<AccidentResultCountDO> selectMonthList = countDOList
                    .stream()
                    .filter(item -> item.getMonth() == month)
                    .collect(Collectors.toList());
 
            List<AccidentLevelResultCountRespDTO> resultCountRespDTOList = new ArrayList<>();
            //循环事故等级
            for (AccidentReportLevelEnum levelEnum:AccidentReportLevelEnum.values()) {
                AccidentLevelResultCountRespDTO resultCountRespDTO = new AccidentLevelResultCountRespDTO();
                resultCountRespDTO.setAccidentLevel(levelEnum.getCode());
                resultCountRespDTO.setAccidentLevelName(levelEnum.getValue());
                List<AccidentResultCountDO> levelList = selectMonthList
                        .stream()
                        .filter(item -> item.getAccidentLevel().equals(levelEnum.getCode()))
                        .collect(Collectors.toList());
                if(levelList.size()>0){
                    resultCountRespDTO.setAccidentCount(levelList.get(0).getAccidentCount());
                    resultCountRespDTO.setDeathCount(levelList.get(0).getDeathCount());
                    resultCountRespDTO.setMinorInjuryCount(levelList.get(0).getMinorInjuryCount());
                    resultCountRespDTO.setSeriousInjuryCount(levelList.get(0).getSeriousInjuryCount());
                    resultCountRespDTO.setEconomicLoss(levelList.get(0).getEconomicLoss());
                    resultCountRespDTOList.add(resultCountRespDTO);
                }else{
                    resultCountRespDTO.setAccidentCount(0);
                    resultCountRespDTO.setDeathCount(0);
                    resultCountRespDTO.setMinorInjuryCount(0);
                    resultCountRespDTO.setSeriousInjuryCount(0);
                    resultCountRespDTO.setEconomicLoss(BigDecimal.valueOf(0));
                    resultCountRespDTOList.add(resultCountRespDTO);
                }
 
            }
            monthAccidentRespDTO.setAccidentLevelList(resultCountRespDTOList);
            monthAccidentRespDTOList.add(monthAccidentRespDTO);
        }
        respDTO.setMonthList(monthAccidentRespDTOList);
      return respDTO;
    }
 
    @Override
    public StatisticsDepLevelMonthAccidentRespDTO getCountByDeptIdAndMonth(IncidentManageCountQuery query) {
        if(null == query.getDeptId()){
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"部门不可为空");
        }
        if (null == query.getYear()) {
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"年份不可为空");
        }
        if(null == query.getMonth()){
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"月份不可为空");
        }
        // 通过RPC获取id对应的部门数据
        DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId());
        //填充数据
        StatisticsDepLevelMonthAccidentRespDTO respDTO = new StatisticsDepLevelMonthAccidentRespDTO();
        respDTO.setMonth(query.getMonth());
        respDTO.setDepLevel(depInfoRPCRespDTO.getDepLevel());
        //开始时间结束时间
        String startTime = TimeUtils.getMonthFirst(query.getYear(),query.getMonth());
        String endTime = TimeUtils.getMonthLast(query.getYear(),query.getMonth());
        //获取指定部门指定时间下事故统计数据
        List<AccidentResultCountDO> countDOList = accidentReportInfoService.getAccidentCountByDeptIdAndTime(startTime, endTime, query.getDeptId());
 
        List<AccidentLevelResultCountRespDTO> resultCountRespDTOList = new ArrayList<>();
        //循环事故等级
        for (AccidentReportLevelEnum levelEnum:AccidentReportLevelEnum.values()) {
            AccidentLevelResultCountRespDTO resultCountRespDTO = new AccidentLevelResultCountRespDTO();
            resultCountRespDTO.setAccidentLevel(levelEnum.getCode());
            resultCountRespDTO.setAccidentLevelName(levelEnum.getValue());
            //过滤事故数据
            List<AccidentResultCountDO> selectAccList = countDOList
                    .stream()
                    .filter(ac -> ac.getAccidentLevel().equals(levelEnum.getCode()))
                    .collect(Collectors.toList());
            if(selectAccList.size()>0){
                resultCountRespDTO.setAccidentCount(selectAccList.get(0).getAccidentCount());
                resultCountRespDTO.setDeathCount(selectAccList.get(0).getDeathCount());
                resultCountRespDTO.setMinorInjuryCount(selectAccList.get(0).getMinorInjuryCount());
                resultCountRespDTO.setSeriousInjuryCount(selectAccList.get(0).getSeriousInjuryCount());
                resultCountRespDTO.setEconomicLoss(selectAccList.get(0).getEconomicLoss());
            }else{
                resultCountRespDTO.setAccidentCount(0);
                resultCountRespDTO.setDeathCount(0);
                resultCountRespDTO.setMinorInjuryCount(0);
                resultCountRespDTO.setSeriousInjuryCount(0);
                resultCountRespDTO.setEconomicLoss(BigDecimal.valueOf(0));
            }
            resultCountRespDTOList.add(resultCountRespDTO);
        }
        respDTO.setAccidentLevelList(resultCountRespDTOList);
        return respDTO;
    }
 
 
    public List<StatisticsDeptLevelYearAccidentRespDTO> getCountByDeptIdsAndYear(IncidentManageCountQuery query) {
        if(null == query.getDeptId()){
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"部门不可为空");
        }
        if (null == query.getYear()) {
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"年份不可为空");
        }
        // 通过RPC获取id对应的部门数据
        List<DepInfoRPCRespDTO> deptInfoList = getDepListInfoByDepId(query.getDeptId());
        //过滤出部门ids
        List<Long> deptIds = deptInfoList
                .stream()
                .map(item -> item.getDepId())
                .collect(Collectors.toList());
 
        //开始时间结束时间
        String startTime = TimeUtils.getYearFirst(query.getYear());
        String endTime = TimeUtils.getYearLast(query.getYear());
        //获取指定部门指定时间下事故统计数据
        List<AccidentResultCountDO>  countDOList = accidentReportInfoService.getAccidentCountByDeptIdsAndTime(startTime, endTime, deptIds);
        List<StatisticsDeptLevelYearAccidentRespDTO> deptLevelRespDTOList = new ArrayList<>();
        //循环部门等级
        for(DepartmentLevelEnum departmentLevelEnum : DepartmentLevelEnum.values()) {
            //填充部门级别数据
            StatisticsDeptLevelYearAccidentRespDTO depLevelRespDTO = new StatisticsDeptLevelYearAccidentRespDTO();
            depLevelRespDTO.setDepLevel(departmentLevelEnum.getCode());
            depLevelRespDTO.setYear(query.getYear());
 
            //获取该部门级别下面的相关部门
            List<DepInfoRPCRespDTO> selectDepList = deptInfoList
                    .stream()
                    .filter(dep -> dep.getDepLevel().equals(departmentLevelEnum.getCode()))
                    .collect(Collectors.toList());
            //获取该部门级别下相关部门数据
            List<AccidentResultCountDO> selectAccList = countDOList
                    .stream()
                    .filter(exe -> selectDepList.stream().map(dep -> dep.getDepId()).collect(Collectors.toList()).contains(exe.getDeptId()))
                    .collect(Collectors.toList());
            List<StatisticsDepLevelMonthAccidentRespDTO> monthAccidentRespDTOList = new ArrayList<>();
            //声明月份
            int allMonth = 12;
            //判断是否是当前年分
//            if(query.getYear().equals(TimeUtils.getCurrentYear())){
//                allMonth = TimeUtils.getCurrentMonth();
//            }
            //循环月份
            for (int i = 1;i <= allMonth;i++) {
                //填充月数据
                StatisticsDepLevelMonthAccidentRespDTO monthAccidentRespDTO = new StatisticsDepLevelMonthAccidentRespDTO();
                monthAccidentRespDTO.setDepLevel(departmentLevelEnum.getCode());
                monthAccidentRespDTO.setMonth(i);
                //过滤出该月份的所有数据
                int month = i;
                List<AccidentResultCountDO> selectMonthList = selectAccList
                        .stream()
                        .filter(item -> item.getMonth() == month)
                        .collect(Collectors.toList());
                List<AccidentLevelResultCountRespDTO> resultCountRespDTOList = new ArrayList<>();
                //循环事故等级
                for (AccidentReportLevelEnum levelEnum:AccidentReportLevelEnum.values()) {
                    //填充事故等级
                    AccidentLevelResultCountRespDTO resultCountRespDTO = new AccidentLevelResultCountRespDTO();
                    resultCountRespDTO.setAccidentLevel(levelEnum.getCode());
                    resultCountRespDTO.setAccidentLevelName(levelEnum.getValue());
                    //过滤出该事故等级下的数据
                    List<AccidentResultCountDO> accidentLevelList = selectMonthList
                            .stream()
                            .filter(item -> item.getAccidentLevel().equals(levelEnum.getCode()))
                            .collect(Collectors.toList());
                    //事故数量
                    int accidentCount = 0;
                    //死亡数量
                    int deathCount = 0;
                    //重伤数量
                    int seriousInjuryCount = 0;
                    //轻伤数量
                    int minorInjuryCount = 0;
                    //经济损失
                    BigDecimal economicLoss = BigDecimal.valueOf(0.00);
 
                    if(accidentLevelList.size()>0){
                        for(AccidentResultCountDO resultCountDO:accidentLevelList) {
                            accidentCount += resultCountDO.getAccidentCount();
                            deathCount += resultCountDO.getDeathCount();
                            seriousInjuryCount += resultCountDO.getSeriousInjuryCount();
                            minorInjuryCount += resultCountDO.getMinorInjuryCount();
                            economicLoss = economicLoss.add(resultCountDO.getEconomicLoss());
                        }
                    }
                    resultCountRespDTO.setAccidentCount(accidentCount);
                    resultCountRespDTO.setDeathCount(deathCount);
                    resultCountRespDTO.setMinorInjuryCount(minorInjuryCount);
                    resultCountRespDTO.setSeriousInjuryCount(seriousInjuryCount);
                    resultCountRespDTO.setEconomicLoss(economicLoss);
                    resultCountRespDTOList.add(resultCountRespDTO);
                }
                monthAccidentRespDTO.setAccidentLevelList(resultCountRespDTOList);
                monthAccidentRespDTOList.add(monthAccidentRespDTO);
            }
            depLevelRespDTO.setMonthList(monthAccidentRespDTOList);
            deptLevelRespDTOList.add(depLevelRespDTO);
        }
        return deptLevelRespDTOList;
    }
    @Override
    public List<StatisticsDepLevelMonthAccidentRespDTO> getCountByDeptIdsAndMonth(IncidentManageCountQuery query) {
        if(null == query.getDeptId()){
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"部门不可为空");
        }
        if (null == query.getYear()) {
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"年份不可为空");
        }
        if(null == query.getMonth()){
            throw new AccidentException(AccidentResultCodes.SERVE_PARAM_NULL,"月份不可为空");
        }
        // 通过RPC获取id对应的部门数据
        List<DepInfoRPCRespDTO> deptInfoList = getDepListInfoByDepId(query.getDeptId());
        //过滤出部门ids
        List<Long> deptIds = deptInfoList
                .stream()
                .map(item -> item.getDepId())
                .collect(Collectors.toList());
 
        //开始时间结束时间
        String startTime = TimeUtils.getMonthFirst(query.getYear(),query.getMonth());
        String endTime = TimeUtils.getMonthLast(query.getYear(),query.getMonth());
        //获取指定部门指定时间下事故统计数据
        List<AccidentResultCountDO> countDOList = accidentReportInfoService.getAccidentCountByDeptIdsAndTime(startTime, endTime, deptIds);
        List<StatisticsDepLevelMonthAccidentRespDTO> respDTOList = new ArrayList<>();
        //循环部门等级
        for(DepartmentLevelEnum departmentLevelEnum : DepartmentLevelEnum.values()) {
            //填充部门级别数据
            StatisticsDepLevelMonthAccidentRespDTO depLevelRespDTO = new StatisticsDepLevelMonthAccidentRespDTO();
            depLevelRespDTO.setMonth(query.getMonth());
            depLevelRespDTO.setDepLevel(departmentLevelEnum.getCode());
            //获取该部门级别下面的相关部门
            List<DepInfoRPCRespDTO> selectDepList = deptInfoList
                    .stream()
                    .filter(dep -> dep.getDepLevel().equals(departmentLevelEnum.getCode()))
                    .collect(Collectors.toList());
            //获取该部门级别下相关部门数据
            List<AccidentResultCountDO> selectAccList = countDOList
                    .stream()
                    .filter(exe -> selectDepList.stream().map(dep -> dep.getDepId()).collect(Collectors.toList()).contains(exe.getDeptId()))
                    .collect(Collectors.toList());
 
            List<AccidentLevelResultCountRespDTO> resultCountRespDTOList = new ArrayList<>();
            //循环事故等级
            for (AccidentReportLevelEnum levelEnum:AccidentReportLevelEnum.values()) {
                AccidentLevelResultCountRespDTO resultCountRespDTO = new AccidentLevelResultCountRespDTO();
                resultCountRespDTO.setAccidentLevel(levelEnum.getCode());
                resultCountRespDTO.setAccidentLevelName(levelEnum.getValue());
                //过滤出该事故等级下的数据
                List<AccidentResultCountDO> accidentLevelList = selectAccList
                        .stream()
                        .filter(item -> item.getAccidentLevel().equals(levelEnum.getCode()))
                        .collect(Collectors.toList());
                //事故数量
                int accidentCount = 0;
                //死亡数量
                int deathCount = 0;
                //重伤数量
                int seriousInjuryCount = 0;
                //轻伤数量
                int minorInjuryCount = 0;
                //经济损失
                BigDecimal economicLoss = BigDecimal.valueOf(0.00);
 
                if(accidentLevelList.size()>0){
                    for(AccidentResultCountDO resultCountDO:accidentLevelList) {
                        accidentCount += resultCountDO.getAccidentCount();
                        deathCount += resultCountDO.getDeathCount();
                        seriousInjuryCount += resultCountDO.getSeriousInjuryCount();
                        minorInjuryCount += resultCountDO.getMinorInjuryCount();
                        economicLoss = economicLoss.add(resultCountDO.getEconomicLoss());
                    }
                }
                resultCountRespDTO.setAccidentCount(accidentCount);
                resultCountRespDTO.setDeathCount(deathCount);
                resultCountRespDTO.setMinorInjuryCount(minorInjuryCount);
                resultCountRespDTO.setSeriousInjuryCount(seriousInjuryCount);
                resultCountRespDTO.setEconomicLoss(economicLoss);
                resultCountRespDTOList.add(resultCountRespDTO);
            }
            depLevelRespDTO.setAccidentLevelList(resultCountRespDTOList);
            respDTOList.add(depLevelRespDTO);
        }
        return respDTOList;
    }
}