From 1305d0aa469fe7330fd2f8e9fbb10d95042571be Mon Sep 17 00:00:00 2001 From: zhangfeng <1603559716@qq.com> Date: 星期一, 10 十月 2022 12:33:36 +0800 Subject: [PATCH] 应急系统和事故管理统计接口 --- emergency/emergency-service/src/main/java/com/gkhy/safePlatform/emergency/service/impl/EmergencyCountServiceImpl.java | 440 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 409 insertions(+), 31 deletions(-) diff --git a/emergency/emergency-service/src/main/java/com/gkhy/safePlatform/emergency/service/impl/EmergencyCountServiceImpl.java b/emergency/emergency-service/src/main/java/com/gkhy/safePlatform/emergency/service/impl/EmergencyCountServiceImpl.java index 63a3827..3836a66 100644 --- a/emergency/emergency-service/src/main/java/com/gkhy/safePlatform/emergency/service/impl/EmergencyCountServiceImpl.java +++ b/emergency/emergency-service/src/main/java/com/gkhy/safePlatform/emergency/service/impl/EmergencyCountServiceImpl.java @@ -7,23 +7,26 @@ import com.gkhy.safePlatform.commons.exception.BusinessException; import com.gkhy.safePlatform.commons.query.PageQuery; 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.emergency.entity.*; +import com.gkhy.safePlatform.emergency.enums.DepartmentLevelEnum; import com.gkhy.safePlatform.emergency.enums.EmergencyResultCodes; import com.gkhy.safePlatform.emergency.excepiton.EmergencyException; import com.gkhy.safePlatform.emergency.model.dto.resp.*; +import com.gkhy.safePlatform.emergency.query.EmergencyDrillCountQuery; import com.gkhy.safePlatform.emergency.query.EmergencyDrillExecuteCountQuery; import com.gkhy.safePlatform.emergency.query.EmergencySuppliesCountQuery; import com.gkhy.safePlatform.emergency.rpc.api.model.dto.req.EmergencyExecuteNumRPCReq; import com.gkhy.safePlatform.emergency.rpc.api.model.dto.req.EmergencyExecuteTimeRPCReq; +import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.EmergencyExecuteNumDetailRPCResp; import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.EmergencyExecuteNumRPCResp; import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.EmergencyExecuteTimeRPCResp; import com.gkhy.safePlatform.emergency.service.EmergencyCountService; import com.gkhy.safePlatform.emergency.service.baseService.EmergencyDrillExecuteInfoService; import com.gkhy.safePlatform.emergency.service.baseService.EmergencySuppliesInfoService; import com.gkhy.safePlatform.emergency.utils.TimeUtils; -import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -31,6 +34,7 @@ import java.text.SimpleDateFormat; import java.util.*; +import java.util.stream.Collectors; @Service("emergencyCountService") public class EmergencyCountServiceImpl implements EmergencyCountService { @@ -47,40 +51,66 @@ @Override public SearchResultVO<EmergencyExecuteTimeRPCResp> getTimeByDeptId(EmergencyExecuteTimeRPCReq query) { EmergencyExecuteTimeRPCResp emergencyExecuteTimeRPCResp = new EmergencyExecuteTimeRPCResp(); - // 获取id对应的部门 DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId()); - emergencyExecuteTimeRPCResp.setDeptId(depInfoRPCRespDTO.getDepId()); emergencyExecuteTimeRPCResp.setDeptName(depInfoRPCRespDTO.getDepName()); emergencyExecuteTimeRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel()); - String lastTime = emergencyDrillExecuteInfoService.selectEmergencyDrillExecuteIntervalTimeByDeptId(query.getDeptId()); - emergencyExecuteTimeRPCResp.setLastTime(lastTime); - emergencyExecuteTimeRPCResp.setDays(TimeUtils.differentDays(lastTime, TimeUtils.formatDate(new Date()))); + emergencyExecuteTimeRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId()); - return new SearchResultVO<>( + getSingleTimeData(emergencyExecuteTimeRPCResp); + SearchResultVO searchResultVO = new SearchResultVO<>( false, null, null, null, - 1L, + null, emergencyExecuteTimeRPCResp, ResultCodes.OK ); + searchResultVO.setCount(1); + return searchResultVO; } @Override public SearchResultVO<List<EmergencyExecuteTimeRPCResp>> getTimeByDeptIds(EmergencyExecuteTimeRPCReq query) { List<EmergencyExecuteTimeRPCResp> list = new ArrayList<>(); - return new SearchResultVO<>( + + // 获取该部门及其子部门的所有信息 + List<DepInfoRPCRespDTO> depList = getDepListInfoByDepId(query.getDeptId()); + for (DepInfoRPCRespDTO depInfoRPCRespDTO : depList){ + EmergencyExecuteTimeRPCResp emergencyExecuteTimeRPCResp = new EmergencyExecuteTimeRPCResp(); + emergencyExecuteTimeRPCResp.setDeptId(depInfoRPCRespDTO.getDepId()); + emergencyExecuteTimeRPCResp.setDeptName(depInfoRPCRespDTO.getDepName()); + emergencyExecuteTimeRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel()); + emergencyExecuteTimeRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId()); + + getSingleTimeData(emergencyExecuteTimeRPCResp); + list.add(emergencyExecuteTimeRPCResp); + } + + 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(EmergencyExecuteTimeRPCResp emergencyExecuteTimeRPCResp){ + // 查询该部门最后一次演练时间 + String lastTime = emergencyDrillExecuteInfoService.selectEmergencyDrillExecuteIntervalTimeByDeptId(emergencyExecuteTimeRPCResp.getDeptId()); + if (StringUtils.isNotBlank(lastTime)){ + emergencyExecuteTimeRPCResp.setLastTime(lastTime); +// emergencyExecuteTimeRPCResp.setDays(TimeUtils.differentDays(lastTime, TimeUtils.formatDate(new Date()))); + } } @Override @@ -91,45 +121,108 @@ EmergencyExecuteNumRPCResp emergencyExecuteNumRPCResp = new EmergencyExecuteNumRPCResp(); // 获取id对应的部门 DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId()); - emergencyExecuteNumRPCResp.setDeptId(depInfoRPCRespDTO.getDepId()); emergencyExecuteNumRPCResp.setDeptName(depInfoRPCRespDTO.getDepName()); emergencyExecuteNumRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel()); + emergencyExecuteNumRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId()); - // 查到该年度对应月份的数据 - List<Map<String,String>> mapList = new ArrayList<>(); - String startTime = TimeUtils.getYearFirst(query.getYear()); - String endTime = TimeUtils.getYearLast(query.getYear()); - List<Long> deptIds = new ArrayList<>(); - deptIds.add(query.getDeptId()); - List<EmergencyDrillExecuteCountData> emergencyDrillExecuteCountDataList = emergencyDrillExecuteInfoService.selectByMonthAndDept(startTime, endTime, deptIds); - if (!emergencyDrillExecuteCountDataList.isEmpty()){ - for (EmergencyDrillExecuteCountData emergencyDrillExecuteCountData : emergencyDrillExecuteCountDataList){ - Map<String ,String> map = new HashMap<>(); - map.put("name",emergencyDrillExecuteCountData.getName()); - map.put("num",emergencyDrillExecuteCountData.getNum().toString()); - mapList.add(map); - } - } - emergencyExecuteNumRPCResp.setData(mapList); + getSingleNumData(emergencyExecuteNumRPCResp,query); - return new SearchResultVO<>( + SearchResultVO searchResultVO = new SearchResultVO<>( false, null, null, null, - 1L, + null, emergencyExecuteNumRPCResp, ResultCodes.OK ); + searchResultVO.setCount(1); + return searchResultVO; } @Override public SearchResultVO<List<EmergencyExecuteNumRPCResp>> getNumByDeptIds(EmergencyExecuteNumRPCReq query) { - return null; + List<EmergencyExecuteNumRPCResp> list = new ArrayList<>(); + + // 获取该部门及其子部门的所有信息 + List<DepInfoRPCRespDTO> deptList = getDepListInfoByDepId(query.getDeptId()); + + for (DepInfoRPCRespDTO depInfoRPCRespDTO : deptList){ + EmergencyExecuteNumRPCResp emergencyExecuteNumRPCResp = new EmergencyExecuteNumRPCResp(); + emergencyExecuteNumRPCResp.setDeptId(depInfoRPCRespDTO.getDepId()); + emergencyExecuteNumRPCResp.setDeptName(depInfoRPCRespDTO.getDepName()); + emergencyExecuteNumRPCResp.setDeptLevel(depInfoRPCRespDTO.getDepLevel()); + emergencyExecuteNumRPCResp.setParentDepId(depInfoRPCRespDTO.getParentDepId()); + + getSingleNumData(emergencyExecuteNumRPCResp,query); + list.add(emergencyExecuteNumRPCResp); + } + + SearchResultVO searchResultVO = new SearchResultVO<>( + false, + null, + null, + null, + null, + list, + ResultCodes.OK + ); + if (!list.isEmpty()){ + searchResultVO.setCount(list.size()); + } + return searchResultVO; } - public DepInfoRPCRespDTO getDepInfoByDepId(Long deptId) { + + + private void getSingleNumData(EmergencyExecuteNumRPCResp emergencyExecuteNumRPCResp,EmergencyExecuteNumRPCReq query){ + List<Long> deptIds = new ArrayList<>(); + deptIds.add(emergencyExecuteNumRPCResp.getDeptId()); + + List<Map<String,Integer>> mapList = new ArrayList<>(); + List<EmergencyDrillExecuteCountRPC> emergencyDrillExecuteCountDataList = new ArrayList<>(); + String startTime ; + String endTime ; + Integer distType; + if (query.getMonth()==null){ + distType=1; + // 查该年度12个月份的 + startTime = TimeUtils.getYearFirst(query.getYear()); + endTime = TimeUtils.getYearLast(query.getYear()); + emergencyDrillExecuteCountDataList= emergencyDrillExecuteInfoService.selectByMonthAndDeptForIntegerMonth(startTime, endTime, deptIds); + }else{ + // 查该年度指定月份的 + distType=2; + startTime = TimeUtils.getMonthFirst(query.getYear(),query.getMonth()); + endTime = TimeUtils.getMonthLast(query.getYear(),query.getMonth()); + emergencyDrillExecuteCountDataList= emergencyDrillExecuteInfoService.selectByDayAndDept(startTime, endTime, deptIds); + } + if (!emergencyDrillExecuteCountDataList.isEmpty()){ + List<EmergencyExecuteNumDetailRPCResp> detailList =new ArrayList<>(); + for (EmergencyDrillExecuteCountRPC emergencyDrillExecuteCountRPC : emergencyDrillExecuteCountDataList){ + + EmergencyExecuteNumDetailRPCResp emergencyExecuteNumDetailRPCResp = new EmergencyExecuteNumDetailRPCResp(); + + emergencyExecuteNumDetailRPCResp.setTime(emergencyDrillExecuteCountRPC.getName()); + emergencyExecuteNumDetailRPCResp.setDistType(distType); + emergencyExecuteNumDetailRPCResp.setYear(query.getYear()); + if (distType==1){ + emergencyExecuteNumDetailRPCResp.setMonth(emergencyDrillExecuteCountRPC.getName()); + } + if (distType==2){ + emergencyExecuteNumDetailRPCResp.setMonth(query.getMonth()); + emergencyExecuteNumDetailRPCResp.setDay(emergencyDrillExecuteCountRPC.getName()); + } + emergencyExecuteNumDetailRPCResp.setNum(emergencyDrillExecuteCountRPC.getNum()); + detailList.add(emergencyExecuteNumDetailRPCResp); + } + emergencyExecuteNumRPCResp.setDetail(detailList); + } + + } + + private DepInfoRPCRespDTO getDepInfoByDepId(Long deptId) { DepInfoRPCRespDTO dep = new DepInfoRPCRespDTO(); ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(deptId); if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) { @@ -140,6 +233,19 @@ throw new BusinessException(ResultCodes.CLIENT_DEP_NOT_EXIST); } 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 @@ -236,5 +342,277 @@ ResultCodes.OK ); } + /**********************************重构****************************************************/ + /** + * 查询部门最后一次演练时间 + * @param deptId + * @return + */ + @Override + public EmergencyExecuteTimeRespDTO getLastTimeByDeptId(Long deptId) { + if(null == deptId){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL); + } + + //通过RPC获取部门相关数据 + DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(deptId); + // 查询该部门最后一次演练时间 + String lastTime = emergencyDrillExecuteInfoService.getLastTimeByDeptId(deptId); + //填充数据 + EmergencyExecuteTimeRespDTO respDTO = new EmergencyExecuteTimeRespDTO(); + respDTO.setDepId(depInfoRPCRespDTO.getDepId()); + respDTO.setDepLevel(depInfoRPCRespDTO.getDepLevel()); + respDTO.setLastPricticeTime(StringUtils.isBlank(lastTime) == true ? "" : lastTime); + + return respDTO; + } + + /** + * 查询部门及其子级部门最后一次演练时间 + * 后面按部门等级划分 + */ + public EmergencyExecuteTimeRespDTO getLastTimeByDeptIds(Long deptId){ + + if(null == deptId){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL); + } + //通过RPC获取部门相关数据 + List<DepInfoRPCRespDTO> depInfoList = getDepListInfoByDepId(deptId); + //过滤获取部门id + List<Long> deptIdList = depInfoList + .stream() + .map(dep -> dep.getDepId()) + .collect(Collectors.toList()); + //过滤出传入部门的信息 + List<DepInfoRPCRespDTO> selectDepList = depInfoList + .stream() + .filter(dep -> dep.getDepId().equals(deptId)) + .collect(Collectors.toList()); + // 查询该部门ids最后一次演练时间 + String lastTime = emergencyDrillExecuteInfoService.getLastTimeByDeptIds(deptIdList); + + //填充数据 + EmergencyExecuteTimeRespDTO respDTO = new EmergencyExecuteTimeRespDTO(); + respDTO.setDepId(deptId); + respDTO.setLastPricticeTime(StringUtils.isBlank(lastTime) == true ? "" : lastTime); + if(selectDepList.size()>0){ + respDTO.setDepLevel(selectDepList.get(0).getDepLevel()); + } + return respDTO; + } + + /** + * 根据部门id和指定年份 统计演练数据 + * + */ + public StatisticsDepLevelYearExecuteRespDTO getCountByDeptIdAndYear(EmergencyDrillCountQuery query){ + if(null == query.getDeptId()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"部门id不可为空"); + } + if(null == query.getYear()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"年份不可为空"); + } + //通过RPC获取部门相关数据 + DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId()); + //填充数据 + StatisticsDepLevelYearExecuteRespDTO respDTO = new StatisticsDepLevelYearExecuteRespDTO(); + respDTO.setDepLevel(depInfoRPCRespDTO.getDepLevel()); + respDTO.setYear(query.getYear()); + //获取指定部门指定时间下的应急数据 + List<EmergencyExecuteCountDO> executeCountDOList = emergencyDrillExecuteInfoService.getCountByDeptIdAndYear(query.getYear(),query.getDeptId()); + //声明月份 + int allMonth = 12; + //判断是否是当前年分 +// if(query.getYear().equals(TimeUtils.getCurrentYear())){ +// allMonth = TimeUtils.getCurrentMonth(); +// } + //总数量 + int totalCount = 0; + List<StatisticsMonthExecuteCountRespDTO> executeCountRespDTOList = new ArrayList<>(); + //循环月份 + for(int i = 1;i <= allMonth; i++){ + StatisticsMonthExecuteCountRespDTO executeCountRespDTO = new StatisticsMonthExecuteCountRespDTO(); + executeCountRespDTO.setYear(query.getYear()); + executeCountRespDTO.setMonth(i); + //获取当月数据 + int month = i; + List<EmergencyExecuteCountDO> selectMonthList = executeCountDOList + .stream() + .filter(ac -> ac.getMonth().equals(month)) + .collect(Collectors.toList()); + if(selectMonthList.size()>0){ + executeCountRespDTO.setCount(selectMonthList.get(0).getCount()); + totalCount += selectMonthList.get(0).getCount(); + }else{ + executeCountRespDTO.setCount(0); + } + executeCountRespDTOList.add(executeCountRespDTO); + } + respDTO.setYearTotalCount(totalCount); + respDTO.setMonthExecuteCountList(executeCountRespDTOList); + return respDTO; + } + + /** + * 根据指定部门、月份 统计演练数据 + * @param query + * @return + */ + @Override + public StatisticsDepLevelMonthEexcuteRespDTO getCountByDeptIdAndMonth(EmergencyDrillCountQuery query) { + if(null == query.getDeptId()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"部门id不可为空"); + } + if(null == query.getYear()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"年份不可为空"); + } + if(null == query.getMonth()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"月份不可为空"); + } + //通过RPC获取部门相关数据 + DepInfoRPCRespDTO depInfoRPCRespDTO = getDepInfoByDepId(query.getDeptId()); + //获取指定月份的演练数据 + EmergencyExecuteCountDO executeCountDO = emergencyDrillExecuteInfoService.getCountByDeptIdAndMonth(query.getYear(),query.getMonth(), query.getDeptId()); + //填充数据 + StatisticsDepLevelMonthEexcuteRespDTO respDTO = new StatisticsDepLevelMonthEexcuteRespDTO(); + respDTO.setDepLevel(depInfoRPCRespDTO.getDepLevel()); + respDTO.setMonth(query.getMonth()); + respDTO.setExecuteCount(executeCountDO.getCount()); + return respDTO; + } + + /** + * 根据部门id及其子级部门和指定年份 统计演练数据 + * + */ + public List<StatisticsDepLevelYearExecuteRespDTO> getCountByDeptIdsAndYear(EmergencyDrillCountQuery query){ + if(null == query.getDeptId()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"部门id不可为空"); + } + if(null == query.getYear()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"年份不可为空"); + } + //通过RPC获取部门相关数据 + List<DepInfoRPCRespDTO> depInfoList = getDepListInfoByDepId(query.getDeptId()); + //过滤获取部门id + List<Long> deptIds = depInfoList + .stream() + .map(dep -> dep.getDepId()) + .collect(Collectors.toList()); + //开始时间结束时间 + String startTime = TimeUtils.getYearFirst(query.getYear()); + String endTime = TimeUtils.getYearLast(query.getYear()); + //获取指定部门指定时间下的应急数据 + List<EmergencyExecuteCountDO> executeCountDOList = emergencyDrillExecuteInfoService.getCountByDeptIdsAndTime(startTime,endTime,deptIds); + + List<StatisticsDepLevelYearExecuteRespDTO> respDTOList = new ArrayList<>(); + //循环部门等级 + for(DepartmentLevelEnum departmentLevelEnum : DepartmentLevelEnum.values()){ + //填充部门级别数据 + StatisticsDepLevelYearExecuteRespDTO respDTO = new StatisticsDepLevelYearExecuteRespDTO(); + respDTO.setDepLevel(departmentLevelEnum.getCode()); + respDTO.setYear(query.getYear()); + + //获取该部门级别下面的相关部门 + List<DepInfoRPCRespDTO> selectDepList = depInfoList + .stream() + .filter(dep -> dep.getDepLevel().equals(departmentLevelEnum.getCode())) + .collect(Collectors.toList()); + //获取该部门级别下相关部门演练数据 + List<EmergencyExecuteCountDO> selectExeList = executeCountDOList + .stream() + .filter(exe -> selectDepList.stream().map(dep -> dep.getDepId()).collect(Collectors.toList()).contains(exe.getDeptId())) + .collect(Collectors.toList()); + + List<StatisticsMonthExecuteCountRespDTO> monthExecuteCountList = new ArrayList<>(); + + //声明月份 + int allMonth = 12; + //声明一年总数量 + int yearTotalCount =0; + //判断是否是当前年分 +// if(query.getYear().equals(TimeUtils.getCurrentYear())){ +// allMonth = TimeUtils.getCurrentMonth(); +// } + //12个月份 + for(int i = 1;i <= allMonth;i++){ + //数量 + int count = 0; + //循环 + for(EmergencyExecuteCountDO executeCountDO : selectExeList){ + if(executeCountDO.getMonth() == i){ + count += executeCountDO.getCount(); + yearTotalCount += executeCountDO.getCount(); + } + } + StatisticsMonthExecuteCountRespDTO executeCountRespDTO = new StatisticsMonthExecuteCountRespDTO(); + executeCountRespDTO.setYear(query.getYear()); + executeCountRespDTO.setMonth(i); + executeCountRespDTO.setCount(count); + monthExecuteCountList.add(executeCountRespDTO); + } + respDTO.setMonthExecuteCountList(monthExecuteCountList); + respDTO.setYearTotalCount(yearTotalCount); + respDTOList.add(respDTO); + } + return respDTOList; + } + /** + * 根据部门id及其子级部门和指定者月份 统计演练数据 + * + */ + @Override + public List<StatisticsDepLevelMonthEexcuteRespDTO> getCountByDeptIdsAndMonth(EmergencyDrillCountQuery query) { + if(null == query.getDeptId()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"部门id不可为空"); + } + if(null == query.getYear()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"年份不可为空"); + } + if(null == query.getMonth()){ + throw new EmergencyException(EmergencyResultCodes.SUPPLIES_PARAM_NULL,"月份不可为空"); + } + //通过RPC获取部门相关数据 + List<DepInfoRPCRespDTO> depInfoList = getDepListInfoByDepId(query.getDeptId()); + //过滤获取部门id + List<Long> deptIds = depInfoList + .stream() + .map(dep -> dep.getDepId()) + .collect(Collectors.toList()); + //开始时间结束时间 + String startTime = TimeUtils.getMonthFirst(query.getYear(),query.getMonth()); + String endTime = TimeUtils.getMonthLast(query.getYear(),query.getMonth()); + //获取演练数据 + List<EmergencyExecuteCountDO> executeCountDOList = emergencyDrillExecuteInfoService.getCountByDeptIdsAndTime(startTime,endTime,deptIds); + List<StatisticsDepLevelMonthEexcuteRespDTO> respDTOList = new ArrayList<>(); + //循环部门等级 + for(DepartmentLevelEnum departmentLevelEnum : DepartmentLevelEnum.values()) { + //填充部门级别数据 + StatisticsDepLevelMonthEexcuteRespDTO respDTO = new StatisticsDepLevelMonthEexcuteRespDTO(); + respDTO.setDepLevel(departmentLevelEnum.getCode()); + respDTO.setMonth(query.getMonth()); + + //获取该部门级别下面的相关部门 + List<DepInfoRPCRespDTO> selectDepList = depInfoList + .stream() + .filter(dep -> dep.getDepLevel().equals(departmentLevelEnum.getCode())) + .collect(Collectors.toList()); + //获取该部门级别下相关部门演练数据 + List<EmergencyExecuteCountDO> selectExeList = executeCountDOList + .stream() + .filter(exe -> selectDepList.stream().map(dep -> dep.getDepId()).collect(Collectors.toList()).contains(exe.getDeptId())) + .collect(Collectors.toList()); + //数量 + int count = 0; + //循环 + for(EmergencyExecuteCountDO executeCountDO : selectExeList){ + count += executeCountDO.getCount(); + } + respDTO.setExecuteCount(count); + respDTOList.add(respDTO); + } + return respDTOList; + } + } -- Gitblit v1.9.2