package com.ruoyi.project.tr.specialCheck.service.impl; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.ruoyi.doublePrevention.entity.PreventRiskControlMeasure; import com.ruoyi.doublePrevention.enums.ErrorCodes; import com.ruoyi.doublePrevention.enums.ResultCodes; 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 com.ruoyi.project.tr.specialCheck.domin.BO.*; import com.ruoyi.project.tr.specialCheck.domin.TbSpecialCheckTaskLog; import com.ruoyi.project.tr.specialCheck.mapper.*; import com.ruoyi.project.tr.specialCheck.service.SpecialCheckTaskService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.time.LocalDateTime; import java.util.Date; import java.util.List; import java.util.UUID; import static com.ruoyi.common.utils.security.ShiroUtils.getSysUser; @Service public class SpecialCheckTaskServiceImpl implements SpecialCheckTaskService { @Autowired private TbBaseCheckCompanyMapper companyTbRepository; @Autowired private TbBaseCheckItemMapper itemTbRepository; @Autowired private TbBaseCheckScoreMapper scoreTbRepository; @Autowired private TbBaseCheckTaskMapper taskTbRepository; @Autowired private TbSpecialCheckTaskLogMapper taskSpecialLogMapper; @Autowired private IRiskListService riskListService; @Override public ResultVO> selectSpecialCheckTaskLogPage(TbSpecialCheckTaskLogBO specialCheckTaskLogBO) { Integer pageIndex = specialCheckTaskLogBO.getPageNum(); Integer pageSize = specialCheckTaskLogBO.getPageSize(); if (pageIndex == 0 || pageSize == 0){ return new ResultVO<>(ErrorCodes.REQUEST_PARAM_ERROR.getCode(),"当前页码或当前页显示数不能为0"); } Page page = PageHelper.startPage(pageIndex, pageSize); taskSpecialLogMapper.selectSpecialCheckTaskLogPage(specialCheckTaskLogBO); Long total = page.getTotal(); int count = total.intValue(); List pageResult = null; ResultVO> resultVO = new ResultVO<>(ResultCodes.OK,pageResult); resultVO.setData(page.getResult()); resultVO.setCount(count); resultVO.setCount((int) page.getTotal()); resultVO.setPageNum(page.getPageNum()); resultVO.setPageSize(page.getPageSize()); return resultVO; } @Override public ResultVO addSpecialTask(TbSpecialCheckTaskLog tbSpecialCheckTaskLog) { User sysUser = getSysUser(); ResultVO resultVO = new ResultVO<>(); resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode()); if (tbSpecialCheckTaskLog.getHazardCode() == null){ resultVO.setMsg("重大风险源不能为空"); return resultVO; } RiskList infoByRiskListNum = riskListService.getInfoByRiskListNum(tbSpecialCheckTaskLog.getHazardCode()); if (ObjectUtils.isEmpty(infoByRiskListNum)){ resultVO.setMsg("请检查重大风险源是否存在"); return resultVO; } if (tbSpecialCheckTaskLog.getTaskId() == null){ resultVO.setMsg("专项任务不能为空"); return resultVO; } if (tbSpecialCheckTaskLog.getCheckType() == null){ resultVO.setMsg("检查类型不能为空"); return resultVO; } if (tbSpecialCheckTaskLog.getResultStatus() == null){ resultVO.setMsg("结果不能为空"); return resultVO; } if (tbSpecialCheckTaskLog.getCheckDate() == null){ resultVO.setMsg("检查日期不能为空"); return resultVO; } LocalDateTime dateTime = LocalDateTime.now(); String uuid = UUID.randomUUID().toString(); tbSpecialCheckTaskLog.setId(uuid); tbSpecialCheckTaskLog.setHazardSource(infoByRiskListNum.getRiskListName()); tbSpecialCheckTaskLog.setCompanyCode("652310082"); tbSpecialCheckTaskLog.setCreateDate(dateTime); tbSpecialCheckTaskLog.setUpdateDate(dateTime); tbSpecialCheckTaskLog.setCreateBy(sysUser.getUserName()); tbSpecialCheckTaskLog.setUpdateBy(sysUser.getUserName()); tbSpecialCheckTaskLog.setReportStatus((byte) 1); tbSpecialCheckTaskLog.setReportTime(null); tbSpecialCheckTaskLog.setDeleted((byte) 0); int saveResult = taskSpecialLogMapper.save(tbSpecialCheckTaskLog); if (saveResult == 0){ resultVO.setCode(ResultCodes.SERVER_ADD_ERROR.getCode()); resultVO.setMsg(ResultCodes.SERVER_ADD_ERROR.getDesc()); return resultVO; } resultVO.setCode(ResultCodes.OK.getCode()); resultVO.setMsg("新增任务成功"); return resultVO; } @Override public TbSpecialCheckTaskLog getSpecialCheckTaskLogByIndexId(Long id) { return taskSpecialLogMapper.getSpecialCheckTaskLogByIndexId(id); } @Override public ResultVO updateSpecialCheckTaskLog(TbSpecialCheckTaskLogUpdateBO updateBO) { User sysUser = getSysUser(); ResultVO resultVO = new ResultVO<>(); resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode()); if (updateBO.getIndexId() == null){ resultVO.setMsg("任务不能为空"); return resultVO; } TbSpecialCheckTaskLog specialCheckTaskLogByIndexId = taskSpecialLogMapper.getSpecialCheckTaskLogByIndexId(updateBO.getIndexId()); if (ObjectUtils.isEmpty(specialCheckTaskLogByIndexId)){ resultVO.setMsg("任务不存在"); return resultVO; } if (updateBO.getHazardCode() == null){ resultVO.setMsg("重大风险源不能为空"); return resultVO; } RiskList infoByRiskListNum = riskListService.getInfoByRiskListNum(updateBO.getHazardCode()); if (ObjectUtils.isEmpty(infoByRiskListNum)){ resultVO.setMsg("请检查重大风险源是否存在"); return resultVO; } if (updateBO.getTaskId() == null){ resultVO.setMsg("专项任务不能为空"); return resultVO; } if (updateBO.getCheckType() == null){ resultVO.setMsg("检查类型不能为空"); return resultVO; } if (updateBO.getResultStatus() == null){ resultVO.setMsg("结果不能为空"); return resultVO; } if (updateBO.getCheckDate() == null){ resultVO.setMsg("检查日期不能为空"); return resultVO; } LocalDateTime dateTime = LocalDateTime.now(); updateBO.setHazardSource(infoByRiskListNum.getRiskListName()); updateBO.setUpdateDate(dateTime); updateBO.setUpdateBy(sysUser.getUserName()); updateBO.setReportStatus((byte) 1); int updateResult = taskSpecialLogMapper.updateSpecialCheckTaskLogById(updateBO); if (updateResult == 0){ resultVO.setCode(ResultCodes.SERVER_UPDATE_ERROR.getCode()); resultVO.setMsg(ResultCodes.SERVER_UPDATE_ERROR.getDesc()); return resultVO; } resultVO.setCode(ResultCodes.OK.getCode()); resultVO.setMsg("更新任务成功"); return resultVO; } @Override public ResultVO deleteTbSpecialCheckTaskLog(TbSpecialCheckTaskLogUpdateBO updateBO) { User sysUser = getSysUser(); ResultVO resultVO = new ResultVO<>(); resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode()); if (updateBO.getIndexId() == null){ resultVO.setMsg("任务为空,删除失败"); return resultVO; } TbSpecialCheckTaskLog specialCheckTaskLogByIndexId = taskSpecialLogMapper.getSpecialCheckTaskLogByIndexId(updateBO.getIndexId()); if (ObjectUtils.isEmpty(specialCheckTaskLogByIndexId)){ resultVO.setMsg("任务不存在,删除失败"); return resultVO; } TbSpecialCheckTaskLog tbSpecialCheckTaskLog = new TbSpecialCheckTaskLog(); LocalDateTime dateTime = LocalDateTime.now(); tbSpecialCheckTaskLog.setIndexId(updateBO.getIndexId()); tbSpecialCheckTaskLog.setUpdateDate(dateTime); tbSpecialCheckTaskLog.setUpdateBy(sysUser.getUserName()); tbSpecialCheckTaskLog.setReportStatus((byte) 1); tbSpecialCheckTaskLog.setDeleted((byte) 1); int deleteResult = taskSpecialLogMapper.deleteTbSpecialCheckTaskLog(tbSpecialCheckTaskLog); if (deleteResult == 0){ resultVO.setCode(ResultCodes.SERVER_DEL_ERROR.getCode()); resultVO.setMsg(ResultCodes.SERVER_DEL_ERROR.getDesc()); return resultVO; } resultVO.setCode(ResultCodes.OK.getCode()); resultVO.setMsg("删除成功"); return resultVO; } }