package com.gkhy.safePlatform.incidentManage.rpc.provider; 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.vo.ResultVO; import com.gkhy.safePlatform.commons.vo.SearchResultVO; import com.gkhy.safePlatform.incidentManage.enums.AccidentResultCodes; import com.gkhy.safePlatform.incidentManage.exception.AccidentException; import com.gkhy.safePlatform.incidentManage.model.dto.resp.*; import com.gkhy.safePlatform.incidentManage.query.IncidentManageCountQuery; import com.gkhy.safePlatform.incidentManage.rpc.api.IncidentManageRpcAPi; import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.req.IncidentManageCountRPCReq; import com.gkhy.safePlatform.incidentManage.rpc.api.model.dto.resp.*; import com.gkhy.safePlatform.incidentManage.service.AccidentCountService; import org.apache.commons.collections.CollectionUtils; import org.apache.dubbo.config.annotation.DubboService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; import java.util.List; @DubboService public class IncidentManageRpcProvider implements IncidentManageRpcAPi { @Autowired private AccidentCountService accidentCountService; @Override public SearchResultVO getCountByDeptId(IncidentManageCountRPCReq query) { return accidentCountService.getCountByDeptId(query); } @Override public SearchResultVO> getCountByDeptIds(IncidentManageCountRPCReq query) { return accidentCountService.getCountByDeptIds(query); } @Override public ResultVO getAccidentCountByDeptIdAndMonth(IncidentManageCountRPCReq query) { ResultVO result = new ResultVO<>(ResultCodes.OK); IncidentManageCountQuery countQuery = new IncidentManageCountQuery(); countQuery.setDeptId(query.getDeptId()); countQuery.setYear(query.getYear()); countQuery.setMonth(query.getMonth()); try{ StatisticsDepLevelMonthAccidentRespDTO accidentRespDTO = accidentCountService.getCountByDeptIdAndMonth(countQuery); StatisticsDepLevelMonthAccidentRPCRespDTO accidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO(); accidentRPCRespDTO.setMonth(accidentRespDTO.getMonth()); accidentRPCRespDTO.setDepLevel(accidentRespDTO.getDepLevel()); List accidentLevelList = accidentRespDTO.getAccidentLevelList(); if(!CollectionUtils.isEmpty(accidentLevelList)){ List resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class); accidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList); } result.setData(accidentRPCRespDTO); }catch (AccidentException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (Exception e) { result.setCode(AccidentResultCodes.ERROR.getCode()); result.setMsg(AccidentResultCodes.ERROR.getDesc()); } return result; } @Override public ResultVO getAccidentCountByDeptIdAndYear(IncidentManageCountRPCReq query) { ResultVO result = new ResultVO<>(ResultCodes.OK); IncidentManageCountQuery countQuery = new IncidentManageCountQuery(); countQuery.setDeptId(query.getDeptId()); countQuery.setYear(query.getYear()); countQuery.setMonth(query.getMonth()); try{ StatisticsDeptLevelYearAccidentRespDTO accidentRespDTO = accidentCountService.getCountByDeptIdAndYear(countQuery); StatisticsDeptLevelYearAccidentRPCRespDTO accidentRPCRespDTO = new StatisticsDeptLevelYearAccidentRPCRespDTO(); accidentRPCRespDTO.setYear(accidentRespDTO.getYear()); accidentRPCRespDTO.setDepLevel(accidentRespDTO.getDepLevel()); List monthList = accidentRespDTO.getMonthList(); List monthAccidentRPCRespDTOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(monthList)){ for(StatisticsDepLevelMonthAccidentRespDTO monthAccidentRespDTO : monthList){ StatisticsDepLevelMonthAccidentRPCRespDTO monthAccidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO(); monthAccidentRPCRespDTO.setMonth(monthAccidentRespDTO.getMonth()); monthAccidentRPCRespDTO.setDepLevel(monthAccidentRespDTO.getDepLevel()); List accidentLevelList = monthAccidentRespDTO.getAccidentLevelList(); if(!CollectionUtils.isEmpty(accidentLevelList)){ List resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class); monthAccidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList); } monthAccidentRPCRespDTOList.add(monthAccidentRPCRespDTO); } } accidentRPCRespDTO.setMonthList(monthAccidentRPCRespDTOList); result.setData(accidentRPCRespDTO); }catch (AccidentException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (Exception e) { result.setCode(AccidentResultCodes.ERROR.getCode()); result.setMsg(AccidentResultCodes.ERROR.getDesc()); } return result; } @Override public ResultVO> getAccidentCountByDeptIdsAndMonth(IncidentManageCountRPCReq query) { ResultVO> result = new ResultVO<>(ResultCodes.OK); IncidentManageCountQuery countQuery = new IncidentManageCountQuery(); countQuery.setDeptId(query.getDeptId()); countQuery.setYear(query.getYear()); countQuery.setMonth(query.getMonth()); try{ List accidentRespDTOList = accidentCountService.getCountByDeptIdsAndMonth(countQuery); List accidentRPCRespDTOList = new ArrayList<>(); for(StatisticsDepLevelMonthAccidentRespDTO accidentRespDTO:accidentRespDTOList){ StatisticsDepLevelMonthAccidentRPCRespDTO accidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO(); accidentRPCRespDTO.setMonth(accidentRespDTO.getMonth()); accidentRPCRespDTO.setDepLevel(accidentRespDTO.getDepLevel()); List accidentLevelList = accidentRespDTO.getAccidentLevelList(); if(!CollectionUtils.isEmpty(accidentLevelList)){ List resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class); accidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList); } accidentRPCRespDTOList.add(accidentRPCRespDTO); } result.setData(accidentRPCRespDTOList); }catch (AccidentException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (Exception e) { result.setCode(AccidentResultCodes.ERROR.getCode()); result.setMsg(AccidentResultCodes.ERROR.getDesc()); } return result; } @Override public ResultVO> getAccidentCountByDeptIdsAndYear(IncidentManageCountRPCReq query) { ResultVO> result = new ResultVO<>(ResultCodes.OK); IncidentManageCountQuery countQuery = new IncidentManageCountQuery(); countQuery.setDeptId(query.getDeptId()); countQuery.setYear(query.getYear()); countQuery.setMonth(query.getMonth()); try{ List yearAccidentRespDTOList = accidentCountService.getCountByDeptIdsAndYear(countQuery); List accidentRPCRespDTOList = new ArrayList<>(); for(StatisticsDeptLevelYearAccidentRespDTO yearAccidentRespDTO:yearAccidentRespDTOList){ StatisticsDeptLevelYearAccidentRPCRespDTO yearAccidentRPCRespDTO = new StatisticsDeptLevelYearAccidentRPCRespDTO(); yearAccidentRPCRespDTO.setYear(yearAccidentRespDTO.getYear()); yearAccidentRPCRespDTO.setDepLevel(yearAccidentRespDTO.getDepLevel()); List monthList = yearAccidentRespDTO.getMonthList(); List monthAccidentRPCRespDTOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(monthList)){ for(StatisticsDepLevelMonthAccidentRespDTO monthAccidentRespDTO:monthList){ StatisticsDepLevelMonthAccidentRPCRespDTO monthAccidentRPCRespDTO = new StatisticsDepLevelMonthAccidentRPCRespDTO(); monthAccidentRPCRespDTO.setMonth(monthAccidentRespDTO.getMonth()); monthAccidentRPCRespDTO.setDepLevel(monthAccidentRespDTO.getDepLevel()); List accidentLevelList = monthAccidentRespDTO.getAccidentLevelList(); if (!CollectionUtils.isEmpty(accidentLevelList)) { List resultCountRPCRespDTOList = BeanCopyUtils.copyBeanList(accidentLevelList, AccidentLevelResultCountRPCRespDTO.class); monthAccidentRPCRespDTO.setAccidentLevelList(resultCountRPCRespDTOList); } monthAccidentRPCRespDTOList.add(monthAccidentRPCRespDTO); } } accidentRPCRespDTOList.add(yearAccidentRPCRespDTO); } result.setData(accidentRPCRespDTOList); }catch (AccidentException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (Exception e) { result.setCode(AccidentResultCodes.ERROR.getCode()); result.setMsg(AccidentResultCodes.ERROR.getDesc()); } return result; } @Override public ResultVO> getAccidentCountByGradeAndTime(IncidentManageCountRPCReq query){ ResultVO> result = new ResultVO<>(ResultCodes.OK); try{ List countByAccidentGradeList = accidentCountService.getCountByAccidentGrade(query.getYear(), query.getMonth()); List statisticCountRPCRespDTOList = new ArrayList<>(); for(AccidentStatisticDTO accidentStatisticDTO:countByAccidentGradeList){ IncidentStatisticCountRPCRespDTO accidentRPCRespDTO = new IncidentStatisticCountRPCRespDTO(); accidentRPCRespDTO.setAccidentGrade(accidentStatisticDTO.getAccidentGrade()); accidentRPCRespDTO.setCount(accidentStatisticDTO.getCount()); statisticCountRPCRespDTOList.add(accidentRPCRespDTO); } result.setData(statisticCountRPCRespDTOList); }catch (AccidentException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (BusinessException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (Exception e) { result.setCode(AccidentResultCodes.ERROR.getCode()); result.setMsg(AccidentResultCodes.ERROR.getDesc()); } return result; } @Override public ResultVO getSpiAccidentCountByGradeAndTime(IncidentManageCountRPCReq query){ ResultVO result = new ResultVO<>(ResultCodes.OK); try{ AccidentCountByGradeRespDTO accidentCountByGradeRespDTO = accidentCountService.getSpiAccidentCountByAccidentGrade(query.getYear(), query.getMonth()); AccidentCountByGradeRPCRespDTO accidentRPCRespDTO = new AccidentCountByGradeRPCRespDTO(); BeanUtils.copyProperties(accidentCountByGradeRespDTO, accidentRPCRespDTO); result.setData(accidentRPCRespDTO); }catch (AccidentException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (BusinessException e){ result.setCode(e.getCode()); result.setMsg(e.getMessage()); }catch (Exception e) { result.setCode(AccidentResultCodes.ERROR.getCode()); result.setMsg(AccidentResultCodes.ERROR.getDesc()); } return result; } }