package com.gkhy.safePlatform.emergency.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.query.PageQuery; 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.entity.*; import com.gkhy.safePlatform.emergency.enums.ApproveStatus; import com.gkhy.safePlatform.emergency.enums.EmergencyResultCodes; import com.gkhy.safePlatform.emergency.excepiton.EmergencyException; import com.gkhy.safePlatform.emergency.model.dto.req.*; import com.gkhy.safePlatform.emergency.model.dto.resp.*; import com.gkhy.safePlatform.emergency.query.EmergencyPlanQuery; import com.gkhy.safePlatform.emergency.query.db.EmergencyPlanDBQuery; import com.gkhy.safePlatform.emergency.service.EmergencyPlanService; import com.gkhy.safePlatform.emergency.service.EmergencyWorkApproveService; import com.gkhy.safePlatform.emergency.service.baseService.*; import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.*; import java.util.stream.Collectors; @Service("emergencyPlanService") public class EmergencyPlanServiceImpl implements EmergencyPlanService { @Autowired private EmergencyPlanInfoService emergencyPlanInfoService; @Autowired private EmergencyPlanAreaInfoService emergencyPlanAreaInfoService; @Autowired private EmergencyPlanDepartmentInfoService emergencyPlanDepartmentInfoService; @Autowired private EmergencyPlanTeamInfoService emergencyPlanTeamInfoService; @Autowired private EmergencyPlanFileInfoService emergencyPlanFileInfoService; @Autowired private EmergencyWorkApproveInfoService emergencyWorkApproveInfoService; @DubboReference(check = false) private AccountDepartmentService accountDepartmentService; @Override public SearchResultVO> selectEmergencyPlanList(Long uid , PageQuery query) { Long pageIndex = query.getPageIndex(); Long pageSize = query.getPageSize(); Page page = new Page<>(pageIndex, pageSize); EmergencyPlanDBQuery emergencyPlanDBQuery = new EmergencyPlanDBQuery(); if (query.getSearchParams() != null) { BeanUtils.copyProperties(query.getSearchParams(), emergencyPlanDBQuery); } List emergencyPlanListDoInfoList = emergencyPlanInfoService.selectEmergencyPlanList(page, emergencyPlanDBQuery); List respList = BeanCopyUtils.copyBeanList(emergencyPlanListDoInfoList, EmergencyPlanPageRespDTO.class); // 判断审批人 for (EmergencyPlanPageRespDTO emergencyPlanPageRespDTO :respList){ //获取对应的审批记录 Integer type = ApproveStatus.EMERGENCY.getStatus(); List emergencyWorkApproveInfoDetailDOList = emergencyWorkApproveInfoService.selectWorkApproveByRelateTypeAndRelateId(type,emergencyPlanPageRespDTO.getId()); if (!CollectionUtils.isEmpty(emergencyWorkApproveInfoDetailDOList)) { emergencyPlanPageRespDTO.setApproveId(emergencyWorkApproveInfoDetailDOList.get(0).getId()); emergencyPlanPageRespDTO.setApproveStatus(emergencyWorkApproveInfoDetailDOList.get(0).getApproveStatus()); emergencyPlanPageRespDTO.setApprovePersonId(emergencyWorkApproveInfoDetailDOList.get(0).getApprovePersonId()); // 审批中 判断审批人是否人与当前登录人 if (emergencyPlanPageRespDTO.getApproveStatus()!=null && emergencyPlanPageRespDTO.getApproveStatus()==2){ emergencyPlanPageRespDTO.setCheckApprove(emergencyPlanPageRespDTO.getApprovePersonId().equals(uid)); } } } return new SearchResultVO<>( true, pageIndex, pageSize, page.getPages(), page.getTotal(), respList, ResultCodes.OK ); } @Override public ResultVO addEmergencyPlan(Long uid, EmergencyPlanReqDTO emergencyPlanReqDTO) { Date nowDate = new Date(); // 新增应急预案 EmergencyPlanInfo emergencyPlanInfo = new EmergencyPlanInfo(); BeanUtils.copyProperties(emergencyPlanReqDTO, emergencyPlanInfo); emergencyPlanInfo.setDelFlag(false); emergencyPlanInfo.setCreateUid(uid); emergencyPlanInfo.setGmtCreate(nowDate); emergencyPlanInfo.setAbolishStatus(false); emergencyPlanInfoService.addEmergencyPlan(emergencyPlanInfo); // 新增应急预案区域表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getAreaList())) { addEmergencyPlanArea(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getAreaList()); } // 新增应急预案适用部门表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getDeptList())) { addEmergencyPlanDepartment(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getDeptList()); } // 新增应急预案附件表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getFileList())) { addEmergencyPlanFile(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getFileList()); } // 新增应急预案应急队伍表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getTeamList())) { addEmergencyPlanTeam(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getTeamList()); } return new ResultVO<>(ResultCodes.OK); } private void addEmergencyPlanArea(Long uid, Long planId, Date nowDate, List emergencyPlanAreaReqDTOList) { List emergencyPlanAreaInfoList = BeanCopyUtils.copyBeanList(emergencyPlanAreaReqDTOList, EmergencyPlanAreaInfo.class); emergencyPlanAreaInfoList.forEach(EmergencyPlanAreaInfo -> { EmergencyPlanAreaInfo.setDelFlag(false); EmergencyPlanAreaInfo.setCreateUid(uid); EmergencyPlanAreaInfo.setGmtCreate(nowDate); EmergencyPlanAreaInfo.setPlanId(planId); }); for (EmergencyPlanAreaInfo emergencyPlanAreaInfo : emergencyPlanAreaInfoList) { emergencyPlanAreaInfoService.addEmergencyPlanArea(emergencyPlanAreaInfo); } } private void addEmergencyPlanDepartment(Long uid, Long planId, Date nowDate, List emergencyPlanDepartmentReqDTOList) { List emergencyPlanDepartmentInfoList = BeanCopyUtils.copyBeanList(emergencyPlanDepartmentReqDTOList, EmergencyPlanDepartmentInfo.class); emergencyPlanDepartmentInfoList.forEach(EmergencyPlanDepartmentInfo -> { EmergencyPlanDepartmentInfo.setDelFlag(false); EmergencyPlanDepartmentInfo.setCreateUid(uid); EmergencyPlanDepartmentInfo.setGmtCreate(nowDate); EmergencyPlanDepartmentInfo.setPlanId(planId); }); for (EmergencyPlanDepartmentInfo emergencyPlanDepartmentInfo : emergencyPlanDepartmentInfoList) { emergencyPlanDepartmentInfoService.addEmergencyPlanDepartment(emergencyPlanDepartmentInfo); } } private void addEmergencyPlanFile(Long uid, Long planId, Date nowDate, List emergencyPlanFileReqDTOList) { List emergencyPlanFileInfoList = BeanCopyUtils.copyBeanList(emergencyPlanFileReqDTOList, EmergencyPlanFileInfo.class); emergencyPlanFileInfoList.forEach(EmergencyPlanFileInfo -> { EmergencyPlanFileInfo.setDelFlag(false); EmergencyPlanFileInfo.setCreateUid(uid); EmergencyPlanFileInfo.setGmtCreate(nowDate); EmergencyPlanFileInfo.setPlanId(planId); }); for (EmergencyPlanFileInfo emergencyPlanFileInfo : emergencyPlanFileInfoList) { emergencyPlanFileInfoService.addEmergencyPlanFile(emergencyPlanFileInfo); } } private void addEmergencyPlanTeam(Long uid, Long planId, Date nowDate, List emergencyPlanTeamReqDTOList) { List emergencyPlanTeamInfoList = BeanCopyUtils.copyBeanList(emergencyPlanTeamReqDTOList, EmergencyPlanTeamInfo.class); emergencyPlanTeamInfoList.forEach(EmergencyPlanTeamInfo -> { EmergencyPlanTeamInfo.setDelFlag(false); EmergencyPlanTeamInfo.setCreateUid(uid); EmergencyPlanTeamInfo.setGmtCreate(nowDate); EmergencyPlanTeamInfo.setPlanId(planId); }); for (EmergencyPlanTeamInfo emergencyPlanTeamInfo : emergencyPlanTeamInfoList) { emergencyPlanTeamInfoService.addEmergencyPlanTeam(emergencyPlanTeamInfo); } } @Override public ResultVO getEmergencyPlanById(Long id) { EmergencyPlanDetailRespDTO emergencyPlanDetailRespDTO = new EmergencyPlanDetailRespDTO(); // 查询是否存在 EmergencyPlanInfoDetailDO emergencyPlanInfoDetailDO = emergencyPlanInfoService.selectEmergencyPlanById(id); if (emergencyPlanInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NOT_EXIST); } else { BeanUtils.copyProperties(emergencyPlanInfoDetailDO, emergencyPlanDetailRespDTO); // 查找对应的区域 List emergencyPlanAreaInfoDOList = emergencyPlanAreaInfoService.selectEmergencyPlanAreaByPlanId(id); if (!CollectionUtils.isEmpty(emergencyPlanAreaInfoDOList)) { List emergencyTeamFileRespDTOList = BeanCopyUtils.copyBeanList(emergencyPlanAreaInfoDOList, EmergencyPlanAreaRespDTO.class); emergencyPlanDetailRespDTO.setAreaList(emergencyTeamFileRespDTOList); } // 查找对应的适用部门 List emergencyPlanDepartmentInfoDOList = emergencyPlanDepartmentInfoService.selectEmergencyPlanDepartmentByPlanId(id); if (!CollectionUtils.isEmpty(emergencyPlanDepartmentInfoDOList)) { List emergencyTeamDepartmentRespDTOList = BeanCopyUtils.copyBeanList(emergencyPlanDepartmentInfoDOList, EmergencyPlanDepartmentRespDTO.class); Map deptPool = new HashMap<>(); for (EmergencyPlanDepartmentRespDTO emergencyPlanDepartmentRespDTO : emergencyTeamDepartmentRespDTOList) { if (!deptPool.containsKey(emergencyPlanDepartmentRespDTO.getDepartmentId())) { ResultVO rpcResult = accountDepartmentService.getDepInfoByDepId(emergencyPlanDepartmentRespDTO.getDepartmentId()); if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) { if (rpcResult.getData() != null) { DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO) rpcResult.getData(); deptPool.put(dep.getDepId(), dep.getDepName()); } } } String depName = deptPool.get(emergencyPlanDepartmentRespDTO.getDepartmentId()); emergencyPlanDepartmentRespDTO.setDepartmentName(depName); } emergencyPlanDetailRespDTO.setDeptList(emergencyTeamDepartmentRespDTOList); } // 查找对应的应急队伍 List emergencyPlanTeamInfoDOList = emergencyPlanTeamInfoService.selectEmergencyPlanTeamByPlanId(id); if (!CollectionUtils.isEmpty(emergencyPlanTeamInfoDOList)) { List emergencyTeamTeamRespDTOList = BeanCopyUtils.copyBeanList(emergencyPlanTeamInfoDOList, EmergencyPlanTeamRespDTO.class); emergencyPlanDetailRespDTO.setTeamList(emergencyTeamTeamRespDTOList); } // 查找对应的附件 List emergencyPlanFileInfoDOList = emergencyPlanFileInfoService.selectEmergencyPlanFileByPlanId(id); if (!CollectionUtils.isEmpty(emergencyPlanFileInfoDOList)) { List emergencyTeamFileRespDTOList = BeanCopyUtils.copyBeanList(emergencyPlanFileInfoDOList, EmergencyPlanFileRespDTO.class); emergencyPlanDetailRespDTO.setFileList(emergencyTeamFileRespDTOList); } return new ResultVO<>(ResultCodes.OK, emergencyPlanDetailRespDTO); } } @Override public ResultVO updateEmergencyPlan(Long uid, EmergencyPlanReqDTO emergencyPlanReqDTO) { Date nowDate = new Date(); // 查询是否存在 EmergencyPlanInfoDetailDO emergencyPlanInfoDetailDO = emergencyPlanInfoService.selectEmergencyPlanById(emergencyPlanReqDTO.getId()); if (emergencyPlanInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NOT_EXIST); } else { EmergencyPlanInfo emergencyPlanInfo = new EmergencyPlanInfo(); BeanUtils.copyProperties(emergencyPlanReqDTO, emergencyPlanInfo); emergencyPlanInfo.setUpdateUid(uid); emergencyPlanInfo.setGmtModitify(nowDate); emergencyPlanInfoService.updateEmergencyPlan(emergencyPlanInfo); // 更新应急预案区域表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getAreaList())) { updateEmergencyPlanArea(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getAreaList()); } // 更新应急预案适用部门表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getDeptList())) { updateEmergencyPlanDepartment(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getDeptList()); } // 更新应急预案附件表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getFileList())) { updateEmergencyPlanFile(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getFileList()); } // 更新应急预案应急队伍表 if (!CollectionUtils.isEmpty(emergencyPlanReqDTO.getTeamList())) { updateEmergencyPlanTeam(uid, emergencyPlanInfo.getId(), nowDate, emergencyPlanReqDTO.getTeamList()); } return new ResultVO<>(ResultCodes.OK); } } private void updateEmergencyPlanArea(Long uid, Long planId, Date nowDate, List areaReqDTOList) { List emergencyPlanAreaInfoDOList = emergencyPlanAreaInfoService.selectEmergencyPlanAreaByPlanId(planId); List oldIdsList = emergencyPlanAreaInfoDOList.stream().map(EmergencyPlanAreaInfoDO::getId).collect(Collectors.toList()); List newIdsList = new ArrayList<>(); //新增的区域集合 List addList = new ArrayList<>(); //删除的区域集合(id) List deleteList = new ArrayList<>(); for (EmergencyPlanAreaReqDTO emergencyPlanAreaReqDTO : areaReqDTOList) { //如果不存在id则表示页面新增的附件 if (emergencyPlanAreaReqDTO.getId() == null) { EmergencyPlanAreaInfo emergencyPlanAreaInfo = new EmergencyPlanAreaInfo(); BeanUtils.copyProperties(emergencyPlanAreaReqDTO, emergencyPlanAreaInfo); emergencyPlanAreaInfo.setDelFlag(false); emergencyPlanAreaInfo.setGmtCreate(nowDate); emergencyPlanAreaInfo.setCreateUid(uid); emergencyPlanAreaInfo.setPlanId(planId); addList.add(emergencyPlanAreaInfo); } //如果存在id则判断页面是否删除 else { newIdsList.add(emergencyPlanAreaReqDTO.getId()); } } for (Long oldId : oldIdsList) { if (!newIdsList.contains(oldId)) { deleteList.add(oldId); } } if (!CollectionUtils.isEmpty(addList)) { for (EmergencyPlanAreaInfo emergencyPlanAreaInfo : addList) { emergencyPlanAreaInfoService.addEmergencyPlanArea(emergencyPlanAreaInfo); } } if (!CollectionUtils.isEmpty(deleteList)) { emergencyPlanAreaInfoService.deleteEmergencyPlanAreaByIds(deleteList); } } private void updateEmergencyPlanDepartment(Long uid, Long planId, Date nowDate, List departmentReqDTOList) { List emergencyPlanDepartmentInfoDOList = emergencyPlanDepartmentInfoService.selectEmergencyPlanDepartmentByPlanId(planId); List oldIdsList = emergencyPlanDepartmentInfoDOList.stream().map(EmergencyPlanDepartmentInfoDO::getId).collect(Collectors.toList()); List newIdsList = new ArrayList<>(); //新增的区域集合 List addList = new ArrayList<>(); //删除的区域集合(id) List deleteList = new ArrayList<>(); for (EmergencyPlanDepartmentReqDTO emergencyPlanDepartmentReqDTO : departmentReqDTOList) { //如果不存在id则表示页面新增的附件 if (emergencyPlanDepartmentReqDTO.getId() == null) { EmergencyPlanDepartmentInfo emergencyPlanDepartmentInfo = new EmergencyPlanDepartmentInfo(); BeanUtils.copyProperties(emergencyPlanDepartmentReqDTO, emergencyPlanDepartmentInfo); emergencyPlanDepartmentInfo.setDelFlag(false); emergencyPlanDepartmentInfo.setGmtCreate(nowDate); emergencyPlanDepartmentInfo.setCreateUid(uid); emergencyPlanDepartmentInfo.setPlanId(planId); addList.add(emergencyPlanDepartmentInfo); } //如果存在id则判断页面是否删除 else { newIdsList.add(emergencyPlanDepartmentReqDTO.getId()); } } for (Long oldId : oldIdsList) { if (!newIdsList.contains(oldId)) { deleteList.add(oldId); } } if (!CollectionUtils.isEmpty(addList)) { for (EmergencyPlanDepartmentInfo emergencyPlanDepartmentInfo : addList) { emergencyPlanDepartmentInfoService.addEmergencyPlanDepartment(emergencyPlanDepartmentInfo); } } if (!CollectionUtils.isEmpty(deleteList)) { emergencyPlanDepartmentInfoService.deleteEmergencyPlanDepartmentByIds(deleteList); } } private void updateEmergencyPlanFile(Long uid, Long planId, Date nowDate, List fileReqDTOList) { List emergencyPlanFileInfoDOList = emergencyPlanFileInfoService.selectEmergencyPlanFileByPlanId(planId); List oldIdsList = emergencyPlanFileInfoDOList.stream().map(EmergencyPlanFileInfoDO::getId).collect(Collectors.toList()); List newIdsList = new ArrayList<>(); //新增的区域集合 List addList = new ArrayList<>(); //删除的区域集合(id) List deleteList = new ArrayList<>(); for (EmergencyPlanFileReqDTO emergencyPlanFileReqDTO : fileReqDTOList) { //如果不存在id则表示页面新增的附件 if (emergencyPlanFileReqDTO.getId() == null) { EmergencyPlanFileInfo emergencyPlanFileInfo = new EmergencyPlanFileInfo(); BeanUtils.copyProperties(emergencyPlanFileReqDTO, emergencyPlanFileInfo); emergencyPlanFileInfo.setDelFlag(false); emergencyPlanFileInfo.setGmtCreate(nowDate); emergencyPlanFileInfo.setCreateUid(uid); emergencyPlanFileInfo.setPlanId(planId); addList.add(emergencyPlanFileInfo); } //如果存在id则判断页面是否删除 else { newIdsList.add(emergencyPlanFileReqDTO.getId()); } } for (Long oldId : oldIdsList) { if (!newIdsList.contains(oldId)) { deleteList.add(oldId); } } if (!CollectionUtils.isEmpty(addList)) { for (EmergencyPlanFileInfo emergencyPlanFileInfo : addList) { emergencyPlanFileInfoService.addEmergencyPlanFile(emergencyPlanFileInfo); } } if (!CollectionUtils.isEmpty(deleteList)) { emergencyPlanFileInfoService.deleteEmergencyPlanFileByIds(deleteList); } } private void updateEmergencyPlanTeam(Long uid, Long planId, Date nowDate, List teamReqDTOList) { List emergencyPlanTeamInfoDOList = emergencyPlanTeamInfoService.selectEmergencyPlanTeamByPlanId(planId); List oldIdsList = emergencyPlanTeamInfoDOList.stream().map(EmergencyPlanTeamInfoDO::getId).collect(Collectors.toList()); List newIdsList = new ArrayList<>(); //新增的区域集合 List addList = new ArrayList<>(); //删除的区域集合(id) List deleteList = new ArrayList<>(); for (EmergencyPlanTeamReqDTO emergencyPlanTeamReqDTO : teamReqDTOList) { //如果不存在id则表示页面新增的附件 if (emergencyPlanTeamReqDTO.getId() == null) { EmergencyPlanTeamInfo emergencyPlanTeamInfo = new EmergencyPlanTeamInfo(); BeanUtils.copyProperties(emergencyPlanTeamReqDTO, emergencyPlanTeamInfo); emergencyPlanTeamInfo.setDelFlag(false); emergencyPlanTeamInfo.setGmtCreate(nowDate); emergencyPlanTeamInfo.setCreateUid(uid); emergencyPlanTeamInfo.setPlanId(planId); addList.add(emergencyPlanTeamInfo); } //如果存在id则判断页面是否删除 else { newIdsList.add(emergencyPlanTeamReqDTO.getId()); } } for (Long oldId : oldIdsList) { if (!newIdsList.contains(oldId)) { deleteList.add(oldId); } } if (!CollectionUtils.isEmpty(addList)) { for (EmergencyPlanTeamInfo emergencyPlanTeamInfo : addList) { emergencyPlanTeamInfoService.addEmergencyPlanTeam(emergencyPlanTeamInfo); } } if (!CollectionUtils.isEmpty(deleteList)) { emergencyPlanTeamInfoService.deleteEmergencyPlanTeamByIds(deleteList); } } @Override public ResultVO batchDeleteEmergencyPlan(Long[] ids) { if (ids == null || ids.length==0){ throw new EmergencyException(EmergencyResultCodes.PLAN_NOT_EXIST); }else{ for (Long id : ids){ deleteEmergencyPlan(id); } return new ResultVO(ResultCodes.OK); } } @Override public ResultVO updateAbolish(Long id, Boolean abolishStatus) { emergencyPlanInfoService.updateAbolish(id,abolishStatus); return new ResultVO(ResultCodes.OK); } private void deleteEmergencyPlan(Long id) { //查询是否存在 EmergencyPlanInfoDetailDO emergencyPlanInfoDetailDO = emergencyPlanInfoService.selectEmergencyPlanById(id); if (emergencyPlanInfoDetailDO == null) { throw new EmergencyException(EmergencyResultCodes.PLAN_NOT_EXIST); } else { Long PlanId = emergencyPlanInfoDetailDO.getId(); emergencyPlanInfoService.deleteEmergencyPlan(PlanId); //删除区域 emergencyPlanAreaInfoService.deleteEmergencyPlanAreaByPlanId(PlanId); //删除适用部门 emergencyPlanDepartmentInfoService.deleteEmergencyPlanDepartmentByPlanId(PlanId); //删除附件 emergencyPlanFileInfoService.deleteEmergencyPlanFileByPlanId(PlanId); //删除应急队伍 emergencyPlanTeamInfoService.deleteEmergencyPlanTeamByPlanId(PlanId); } } }