zhangf
2024-05-09 4915493db5013f4e0857ac7127616781732c2d6c
emergency/emergency-rpc-provider/src/main/java/com/gkhy/safePlatform/emergency/rpc/provider/EmergencyRpcProvider.java
@@ -6,17 +6,20 @@
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.emergency.model.dto.resp.EmergencySuppliesRespDTO;
import com.gkhy.safePlatform.emergency.model.dto.resp.EmergencySuppliesTypeRespDTO;
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.EmergencyDrillTimeQuery;
import com.gkhy.safePlatform.emergency.rpc.api.EmergencyRpcAPi;
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.req.EmergencyExecuteCountRPCReq;
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.EmergencyExecuteNumRPCResp;
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.EmergencyExecuteTimeRPCResp;
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.EmergencySuppliesRPCResp;
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.EmergencySuppliesTypeRPCResp;
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.req.EmergencydrillTimeRPCReq;
import com.gkhy.safePlatform.emergency.rpc.api.model.dto.resp.*;
import com.gkhy.safePlatform.emergency.service.EmergencyCountService;
import com.gkhy.safePlatform.emergency.service.EmergencySuppliesService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
@@ -24,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@DubboService
public class EmergencyRpcProvider implements EmergencyRpcAPi {
@@ -54,32 +58,285 @@
        return emergencyCountService.getNumByDeptIds(query);
    }
    @Override
    public ResultVO<List<EmergencySuppliesTypeRPCResp>> emergencySuppliesList(ContextCacheUser currentUser) {
       List<EmergencySuppliesTypeRespDTO> list = (List<EmergencySuppliesTypeRespDTO>)emergencySuppliesService.emergencySuppliesList(currentUser).getData();
       List<EmergencySuppliesTypeRPCResp> typeRPCRespList = new ArrayList<>();
        for (EmergencySuppliesTypeRespDTO typeRespDTO:list) {
            EmergencySuppliesTypeRPCResp typeRPCResp = new EmergencySuppliesTypeRPCResp();
            typeRPCResp.setMaterialType(typeRespDTO.getMaterialType());
            typeRPCResp.setMaterialTypeName(typeRespDTO.getMaterialTypeName());
            if(!CollectionUtils.isEmpty(typeRespDTO.getList())){
                List<EmergencySuppliesRPCResp> emergencySuppliesRPCRespList = BeanCopyUtils.copyBeanList(typeRespDTO.getList(), EmergencySuppliesRPCResp.class);
                typeRPCResp.setList(emergencySuppliesRPCRespList);
        ResultVO<List<EmergencySuppliesTypeRPCResp>> result = new ResultVO<>(ResultCodes.OK);
        List<EmergencySuppliesTypeRPCResp> typeRPCRespList = new ArrayList<>();
        try{
            List<EmergencySuppliesTypeRespDTO> typeRespDTOList = emergencySuppliesService.emergencySuppliesList(currentUser);
            for (EmergencySuppliesTypeRespDTO typeRespDTO:typeRespDTOList) {
                EmergencySuppliesTypeRPCResp typeRPCResp = new EmergencySuppliesTypeRPCResp();
                typeRPCResp.setMaterialType(typeRespDTO.getMaterialType());
                typeRPCResp.setMaterialTypeName(typeRespDTO.getMaterialTypeName());
                if(!CollectionUtils.isEmpty(typeRespDTO.getList())){
                    List<EmergencySuppliesRPCResp> emergencySuppliesRPCRespList = BeanCopyUtils.copyBeanList(typeRespDTO.getList(), EmergencySuppliesRPCResp.class);
                    typeRPCResp.setList(emergencySuppliesRPCRespList);
                }
                typeRPCRespList.add(typeRPCResp);
            }
            typeRPCRespList.add(typeRPCResp);
            result.setData(typeRPCRespList);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return new ResultVO<>(ResultCodes.OK,typeRPCRespList);
        return result;
    }
    @Override
    public ResultVO<List<EmergencySuppliesRPCResp>> listCountByIds(ContextCacheUser currentUser,List<Long> ids) {
        List<EmergencySuppliesRespDTO> list = (List<EmergencySuppliesRespDTO>)emergencySuppliesService.listCountByIds(currentUser,ids).getData();
        List<EmergencySuppliesRPCResp> emergencySuppliesRPCRespList = null;
        if(!CollectionUtils.isEmpty(list)){
            emergencySuppliesRPCRespList = BeanCopyUtils.copyBeanList(list, EmergencySuppliesRPCResp.class);
        ResultVO<List<EmergencySuppliesRPCResp>> result = new ResultVO<>(ResultCodes.OK);
        try{
            List<EmergencySuppliesRPCResp> emergencySuppliesRPCRespList = new ArrayList<>();
            List<EmergencySuppliesRespDTO> respDTOList = emergencySuppliesService.listCountByIds(currentUser, ids);
            if(!CollectionUtils.isEmpty(respDTOList)){
                emergencySuppliesRPCRespList = BeanCopyUtils.copyBeanList(respDTOList, EmergencySuppliesRPCResp.class);
            }
            result.setData(emergencySuppliesRPCRespList);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return new ResultVO<>(ResultCodes.OK,emergencySuppliesRPCRespList);
        return result;
    }
    @Override
    public ResultVO<EmergencyExecuteTimeRPCRespDTO> getExecuteLastTimeByDeptId(Long depId) {
        ResultVO<EmergencyExecuteTimeRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        try{
            EmergencyExecuteTimeRPCRespDTO lastTimeRPCResp = new EmergencyExecuteTimeRPCRespDTO();
            EmergencyExecuteTimeRespDTO timeRespDTO = emergencyCountService.getLastTimeByDeptId(depId);
            if(null != timeRespDTO){
                BeanUtils.copyProperties(timeRespDTO,lastTimeRPCResp);
            }
            result.setData(lastTimeRPCResp);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<List<EmergencyExecuteDepLevelLasTimeRPCRespDTO>> getExecuteLastTimeByDeptIds(Long depId) {
        ResultVO<List<EmergencyExecuteDepLevelLasTimeRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        try{
            List<EmergencyExecuteDepLevelLasTimeRespDTO> lasTimeRespDTOS = emergencyCountService.getLastTimeByDeptIds(depId);
            List<EmergencyExecuteDepLevelLasTimeRPCRespDTO> timeRPCRespDTOS = new ArrayList<>();
            for(EmergencyExecuteDepLevelLasTimeRespDTO timeRespDTO:lasTimeRespDTOS){
                if(timeRespDTO != null){
                    EmergencyExecuteDepLevelLasTimeRPCRespDTO timeRPCRespDTO = new EmergencyExecuteDepLevelLasTimeRPCRespDTO();
                    BeanUtils.copyProperties(timeRespDTO,timeRPCRespDTO);
                    timeRPCRespDTOS.add(timeRPCRespDTO);
                }
            }
            result.setData(timeRPCRespDTOS);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<EmergencyExecuteLastTimeRPCRespDTO> getExecuteLastTimeByDeptIdAndTime(EmergencydrillTimeRPCReq query) {
        ResultVO<EmergencyExecuteLastTimeRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        EmergencyDrillTimeQuery timeQuery = new EmergencyDrillTimeQuery();
        timeQuery.setDeptId(query.getDeptId());
        timeQuery.setYear(query.getYear());
        timeQuery.setMonth(query.getMonth());
        try{
            EmergencyExecuteLastTimeRPCRespDTO lastTimeRPCResp = new EmergencyExecuteLastTimeRPCRespDTO();
            EmergencyExecuteLastTimeRespDTO timeRespDTO = emergencyCountService.getLastPracticeTimeByDeptIdAndTime(timeQuery);
            if(null != timeRespDTO){
                BeanUtils.copyProperties(timeRespDTO,lastTimeRPCResp);
            }
            result.setData(lastTimeRPCResp);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<List<EmergencyExecuteDepLevelLasTimeRPCRespDTO>> getExecuteLastTimeByDeptIdsAndTime(EmergencydrillTimeRPCReq query) {
        ResultVO<List<EmergencyExecuteDepLevelLasTimeRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        EmergencyDrillTimeQuery timeQuery = new EmergencyDrillTimeQuery();
        timeQuery.setDeptId(query.getDeptId());
        timeQuery.setYear(query.getYear());
        timeQuery.setMonth(query.getMonth());
        try{
            List<EmergencyExecuteDepLevelLasTimeRPCRespDTO> levelLasTimeRPCRespDTOS = new ArrayList<>();
            List<EmergencyExecuteDepLevelLasTimeRespDTO> lasTimeRespDTOS = emergencyCountService.getLastPracticeTimeByDeptIdsAndTime(timeQuery);
            for(EmergencyExecuteDepLevelLasTimeRespDTO lastTimeRPCRespDTO :lasTimeRespDTOS){
                if(null != lastTimeRPCRespDTO){
                    EmergencyExecuteDepLevelLasTimeRPCRespDTO levelLasTimeRPCRespDTO = new EmergencyExecuteDepLevelLasTimeRPCRespDTO();
                    BeanUtils.copyProperties(lastTimeRPCRespDTO,levelLasTimeRPCRespDTO);
                    levelLasTimeRPCRespDTOS.add(levelLasTimeRPCRespDTO);
                }
            }
            result.setData(levelLasTimeRPCRespDTOS);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<StatisticsDepLevelMonthEexcuteRPCRespDTO> getExecuteCountByDeptIdAndMonth(EmergencyExecuteCountRPCReq query) {
        ResultVO<StatisticsDepLevelMonthEexcuteRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        EmergencyDrillCountQuery countQuery = new EmergencyDrillCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        countQuery.setMonth(query.getMonth());
        try{
            StatisticsDepLevelMonthEexcuteRespDTO monthEexcuteRespDTO = emergencyCountService.getCountByDeptIdAndMonth(countQuery);
            StatisticsDepLevelMonthEexcuteRPCRespDTO monthEexcuteRPCRespDTO = new StatisticsDepLevelMonthEexcuteRPCRespDTO();
            monthEexcuteRPCRespDTO.setDepLevel(monthEexcuteRespDTO.getDepLevel());
            monthEexcuteRPCRespDTO.setExecuteCount(monthEexcuteRespDTO.getExecuteCount());
            monthEexcuteRPCRespDTO.setMonth(monthEexcuteRespDTO.getMonth());
            result.setData(monthEexcuteRPCRespDTO);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<StatisticsDepLevelYearExecuteRPCRespDTO> getExecuteCountByDeptIdAndYear(EmergencyExecuteCountRPCReq query) {
        ResultVO<StatisticsDepLevelYearExecuteRPCRespDTO> result = new ResultVO<>(ResultCodes.OK);
        EmergencyDrillCountQuery countQuery = new EmergencyDrillCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        try{
            StatisticsDepLevelYearExecuteRespDTO executeRespDTO = emergencyCountService.getCountByDeptIdAndYear(countQuery);
            StatisticsDepLevelYearExecuteRPCRespDTO executeRPCRespDTO = new StatisticsDepLevelYearExecuteRPCRespDTO();
            executeRPCRespDTO.setDepLevel(executeRespDTO.getDepLevel());
            executeRPCRespDTO.setYear(executeRespDTO.getYear());
            executeRPCRespDTO.setYearTotalCount(executeRespDTO.getYearTotalCount());
            List<StatisticsMonthExecuteCountRespDTO> monthExecuteCountList = executeRespDTO.getMonthExecuteCountList();
            if(!CollectionUtils.isEmpty(monthExecuteCountList)){
                List<StatisticsMonthExecuteCountRPCRespDTO> monthExecuteCountRPCRespDTOList = BeanCopyUtils.copyBeanList(monthExecuteCountList, StatisticsMonthExecuteCountRPCRespDTO.class);
                executeRPCRespDTO.setMonthExecuteCountList(monthExecuteCountRPCRespDTOList);
            }
            result.setData(executeRPCRespDTO);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<List<StatisticsDepLevelMonthEexcuteRPCRespDTO>> getExecuteCountByDeptIdsAndMonth(EmergencyExecuteCountRPCReq query) {
        ResultVO<List<StatisticsDepLevelMonthEexcuteRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        EmergencyDrillCountQuery countQuery = new EmergencyDrillCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        countQuery.setMonth(query.getMonth());
        try{
            List<StatisticsDepLevelMonthEexcuteRespDTO> monthEexcuteRespDTOList = emergencyCountService.getCountByDeptIdsAndMonth(countQuery);
            if(!CollectionUtils.isEmpty(monthEexcuteRespDTOList)){
                List<StatisticsDepLevelMonthEexcuteRPCRespDTO> monthExecuteCountRPCRespDTOList = BeanCopyUtils.copyBeanList(monthEexcuteRespDTOList, StatisticsDepLevelMonthEexcuteRPCRespDTO.class);
                result.setData(monthExecuteCountRPCRespDTOList);
            }
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<List<StatisticsDepLevelYearExecuteRPCRespDTO>> getExecuteCountByDeptIdsAndYear(EmergencyExecuteCountRPCReq query) {
        ResultVO<List<StatisticsDepLevelYearExecuteRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        EmergencyDrillCountQuery countQuery = new EmergencyDrillCountQuery();
        countQuery.setDeptId(query.getDeptId());
        countQuery.setYear(query.getYear());
        try{
            List<StatisticsDepLevelYearExecuteRespDTO> executeRespDTOList = emergencyCountService.getCountByDeptIdsAndYear(countQuery);
            List<StatisticsDepLevelYearExecuteRPCRespDTO> RPCRespDTO = new ArrayList<>();
            for(StatisticsDepLevelYearExecuteRespDTO vo : executeRespDTOList){
                StatisticsDepLevelYearExecuteRPCRespDTO executeRPCRespDTO = new StatisticsDepLevelYearExecuteRPCRespDTO();
                executeRPCRespDTO.setDepLevel(vo.getDepLevel());
                executeRPCRespDTO.setYear(vo.getYear());
                executeRPCRespDTO.setYearTotalCount(vo.getYearTotalCount());
                List<StatisticsMonthExecuteCountRespDTO> monthExecuteCountList = vo.getMonthExecuteCountList();
                if(!CollectionUtils.isEmpty(monthExecuteCountList)){
                    List<StatisticsMonthExecuteCountRPCRespDTO> monthExecuteCountRPCRespDTOList = BeanCopyUtils.copyBeanList(monthExecuteCountList, StatisticsMonthExecuteCountRPCRespDTO.class);
                    executeRPCRespDTO.setMonthExecuteCountList(monthExecuteCountRPCRespDTOList);
                }
                RPCRespDTO.add(executeRPCRespDTO);
            }
            result.setData(RPCRespDTO);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
    @Override
    public ResultVO<List<EmergencySuppliesInfoRPCRespDTO>> getEmergencySupplies() {
        ResultVO<List<EmergencySuppliesInfoRPCRespDTO>> result = new ResultVO<>(ResultCodes.OK);
        try{
            List<EmergencySuppliesInfoRespDTO> emergencySupplies = emergencySuppliesService.getEmergencySupplies();
            List<EmergencySuppliesInfoRPCRespDTO> collect = new ArrayList<>();
            for (EmergencySuppliesInfoRespDTO emergencySupply : emergencySupplies) {
                EmergencySuppliesInfoRPCRespDTO emergencySupplyDTO = new EmergencySuppliesInfoRPCRespDTO();
                BeanUtils.copyProperties(emergencySupply, emergencySupplyDTO);
                collect.add(emergencySupplyDTO);
            }
            result.setData(collect);
        }catch (EmergencyException e){
            result.setCode(e.getCode());
            result.setMsg(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            result.setCode(EmergencyResultCodes.ERROR.getCode());
            result.setMsg(EmergencyResultCodes.ERROR.getDesc());
        }
        return result;
    }
}