zhangf
2024-05-08 0414ddb0b2b3a7199ae6181a770f97ac140dbd73
incident-manage/incident-manage-service/src/main/java/com/gkhy/safePlatform/incidentManage/service/impl/AccidentCountServiceImpl.java
@@ -2,16 +2,22 @@
import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService;
import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO;
import com.gkhy.safePlatform.commons.enums.E;
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.AccidentReportGradeEnum;
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;
@@ -25,7 +31,8 @@
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.print.DocFlavor;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@@ -50,22 +57,28 @@
        incidentManageCountRPCResp.setDeptId(depInfoRPCRespDTO.getDepId());
        incidentManageCountRPCResp.setDeptName(depInfoRPCRespDTO.getDepName());
        incidentManageCountRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel());
        incidentManageCountRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId());
        getSingleTimeData(incidentManageCountRPCResp, query);
        return new SearchResultVO<>(
        SearchResultVO searchResultVO = new SearchResultVO<>(
                false,
                null,
                null,
                null,
                1L,
                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<>();
        // 获取该部门及其子部门的所有信息
@@ -76,36 +89,44 @@
            incidentManageCountRPCResp.setDeptId(depInfoRPCRespDTO.getDepId());
            incidentManageCountRPCResp.setDeptName(depInfoRPCRespDTO.getDepName());
            incidentManageCountRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel());
            incidentManageCountRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId());
            getSingleTimeData(incidentManageCountRPCResp, query);
            list.add(incidentManageCountRPCResp);
        }
        return new SearchResultVO<>(
        SearchResultVO searchResultVO = new SearchResultVO<>(
                false,
                null,
                null,
                null,
                (long) list.size(),
                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 = query.getDeptId();
        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());
@@ -113,13 +134,23 @@
        }
        // 拼装第一层时间(去重)
        Set<String> timeSET = accidentReportCountRPCList.stream().map(AccidentReportCountRPC::getTime).collect(Collectors.toSet());
        Set<Integer> timeSET = accidentReportCountRPCList.stream().map(AccidentReportCountRPC::getTime).collect(Collectors.toSet());
        // 拼装第一层时间(排序)
        List<String> timeList = timeSET.stream().sorted().collect(Collectors.toList());
        List<Integer> timeList = timeSET.stream().sorted().collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(timeSET)) {
            for (String str : timeSET) {
            for (Integer integer : timeSET) {
                IncidentManageCountRPCResp incidentManageCountRPCResp = new IncidentManageCountRPCResp();
                incidentManageCountRPCResp.setTime(str);
                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);
            }
@@ -147,14 +178,19 @@
    private DepInfoRPCRespDTO getDepInfoByDepId(Long deptId) {
        DepInfoRPCRespDTO dep = new DepInfoRPCRespDTO();
        ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(deptId);
        if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) {
            if (rpcResult.getData() != null) {
                dep = (DepInfoRPCRespDTO) rpcResult.getData();
        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);
            }
        } else {
            throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST);
        }catch (Exception e){
            throw new AccidentException(AccidentResultCodes.RPC_ERROR);
        }
        return dep;
    }
@@ -202,4 +238,378 @@
        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;
    }
    /**
     * 统计数据
     */
    @Override
    public List<AccidentStatisticDTO> getCountByAccidentGrade(Integer year, Integer month) {
        if(null == year && null != month){
            throw new BusinessException(ResultCodes.CLIENT_PARAM_ERROR,"年份不可为空");
        }
        if(null == year && null == month) {
            year = LocalDate.now().getYear();
        }
        List<AccidentStatisticDTO> accidentStatisticDTOList = new ArrayList<>();
        List<AccidentStatisticCountDO> countByAccidentGrades = accidentReportInfoService.getCountByAccidentGrade(year, month);
        for (AccidentReportGradeEnum gradeEnum : AccidentReportGradeEnum.values()) {
            AccidentStatisticDTO accidentStatisticDTO = new AccidentStatisticDTO();
            accidentStatisticDTO.setAccidentGrade(gradeEnum.getValue());
            List<AccidentStatisticCountDO> collect = countByAccidentGrades.stream().filter(c -> c.getAccidentGrade().equals(gradeEnum.getCode())).collect(Collectors.toList());
            accidentStatisticDTO.setCount(collect.size()>0 ? collect.get(0).getCount() : 0);
            accidentStatisticDTOList.add(accidentStatisticDTO);
        }
        return accidentStatisticDTOList;
    }
    /**
     * 统计数据
     */
    @Override
    public AccidentCountByGradeRespDTO getSpiAccidentCountByAccidentGrade(Integer year, Integer month) {
        List<AccidentStatisticCountDO> countByAccidentGrades = accidentReportInfoService.getCountByAccidentGrade(year, month);
        AccidentCountByGradeRespDTO accidentCountByGradeRespDTO = new AccidentCountByGradeRespDTO();
        int total = 0;
        for (AccidentStatisticCountDO countByAccidentGrade : countByAccidentGrades) {
            if(countByAccidentGrade.getAccidentGrade().equals(AccidentReportGradeEnum.GRADE_ONE.getCode())){
                accidentCountByGradeRespDTO.setAccidentOne(countByAccidentGrade.getCount());
            }
            if(countByAccidentGrade.getAccidentGrade().equals(AccidentReportGradeEnum.GRADE_TWO.getCode())){
                accidentCountByGradeRespDTO.setAccidentTwo(countByAccidentGrade.getCount());
            }
            if(countByAccidentGrade.getAccidentGrade().equals(AccidentReportGradeEnum.GRADE_THREE.getCode())){
                accidentCountByGradeRespDTO.setAccidentThree(countByAccidentGrade.getCount());
            }
            if(countByAccidentGrade.getAccidentGrade().equals(AccidentReportGradeEnum.GRADE_FOUR.getCode())){
                accidentCountByGradeRespDTO.setAccidentFour(countByAccidentGrade.getCount());
            }
            total += countByAccidentGrade.getCount();
        }
        return accidentCountByGradeRespDTO;
    }
}