package com.gkhy.safePlatform.incidentManage.service.impl; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.utils.StringUtils; 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.AccidentResultCodes; import com.gkhy.safePlatform.incidentManage.exception.AccidentException; import com.gkhy.safePlatform.incidentManage.model.dto.req.WorkInjuryDeclarationFileReqDTO; import com.gkhy.safePlatform.incidentManage.model.dto.req.WorkInjuryDeclarationReqDTO; import com.gkhy.safePlatform.incidentManage.model.dto.resp.WorkInjuryDeclarationDetailRespDTO; import com.gkhy.safePlatform.incidentManage.model.dto.resp.WorkInjuryDeclarationFileRespDTO; import com.gkhy.safePlatform.incidentManage.model.dto.resp.WorkInjuryDeclarationPageRespDTO; import com.gkhy.safePlatform.incidentManage.query.WorkInjuryDeclarationQuery; import com.gkhy.safePlatform.incidentManage.query.db.WorkInjuryDeclarationDBQuery; import com.gkhy.safePlatform.incidentManage.service.WorkInjuryDeclarationService; import com.gkhy.safePlatform.incidentManage.service.baseService.WorkInjuryDeclarationFileInfoService; import com.gkhy.safePlatform.incidentManage.service.baseService.WorkInjuryDeclarationInfoService; 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.stream.Collectors; @Service("workInjuryDeclarationService") public class WorkInjuryDeclarationServiceImpl implements WorkInjuryDeclarationService { @Autowired private WorkInjuryDeclarationInfoService workInjuryDeclarationInfoService; @Autowired private WorkInjuryDeclarationFileInfoService workInjuryDeclarationFileInfoService; @Override public SearchResultVO> selectWorkInjuryDeclarationList(PageQuery query) { Long pageIndex = query.getPageIndex(); Long pageSize = query.getPageSize(); Page page = new Page<>(pageIndex, pageSize); WorkInjuryDeclarationDBQuery WorkInjuryDeclarationDBQuery = new WorkInjuryDeclarationDBQuery(); if (query.getSearchParams() != null) { BeanUtils.copyProperties(query.getSearchParams(), WorkInjuryDeclarationDBQuery); } List WorkInjuryDeclarationInfoPageDOList = workInjuryDeclarationInfoService.selectWorkInjuryDeclarationList(page, WorkInjuryDeclarationDBQuery); List respList = BeanCopyUtils.copyBeanList(WorkInjuryDeclarationInfoPageDOList, WorkInjuryDeclarationPageRespDTO.class); return new SearchResultVO<>( true, pageIndex, pageSize, page.getTotal(), respList, ResultCodes.OK ); } @Override public ResultVO addWorkInjuryDeclaration(Long uid, WorkInjuryDeclarationReqDTO WorkInjuryDeclarationReqDTO) { //必填项验证 checkRequired(WorkInjuryDeclarationReqDTO); Date nowDate = new Date(); //1.新增工伤申报 WorkInjuryDeclarationInfo WorkInjuryDeclarationInfo = new WorkInjuryDeclarationInfo(); BeanUtils.copyProperties(WorkInjuryDeclarationReqDTO, WorkInjuryDeclarationInfo); WorkInjuryDeclarationInfo.setDelFlag(false); WorkInjuryDeclarationInfo.setCreateUid(uid); WorkInjuryDeclarationInfo.setGmtCreate(nowDate); workInjuryDeclarationInfoService.addWorkInjuryDeclaration(WorkInjuryDeclarationInfo); //2.新增工伤申报附件 if (!CollectionUtils.isEmpty(WorkInjuryDeclarationReqDTO.getFileList())){ addWorkInjuryDeclarationFile(WorkInjuryDeclarationInfo.getId(),uid,nowDate,WorkInjuryDeclarationReqDTO.getFileList()); } return new ResultVO(ResultCodes.OK); } private void addWorkInjuryDeclarationFile(Long WorkInjuryDeclarationId ,Long uid , Date nowDate , List WorkInjuryDeclarationFileReqDTOList){ List fileInfoList = BeanCopyUtils.copyBeanList(WorkInjuryDeclarationFileReqDTOList, WorkInjuryDeclarationFileInfo.class); fileInfoList.forEach(WorkInjuryDeclarationFileInfo -> { WorkInjuryDeclarationFileInfo.setWorkInjuryDeclarationId(WorkInjuryDeclarationId); WorkInjuryDeclarationFileInfo.setDelFlag(false); WorkInjuryDeclarationFileInfo.setCreateUid(uid); WorkInjuryDeclarationFileInfo.setGmtCreate(nowDate); }); for (WorkInjuryDeclarationFileInfo WorkInjuryDeclarationFileInfo :fileInfoList){ workInjuryDeclarationFileInfoService.addWorkInjuryDeclarationFile(WorkInjuryDeclarationFileInfo); } } @Override public ResultVO getWorkInjuryDeclarationById(Long id) { WorkInjuryDeclarationDetailRespDTO WorkInjuryDeclarationDetailRespDTO = new WorkInjuryDeclarationDetailRespDTO(); //查询是否存在 WorkInjuryDeclarationInfoDetailDO WorkInjuryDeclarationInfoDetailDO = workInjuryDeclarationInfoService.selectWorkInjuryDeclarationById(id); if (WorkInjuryDeclarationInfoDetailDO==null){ throw new AccidentException(AccidentResultCodes.WORK_INJURY_DECLARATION_NOT_EXIST); }else{ BeanUtils.copyProperties(WorkInjuryDeclarationInfoDetailDO,WorkInjuryDeclarationDetailRespDTO); //查找对应的附件 List WorkInjuryDeclarationFileInfoDOList = workInjuryDeclarationFileInfoService.selectByWorkInjuryDeclarationId(id); if (!CollectionUtils.isEmpty(WorkInjuryDeclarationFileInfoDOList)){ List WorkInjuryDeclarationFileRespDTOList = BeanCopyUtils.copyBeanList(WorkInjuryDeclarationFileInfoDOList , WorkInjuryDeclarationFileRespDTO.class); WorkInjuryDeclarationDetailRespDTO.setFileList(WorkInjuryDeclarationFileRespDTOList); } return new ResultVO<>(ResultCodes.OK ,WorkInjuryDeclarationDetailRespDTO); } } @Override public ResultVO updateWorkInjuryDeclaration(Long uid, WorkInjuryDeclarationReqDTO WorkInjuryDeclarationReqDTO) { Date nowDate = new Date(); //查询是否存在 WorkInjuryDeclarationInfoDetailDO WorkInjuryDeclarationInfoDetailDO = workInjuryDeclarationInfoService.selectWorkInjuryDeclarationById(WorkInjuryDeclarationReqDTO.getId()); if (WorkInjuryDeclarationInfoDetailDO==null){ throw new AccidentException(AccidentResultCodes.WORK_INJURY_DECLARATION_NOT_EXIST); }else{ WorkInjuryDeclarationInfo WorkInjuryDeclarationInfo = new WorkInjuryDeclarationInfo(); BeanUtils.copyProperties(WorkInjuryDeclarationReqDTO,WorkInjuryDeclarationInfo); WorkInjuryDeclarationInfo.setUpdateUid(uid); WorkInjuryDeclarationInfo.setGmtModitify(nowDate); workInjuryDeclarationInfoService.updateWorkInjuryDeclaration(WorkInjuryDeclarationInfo); //修改工伤申报附件 updateWorkInjuryDeclarationFile(uid,WorkInjuryDeclarationReqDTO.getId(),nowDate,WorkInjuryDeclarationReqDTO.getFileList()); return new ResultVO(ResultCodes.OK); } } private void updateWorkInjuryDeclarationFile(Long uid ,Long WorkInjuryDeclarationId ,Date nowDate,List WorkInjuryDeclarationFileReqDTOList){ List WorkInjuryDeclarationFileInfoDOList = workInjuryDeclarationFileInfoService.selectByWorkInjuryDeclarationId(WorkInjuryDeclarationId); List oldIdsList = WorkInjuryDeclarationFileInfoDOList.stream().map(WorkInjuryDeclarationFileInfoDO::getId).collect(Collectors.toList()); List newIdsList = new ArrayList<>(); //新增的附件集合 List addList = new ArrayList<>(); //删除的附件集合(id) List deleteList = new ArrayList<>(); for (WorkInjuryDeclarationFileReqDTO WorkInjuryDeclarationFileReqDTO : WorkInjuryDeclarationFileReqDTOList){ //如果不存在id则表示页面新增的附件 if (WorkInjuryDeclarationFileReqDTO.getId() == null){ WorkInjuryDeclarationFileInfo WorkInjuryDeclarationFileInfo = new WorkInjuryDeclarationFileInfo(); BeanUtils.copyProperties(WorkInjuryDeclarationFileReqDTO,WorkInjuryDeclarationFileInfo); WorkInjuryDeclarationFileInfo.setDelFlag(false); WorkInjuryDeclarationFileInfo.setGmtCreate(nowDate); WorkInjuryDeclarationFileInfo.setCreateUid(uid); WorkInjuryDeclarationFileInfo.setWorkInjuryDeclarationId(WorkInjuryDeclarationId); addList.add(WorkInjuryDeclarationFileInfo); } //如果存在id则判断页面是否删除 else{ newIdsList.add(WorkInjuryDeclarationFileReqDTO.getId()); } } for (Long oldId : oldIdsList){ if (!newIdsList.contains(oldId)){ deleteList.add(oldId); } } if (!CollectionUtils.isEmpty(addList)){ for (WorkInjuryDeclarationFileInfo WorkInjuryDeclarationFileInfo : addList){ workInjuryDeclarationFileInfoService.addWorkInjuryDeclarationFile(WorkInjuryDeclarationFileInfo); } } if (!CollectionUtils.isEmpty(deleteList)){ workInjuryDeclarationFileInfoService.deleteWorkInjuryDeclarationFileByIds(deleteList); } } @Override public ResultVO batchDeleteWorkInjuryDeclaration(String ids) { if (StringUtils.isBlank(ids)){ throw new AccidentException(AccidentResultCodes.WORK_INJURY_DECLARATION_NULL); }else{ String[] idArr = ids.split(","); for (String id : idArr) { deleteWorkInjuryDeclaration(Long.valueOf(id)); } return new ResultVO(ResultCodes.OK); } } private void deleteWorkInjuryDeclaration(Long id) { //查询是否存在 WorkInjuryDeclarationInfoDetailDO WorkInjuryDeclarationInfoDetailDO = workInjuryDeclarationInfoService.selectWorkInjuryDeclarationById(id); if (WorkInjuryDeclarationInfoDetailDO==null){ throw new AccidentException(AccidentResultCodes.WORK_INJURY_DECLARATION_NOT_EXIST); }else{ workInjuryDeclarationInfoService.deleteWorkInjuryDeclarationById(id); //删除附件 workInjuryDeclarationFileInfoService.deleteWorkInjuryDeclarationFileByWorkInjuryDeclarationId(id); } } /** * 验证必填项 * @return */ private void checkRequired(WorkInjuryDeclarationReqDTO WorkInjuryDeclarationReqDTO) { /* //名称 if (StringUtils.isBlank(WorkInjuryDeclarationReqDTO.getAccidentName())) { throw new AccidentException(AccidentResultCodes.Report_NAME_NULL); } //部门 if (WorkInjuryDeclarationReqDTO.getAccidentDepartmentId()==null) { throw new AccidentException(AccidentResultCodes.Report_DEPARTMENT_NULL); } //发生时间 if (WorkInjuryDeclarationReqDTO.getOccurrenceTime() == null ) { throw new AccidentException(AccidentResultCodes.Report_TIME_NULL); } //发生地点 if (StringUtils.isBlank(WorkInjuryDeclarationReqDTO.getOccurrencePlace())) { throw new AccidentException(AccidentResultCodes.Report_PLACE_NULL); } //事故原因 if (StringUtils.isBlank(WorkInjuryDeclarationReqDTO.getAccidentCause())) { throw new AccidentException(AccidentResultCodes.Report_CAUSE_NULL); } //是否有伤亡 if (WorkInjuryDeclarationReqDTO.getCasualties()==null) { throw new AccidentException(AccidentResultCodes.Report_CASUALTIES_NULL); } //简要经过 if (StringUtils.isBlank(WorkInjuryDeclarationReqDTO.getAccidentBriefProcess())) { throw new AccidentException(AccidentResultCodes.Report_BRIEF_PROCESS_NULL); } //初步分析 if (StringUtils.isBlank(WorkInjuryDeclarationReqDTO.getAccidentCausesPreliminaryAnalysis())) { throw new AccidentException(AccidentResultCodes.Report_CASE_PRELIMINARY_ANALYSIS_NULL); } //应急防范措施 if (StringUtils.isBlank(WorkInjuryDeclarationReqDTO.getEmergencyPrecautions())) { throw new AccidentException(AccidentResultCodes.Report_EMERGENCY_PRECAUTIONS_NULL); }*/ } }