package com.ruoyi.doublePrevention.service.baseService.impl; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.ruoyi.common.exception.BusinessException; import com.ruoyi.common.utils.BeanCopyUtils; import com.ruoyi.common.utils.text.Convert; import com.ruoyi.doublePrevention.entity.PreventOverhaulLog; import com.ruoyi.doublePrevention.entity.PreventReportConfig; import com.ruoyi.doublePrevention.entity.dto.req.PreventOverhaulLogInsertReqBO; import com.ruoyi.doublePrevention.entity.dto.req.PreventOverhaulLogReqBO; import com.ruoyi.doublePrevention.entity.dto.req.PreventOverhaulLogUpdateReqBO; import com.ruoyi.doublePrevention.entity.dto.resp.PreventOverhaulLogRespDTO; import com.ruoyi.doublePrevention.enums.ErrorCodes; import com.ruoyi.doublePrevention.enums.SyncEnum; import com.ruoyi.doublePrevention.repository.PreventOverhaulLogRepository; import com.ruoyi.doublePrevention.repository.param.HandlerReportParam; import com.ruoyi.doublePrevention.service.baseService.PreventOverhaulLogService; import com.ruoyi.doublePrevention.service.baseService.PreventReportConfigService; import com.ruoyi.doublePrevention.vo.ResultVO; import com.ruoyi.project.system.user.domain.User; import com.ruoyi.project.tr.riskList.domain.RiskList; import com.ruoyi.project.tr.riskList.service.IRiskListService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.util.Date; import java.util.List; import java.util.UUID; import static com.ruoyi.common.utils.security.ShiroUtils.getSysUser; @Service public class PreventOverhaulLogServiceImpl implements PreventOverhaulLogService { @Autowired private PreventOverhaulLogRepository overhaulLogRepository; @Autowired private PreventReportConfigService preventReportConfigService; @Autowired private IRiskListService iRiskListService; @Override public ResultVO selectOverhaulLogPage(PreventOverhaulLogReqBO overhaulLogReqBO) { ResultVO resultVO = new ResultVO<>(); if (ObjectUtils.isEmpty(overhaulLogReqBO.getPageSize())){ throw new BusinessException("分页信息不能为空"); } if (ObjectUtils.isEmpty(overhaulLogReqBO.getPageNum())){ throw new BusinessException("分页信息不能为空"); } Integer pageIndex = overhaulLogReqBO.getPageNum(); Integer pageSize = overhaulLogReqBO.getPageSize(); Page page = PageHelper.startPage(pageIndex, pageSize); List preventOverhaulLogs = overhaulLogRepository.selectOverhaulLogPage(overhaulLogReqBO); List result = page.getResult(); List preventOverhaulLogRespDTOS = BeanCopyUtils.copyBeanList(result, PreventOverhaulLogRespDTO.class); List riskUnitLists = iRiskListService.getRiskUnitLists(); for (PreventOverhaulLogRespDTO overhaulLog : preventOverhaulLogRespDTOS) { for (RiskList riskUnit : riskUnitLists) { if (overhaulLog.getRiskUnitId() == riskUnit.getRiskListId()){ overhaulLog.setRiskUnitName(riskUnit.getRiskListName()); } } } resultVO.setData(preventOverhaulLogRespDTOS); resultVO.setCount((int) page.getTotal()); resultVO.setPageNum(page.getPageNum()); resultVO.setPageSize(page.getPageSize()); return resultVO; } @Override public ResultVO savePreventOverhaulLog(PreventOverhaulLogInsertReqBO insertReqBO) { User sysUser = getSysUser(); ResultVO resultVO = new ResultVO<>(); resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode()); if (ObjectUtils.isEmpty(insertReqBO.getRiskUnitId())){ throw new RuntimeException("安全风险分析单元为空"); } if (ObjectUtils.isEmpty(insertReqBO.getStopStartTime())){ throw new RuntimeException("装置停用或者检维修开始时间为空"); } if (ObjectUtils.isEmpty(insertReqBO.getStopEndTime())){ throw new RuntimeException("装置停用或者检维修结束时间为空"); } if (insertReqBO.getStopReason().isEmpty()){ throw new RuntimeException("停用原因为空"); } Date date = new Date(); String uuid = UUID.randomUUID().toString(); PreventOverhaulLog preventOverhaulLog = BeanCopyUtils.copyBean(insertReqBO, PreventOverhaulLog.class); preventOverhaulLog.setUuid(uuid); preventOverhaulLog.setDeleteStatus((byte) 0); preventOverhaulLog.setCreateByUserName(sysUser.getUserName()); preventOverhaulLog.setGmtCreate(date); preventOverhaulLog.setLastEditUserName(sysUser.getUserName()); preventOverhaulLog.setGmtModitify(date); //todo 对所属企业id和uuid没有进行设置 PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode()); //设置上报时间为空 preventOverhaulLog.setReportTime(null); //设置本条数据上报更新时间 preventOverhaulLog.setUpdateReportDataTime(date); //读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置 if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode() && reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){ //设置上报状态为-等待上报 preventOverhaulLog.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode()); //设置本条数据上报开关为-开启 preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_ON.getCode()); //其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作 }else { //设置上报状态为-不上报 preventOverhaulLog.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode()); //设置本条数据上报开关为-关闭 preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_OFF.getCode()); } int result = overhaulLogRepository.savePreventOverhaulLog(preventOverhaulLog); resultVO.setCount(result); resultVO.setCode("200"); resultVO.setMsg("保存成功"); return resultVO; } /** * 查询 by id * */ @Override public PreventOverhaulLog getOverhaulLogById(Long id) { return overhaulLogRepository.getOverhaulLogById(id); } /** * 修改保存 * */ @Override public ResultVO updateOverhaulLog(PreventOverhaulLogUpdateReqBO updateReqBO) { User sysUser = getSysUser(); ResultVO resultVO = new ResultVO<>(); resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode()); resultVO.setCode("200"); resultVO.setMsg("保存成功"); if (ObjectUtils.isEmpty(updateReqBO.getId())){ throw new RuntimeException("所选记录不能为空"); } PreventOverhaulLog overhaulLogById = overhaulLogRepository.getOverhaulLogById(updateReqBO.getId()); if (ObjectUtils.isEmpty(overhaulLogById)){ throw new RuntimeException("记录不存在或已被被删除"); } if (ObjectUtils.isEmpty(updateReqBO.getRiskUnitId())){ throw new RuntimeException("安全风险分析单元为空"); } if (ObjectUtils.isEmpty(updateReqBO.getStopStartTime())){ throw new RuntimeException("装置停用或者检维修开始时间为空"); } if (ObjectUtils.isEmpty(updateReqBO.getStopEndTime())){ throw new RuntimeException("装置停用或者检维修结束时间为空"); } if (updateReqBO.getStopReason().isEmpty()){ throw new RuntimeException("停用原因为空"); } Date date = new Date(); String uuid = UUID.randomUUID().toString(); PreventOverhaulLog preventOverhaulLog = BeanCopyUtils.copyBean(updateReqBO, PreventOverhaulLog.class); preventOverhaulLog.setUuid(uuid); preventOverhaulLog.setDeleteStatus((byte) 0); preventOverhaulLog.setLastEditUserName(sysUser.getUserName()); preventOverhaulLog.setGmtModitify(date); preventOverhaulLog.setLastEditUserName(sysUser.getUserName()); preventOverhaulLog.setGmtModitify(date); //todo 对所属企业id和uuid没有进行设置 PreventReportConfig reportConfigById = preventReportConfigService.getReportConfigById(SyncEnum.REPORT_CONFIG_RISK_ANA_UNIT.getCode()); //设置上报时间为空 preventOverhaulLog.setReportTime(null); //设置本条数据上报更新时间 preventOverhaulLog.setUpdateReportDataTime(date); //读取上报主配置,进行任务记录上报配置,如果开启上报功能,且设置为自动上报,开启上报相关配置 if (reportConfigById.getReportState() == SyncEnum.REPORT_ON.getCode() && reportConfigById.getReportType() == SyncEnum.REPORT_HAND_EXEC_CONFIG.getCode()){ //设置上报状态为-等待上报 preventOverhaulLog.setReportStatus(SyncEnum.SYNC_WAIT_EXEC.getCode()); //设置本条数据上报开关为-开启 preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_ON.getCode()); //其他情况默认不开启上报数据,如果是手动上报,可对单条数据进行操作 }else { //设置上报状态为-不上报 preventOverhaulLog.setReportStatus(SyncEnum.SYNC_NOT_EXEC.getCode()); //设置本条数据上报开关为-关闭 preventOverhaulLog.setReportSwitch(SyncEnum.REPORT_OFF.getCode()); } int result = overhaulLogRepository.updateOverhaulLog(preventOverhaulLog); if (result < 1){ throw new RuntimeException("操作失败"); } resultVO.setCount(result); return resultVO; } @Override public int deleteOverhaulLogByIds(String ids) { return overhaulLogRepository.deleteOverhaulLogByIds(Convert.toStrArray(ids)); } @Override public List listReportOverhaulLog() { return overhaulLogRepository.listReportOverhaulLog(); } @Override public int updateOverhaulReportStatus(HandlerReportParam handlerReportParam) { return overhaulLogRepository.updateOverhaulReportStatus(handlerReportParam); } }