| | |
| | | package com.gkhy.safePlatform.incidentManage.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.gkhy.safePlatform.account.rpc.apimodel.AccountAuthService; |
| | | import com.gkhy.safePlatform.account.rpc.apimodel.AccountDepartmentService; |
| | | import com.gkhy.safePlatform.account.rpc.apimodel.model.resp.DepInfoRPCRespDTO; |
| | | import com.gkhy.safePlatform.commons.co.ContextCacheUser; |
| | | 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.incidentManage.entity.*; |
| | | import com.gkhy.safePlatform.incidentManage.enums.AccidentExpressEnum; |
| | | import com.gkhy.safePlatform.incidentManage.enums.AccidentResultCodes; |
| | | import com.gkhy.safePlatform.incidentManage.exception.AccidentException; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.req.AccidentExpressCasualtyReqDTO; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.req.AccidentExpressFileReqDTO; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.req.AccidentExpressReqDTO; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressCasualtyRespDTO; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressDetailRespDTO; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressFileRespDTO; |
| | | import com.gkhy.safePlatform.incidentManage.model.dto.resp.AccidentExpressPageRespDTO; |
| | | import com.gkhy.safePlatform.incidentManage.query.AccidentExpressQuery; |
| | | import com.gkhy.safePlatform.incidentManage.query.db.AccidentExpressDBQuery; |
| | | import com.gkhy.safePlatform.incidentManage.service.AccidentExpressService; |
| | | import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressCasualtyInfoService; |
| | | import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressFileInfoService; |
| | | import com.gkhy.safePlatform.incidentManage.service.baseService.AccidentExpressInfoService; |
| | | 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.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("accidentExpressService") |
| | |
| | | |
| | | @Autowired |
| | | private AccidentExpressFileInfoService accidentExpressFileInfoService; |
| | | |
| | | @Autowired |
| | | private AccidentExpressCasualtyInfoService accidentExpressCasualtyInfoService; |
| | | |
| | | @DubboReference(check = false) |
| | | private AccountDepartmentService accountDepartmentService; |
| | | |
| | | |
| | | @Override |
| | |
| | | BeanUtils.copyProperties(query.getSearchParams(), accidentExpressDBQuery); |
| | | } |
| | | |
| | | |
| | | List<AccidentExpressInfoPageDO> accidentExpressInfoPageDOList = accidentExpressInfoService.selectAccidentExpressList(page, accidentExpressDBQuery); |
| | | List<AccidentExpressPageRespDTO> respList = BeanCopyUtils.copyBeanList(accidentExpressInfoPageDOList, AccidentExpressPageRespDTO.class); |
| | | |
| | | Map<Long, String> depPool = new HashMap<>(); |
| | | |
| | | respList.forEach(AccidentExpressPageRespDTO -> { |
| | | // 设置部门名称 |
| | | if (!depPool.containsKey(AccidentExpressPageRespDTO.getAccidentDepartmentId())) { |
| | | ResultVO<DepInfoRPCRespDTO> rpcResult = accountDepartmentService.getDepInfoByDepId(AccidentExpressPageRespDTO.getAccidentDepartmentId()); |
| | | if (rpcResult != null && rpcResult.getCode().equals(ResultCodes.OK.getCode())) { |
| | | if (rpcResult.getData() != null) { |
| | | DepInfoRPCRespDTO dep = (DepInfoRPCRespDTO) rpcResult.getData(); |
| | | |
| | | depPool.put(dep.getDepId(), dep.getDepName()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String depName = depPool.get(AccidentExpressPageRespDTO.getAccidentDepartmentId()); |
| | | AccidentExpressPageRespDTO.setDeptName(depName); |
| | | }); |
| | | |
| | | return new SearchResultVO<>( |
| | | true, |
| | | pageIndex, |
| | | pageSize, |
| | | pageSize, page.getPages(), |
| | | page.getTotal(), |
| | | respList, |
| | | ResultCodes.OK |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResultVO addAccidentExpress(Long uid, AccidentExpressReqDTO accidentExpressReqDTO) { |
| | | public ResultVO<AccidentExpressDetailRespDTO> addAccidentExpress(ContextCacheUser contextCacheUser, AccidentExpressReqDTO accidentExpressReqDTO) { |
| | | Long uid = contextCacheUser.getUid(); |
| | | String uName = contextCacheUser.getRealName(); |
| | | //必填项验证 |
| | | checkRequired(accidentExpressReqDTO); |
| | | |
| | | //枚举验证 |
| | | checkEnum(accidentExpressReqDTO); |
| | | |
| | | Date nowDate = new Date(); |
| | | //1.新增应急队伍 |
| | | //1.新增事故快报 |
| | | AccidentExpressInfo accidentExpressInfo = new AccidentExpressInfo(); |
| | | BeanUtils.copyProperties(accidentExpressReqDTO, accidentExpressInfo); |
| | | accidentExpressInfo.setDelFlag(false); |
| | | accidentExpressInfo.setCreateUid(uid); |
| | | accidentExpressInfo.setCreateName(uName); |
| | | accidentExpressInfo.setGmtCreate(nowDate); |
| | | accidentExpressInfoService.addAccidentExpress(accidentExpressInfo); |
| | | //2.新增应急队伍附件 |
| | | if (!CollectionUtils.isEmpty(accidentExpressReqDTO.getFileList())){ |
| | | addAccidentExpressFile(accidentExpressInfo.getId(),uid,nowDate,accidentExpressReqDTO.getFileList()); |
| | | //2.新增事故快报附件 |
| | | if (!CollectionUtils.isEmpty(accidentExpressReqDTO.getFileList())) { |
| | | addAccidentExpressFile(accidentExpressInfo.getId(), uid, nowDate, accidentExpressReqDTO.getFileList()); |
| | | } |
| | | return new ResultVO(ResultCodes.OK); |
| | | |
| | | AccidentExpressDetailRespDTO accidentExpressDetailRespDTO = new AccidentExpressDetailRespDTO(); |
| | | BeanUtils.copyProperties(accidentExpressInfo, accidentExpressDetailRespDTO); |
| | | return new ResultVO<>(ResultCodes.OK, accidentExpressDetailRespDTO); |
| | | } |
| | | |
| | | private void addAccidentExpressFile(Long accidentExpressId ,Long uid , Date nowDate , List<AccidentExpressFileReqDTO> AccidentExpressFileReqDTOList){ |
| | | private void addAccidentExpressFile(Long accidentExpressId, Long uid, Date nowDate, List<AccidentExpressFileReqDTO> AccidentExpressFileReqDTOList) { |
| | | List<AccidentExpressFileInfo> fileInfoList = BeanCopyUtils.copyBeanList(AccidentExpressFileReqDTOList, AccidentExpressFileInfo.class); |
| | | fileInfoList.forEach(AccidentExpressFileInfo -> { |
| | | AccidentExpressFileInfo.setAccidentExpressId(accidentExpressId); |
| | |
| | | AccidentExpressFileInfo.setCreateUid(uid); |
| | | AccidentExpressFileInfo.setGmtCreate(nowDate); |
| | | }); |
| | | for (AccidentExpressFileInfo AccidentExpressFileInfo :fileInfoList){ |
| | | for (AccidentExpressFileInfo AccidentExpressFileInfo : fileInfoList) { |
| | | accidentExpressFileInfoService.addAccidentExpressFile(AccidentExpressFileInfo); |
| | | } |
| | | } |
| | |
| | | AccidentExpressDetailRespDTO AccidentExpressDetailRespDTO = new AccidentExpressDetailRespDTO(); |
| | | //查询是否存在 |
| | | AccidentExpressInfoDetailDO AccidentExpressInfoDetailDO = accidentExpressInfoService.selectAccidentExpressById(id); |
| | | if (AccidentExpressInfoDetailDO==null){ |
| | | if (AccidentExpressInfoDetailDO == null) { |
| | | throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NOT_EXIST); |
| | | }else{ |
| | | BeanUtils.copyProperties(AccidentExpressInfoDetailDO,AccidentExpressDetailRespDTO); |
| | | } else { |
| | | BeanUtils.copyProperties(AccidentExpressInfoDetailDO, AccidentExpressDetailRespDTO); |
| | | //查找对应的附件 |
| | | List<AccidentExpressFileInfoDO> AccidentExpressFileInfoDOList = accidentExpressFileInfoService.selectByAccidentExpressId(id); |
| | | if (!CollectionUtils.isEmpty(AccidentExpressFileInfoDOList)){ |
| | | List<AccidentExpressFileRespDTO> accidentExpressFileRespDTOList = BeanCopyUtils.copyBeanList(AccidentExpressFileInfoDOList , AccidentExpressFileRespDTO.class); |
| | | if (!CollectionUtils.isEmpty(AccidentExpressFileInfoDOList)) { |
| | | List<AccidentExpressFileRespDTO> accidentExpressFileRespDTOList = BeanCopyUtils.copyBeanList(AccidentExpressFileInfoDOList, AccidentExpressFileRespDTO.class); |
| | | AccidentExpressDetailRespDTO.setFileList(accidentExpressFileRespDTOList); |
| | | } |
| | | return new ResultVO<>(ResultCodes.OK ,AccidentExpressDetailRespDTO); |
| | | return new ResultVO<>(ResultCodes.OK, AccidentExpressDetailRespDTO); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResultVO updateAccidentExpress(Long uid, AccidentExpressReqDTO accidentExpressReqDTO) { |
| | | |
| | | //必填项验证 |
| | | checkRequired(accidentExpressReqDTO); |
| | | //枚举验证 |
| | | checkEnum(accidentExpressReqDTO); |
| | | |
| | | Date nowDate = new Date(); |
| | | //查询是否存在 |
| | | AccidentExpressInfoDetailDO AccidentExpressInfoDetailDO = accidentExpressInfoService.selectAccidentExpressById(accidentExpressReqDTO.getId()); |
| | | if (AccidentExpressInfoDetailDO==null){ |
| | | if (AccidentExpressInfoDetailDO == null) { |
| | | throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NOT_EXIST); |
| | | }else{ |
| | | } else { |
| | | AccidentExpressInfo accidentExpressInfo = new AccidentExpressInfo(); |
| | | BeanUtils.copyProperties(accidentExpressReqDTO,accidentExpressInfo); |
| | | BeanUtils.copyProperties(accidentExpressReqDTO, accidentExpressInfo); |
| | | accidentExpressInfo.setUpdateUid(uid); |
| | | accidentExpressInfo.setGmtModitify(nowDate); |
| | | accidentExpressInfoService.updateAccidentExpress(accidentExpressInfo); |
| | | //修改应急队伍附件 |
| | | updateAccidentExpressFile(uid,accidentExpressReqDTO.getId(),nowDate,accidentExpressReqDTO.getFileList()); |
| | | //修改事故快报附件 |
| | | updateAccidentExpressFile(uid, accidentExpressReqDTO.getId(), nowDate, accidentExpressReqDTO.getFileList()); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | } |
| | | |
| | | private void updateAccidentExpressFile(Long uid ,Long accidentExpressId ,Date nowDate,List<AccidentExpressFileReqDTO> AccidentExpressFileReqDTOList){ |
| | | private void updateAccidentExpressFile(Long uid, Long accidentExpressId, Date nowDate, List<AccidentExpressFileReqDTO> accidentExpressFileReqDTOList) { |
| | | |
| | | List<AccidentExpressFileInfoDO> accidentExpressFileInfoDOList = accidentExpressFileInfoService.selectByAccidentExpressId(accidentExpressId); |
| | | List<Long> oldIdsList = accidentExpressFileInfoDOList.stream().map(AccidentExpressFileInfoDO::getId).collect(Collectors.toList()); |
| | |
| | | List<AccidentExpressFileInfo> addList = new ArrayList<>(); |
| | | //删除的附件集合(id) |
| | | List<Long> deleteList = new ArrayList<>(); |
| | | for (AccidentExpressFileReqDTO AccidentExpressFileReqDTO : AccidentExpressFileReqDTOList){ |
| | | //如果不存在id则表示页面新增的附件 |
| | | if (AccidentExpressFileReqDTO.getId() == null){ |
| | | AccidentExpressFileInfo AccidentExpressFileInfo = new AccidentExpressFileInfo(); |
| | | BeanUtils.copyProperties(AccidentExpressFileReqDTO,AccidentExpressFileInfo); |
| | | AccidentExpressFileInfo.setDelFlag(false); |
| | | AccidentExpressFileInfo.setGmtCreate(nowDate); |
| | | AccidentExpressFileInfo.setCreateUid(uid); |
| | | AccidentExpressFileInfo.setAccidentExpressId(accidentExpressId); |
| | | addList.add(AccidentExpressFileInfo); |
| | | } |
| | | //如果存在id则判断页面是否删除 |
| | | else{ |
| | | newIdsList.add(AccidentExpressFileReqDTO.getId()); |
| | | if(accidentExpressFileReqDTOList != null && !accidentExpressFileInfoDOList.isEmpty()){ |
| | | for (AccidentExpressFileReqDTO accidentExpressFileReqDTO : accidentExpressFileReqDTOList) { |
| | | //如果不存在id则表示页面新增的附件 |
| | | if (accidentExpressFileReqDTO.getId() == null) { |
| | | AccidentExpressFileInfo accidentExpressFileInfo = new AccidentExpressFileInfo(); |
| | | BeanUtils.copyProperties(accidentExpressFileReqDTO, accidentExpressFileInfo); |
| | | accidentExpressFileInfo.setDelFlag(false); |
| | | accidentExpressFileInfo.setGmtCreate(nowDate); |
| | | accidentExpressFileInfo.setCreateUid(uid); |
| | | accidentExpressFileInfo.setAccidentExpressId(accidentExpressId); |
| | | addList.add(accidentExpressFileInfo); |
| | | } |
| | | //如果存在id则判断页面是否删除 |
| | | else { |
| | | newIdsList.add(accidentExpressFileReqDTO.getId()); |
| | | } |
| | | } |
| | | } |
| | | for (Long oldId : oldIdsList){ |
| | | if (!newIdsList.contains(oldId)){ |
| | | for (Long oldId : oldIdsList) { |
| | | if (!newIdsList.contains(oldId)) { |
| | | deleteList.add(oldId); |
| | | } |
| | | } |
| | | if (!CollectionUtils.isEmpty(addList)){ |
| | | for (AccidentExpressFileInfo AccidentExpressFileInfo : addList){ |
| | | if (!CollectionUtils.isEmpty(addList)) { |
| | | for (AccidentExpressFileInfo AccidentExpressFileInfo : addList) { |
| | | accidentExpressFileInfoService.addAccidentExpressFile(AccidentExpressFileInfo); |
| | | } |
| | | } |
| | | if (!CollectionUtils.isEmpty(deleteList)){ |
| | | if (!CollectionUtils.isEmpty(deleteList)) { |
| | | accidentExpressFileInfoService.deleteAccidentExpressFileByIds(deleteList); |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ResultVO batchDeleteAccidentExpress(String ids) { |
| | | if (StringUtils.isBlank(ids)){ |
| | | public ResultVO batchDeleteAccidentExpress(Long[] ids) { |
| | | if (ids == null || ids.length == 0) { |
| | | throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NULL); |
| | | }else{ |
| | | String[] idArr = ids.split(","); |
| | | for (String id : idArr) { |
| | | deleteAccidentExpress(Long.valueOf(id)); |
| | | } else { |
| | | for (Long id : ids) { |
| | | deleteAccidentExpress(id); |
| | | } |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | |
| | | private void deleteAccidentExpress(Long id) { |
| | | //查询是否存在 |
| | | AccidentExpressInfoDetailDO AccidentExpressInfoDetailDO = accidentExpressInfoService.selectAccidentExpressById(id); |
| | | if (AccidentExpressInfoDetailDO==null){ |
| | | if (AccidentExpressInfoDetailDO == null) { |
| | | throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NOT_EXIST); |
| | | }else{ |
| | | } else { |
| | | accidentExpressInfoService.deleteAccidentExpressById(id); |
| | | //删除附件 |
| | | accidentExpressFileInfoService.deleteAccidentExpressFileByAccidentExpressId(id); |
| | | //删除伤亡 |
| | | accidentExpressCasualtyInfoService.deleteAccidentExpressCasualtyByAccidentExpressId(id); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResultVO selectAccidentExpressCasualtyList(Long accidentExpressId) { |
| | | List<AccidentExpressCasualtyInfoDO> accidentExpressCasualtyInfoDOList = accidentExpressCasualtyInfoService.selectByAccidentExpressId(accidentExpressId); |
| | | List<AccidentExpressCasualtyRespDTO> respList = BeanCopyUtils.copyBeanList(accidentExpressCasualtyInfoDOList, AccidentExpressCasualtyRespDTO.class); |
| | | return new ResultVO<>(ResultCodes.OK, respList); |
| | | } |
| | | |
| | | @Override |
| | | public ResultVO addAccidentExpressCasualty(Long uid, AccidentExpressCasualtyReqDTO accidentExpressCasualtyReqDTO) { |
| | | if (accidentExpressCasualtyReqDTO.getAccidentExpressId() == null) { |
| | | throw new AccidentException(AccidentResultCodes.ACCIDENT_EXPRESS_NULL); |
| | | } else { |
| | | AccidentExpressCasualtyInfo accidentExpressCasualtyInfo = new AccidentExpressCasualtyInfo(); |
| | | BeanUtils.copyProperties(accidentExpressCasualtyReqDTO, accidentExpressCasualtyInfo); |
| | | accidentExpressCasualtyInfo.setDelFlag(false); |
| | | accidentExpressCasualtyInfo.setGmtCreate(new Date()); |
| | | accidentExpressCasualtyInfo.setCreateUid(uid); |
| | | accidentExpressCasualtyInfoService.addAccidentExpressCasualty(accidentExpressCasualtyInfo); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResultVO delAccidentExpressCasualty(Long id) { |
| | | accidentExpressCasualtyInfoService.deleteAccidentExpressCasualtyById(id); |
| | | return new ResultVO(ResultCodes.OK); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 验证必填项 |
| | | * |
| | | * @return |
| | | */ |
| | | private void checkRequired(AccidentExpressReqDTO AccidentExpressReqDTO) { |
| | | private void checkRequired(AccidentExpressReqDTO accidentExpressReqDTO) { |
| | | //名称 |
| | | if (StringUtils.isBlank(AccidentExpressReqDTO.getAccidentName())) { |
| | | if (StringUtils.isBlank(accidentExpressReqDTO.getAccidentName())) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_NAME_NULL); |
| | | } |
| | | //部门 |
| | | if (AccidentExpressReqDTO.getAccidentDepartmentId()==null) { |
| | | if (accidentExpressReqDTO.getAccidentDepartmentId() == null) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_DEPARTMENT_NULL); |
| | | } |
| | | //发生时间 |
| | | if (AccidentExpressReqDTO.getOccurrenceTime() == null ) { |
| | | if (accidentExpressReqDTO.getOccurrenceTime() == null) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_TIME_NULL); |
| | | } |
| | | //发生地点 |
| | | if (StringUtils.isBlank(AccidentExpressReqDTO.getOccurrencePlace())) { |
| | | if (StringUtils.isBlank(accidentExpressReqDTO.getOccurrencePlace())) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_PLACE_NULL); |
| | | } |
| | | //事故原因 |
| | | if (StringUtils.isBlank(AccidentExpressReqDTO.getAccidentCause())) { |
| | | if (accidentExpressReqDTO.getAccidentCause() == null) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_CAUSE_NULL); |
| | | } |
| | | //是否有伤亡 |
| | | if (AccidentExpressReqDTO.getCasualties()==null) { |
| | | if (accidentExpressReqDTO.getCasualties() == null) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_CASUALTIES_NULL); |
| | | } |
| | | //简要经过 |
| | | if (StringUtils.isBlank(AccidentExpressReqDTO.getAccidentBriefProcess())) { |
| | | if (StringUtils.isBlank(accidentExpressReqDTO.getAccidentBriefProcess())) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_BRIEF_PROCESS_NULL); |
| | | } |
| | | //初步分析 |
| | | if (StringUtils.isBlank(AccidentExpressReqDTO.getAccidentCausesPreliminaryAnalysis())) { |
| | | if (StringUtils.isBlank(accidentExpressReqDTO.getAccidentCausesPreliminaryAnalysis())) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_CASE_PRELIMINARY_ANALYSIS_NULL); |
| | | } |
| | | //应急防范措施 |
| | | if (StringUtils.isBlank(AccidentExpressReqDTO.getEmergencyPrecautions())) { |
| | | if (StringUtils.isBlank(accidentExpressReqDTO.getEmergencyPrecautions())) { |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_EMERGENCY_PRECAUTIONS_NULL); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * 枚举验证 |
| | | * |
| | | */ |
| | | private void checkEnum(AccidentExpressReqDTO accidentExpressReqDTO){ |
| | | if (AccidentExpressEnum.getByCode(accidentExpressReqDTO.getAccidentCause())==null){ |
| | | throw new AccidentException(AccidentResultCodes.EXPRESS_ENUMS_CAUSE_NOT_EXIST); |
| | | } |
| | | } |
| | | |
| | | } |