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 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;
|
|
|
@Override
|
public ResultVO<PreventOverhaulLogRespDTO> 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<PreventOverhaulLog> page = PageHelper.startPage(pageIndex, pageSize);
|
List<PreventOverhaulLog> preventOverhaulLogs = overhaulLogRepository.selectOverhaulLogPage(overhaulLogReqBO);
|
List<PreventOverhaulLog> result = page.getResult();
|
|
resultVO.setData(result);
|
resultVO.setCount((int) page.getTotal());
|
resultVO.setPageNum(page.getPageNum());
|
resultVO.setPageSize(page.getPageSize());
|
|
return resultVO;
|
}
|
|
@Override
|
public ResultVO<PreventOverhaulLog> savePreventOverhaulLog(PreventOverhaulLogInsertReqBO insertReqBO) {
|
|
User sysUser = getSysUser();
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
|
|
// if (insertReqBO.getHazardCode().isEmpty()){
|
// throw new RuntimeException("风险分析对象编码为空");
|
// }
|
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);
|
preventOverhaulLog.setRiskUnitId(null);// todo 暂时未设置
|
|
//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<PreventOverhaulLog> updateOverhaulLog(PreventOverhaulLogUpdateReqBO updateReqBO) {
|
|
|
User sysUser = getSysUser();
|
ResultVO resultVO = new ResultVO<>();
|
resultVO.setCode(ErrorCodes.REQUEST_PARAM_ERROR.getCode());
|
|
if (updateReqBO.getHazardCode().isEmpty()){
|
resultVO.setMsg("风险分析对象编码");
|
return resultVO;
|
}
|
if (ObjectUtils.isEmpty(updateReqBO.getRiskUnitId())){
|
resultVO.setMsg("所属安全风险分析单元");
|
return resultVO;
|
}
|
if (ObjectUtils.isEmpty(updateReqBO.getStopStartTime())){
|
resultVO.setMsg("装置停用或者检维修开始时间");
|
return resultVO;
|
}
|
if (ObjectUtils.isEmpty(updateReqBO.getStopEndTime())){
|
resultVO.setMsg("装置停用或者检维修结束时间");
|
return resultVO;
|
}
|
if (updateReqBO.getStopReason().isEmpty()){
|
resultVO.setMsg("描述停用原因");
|
return resultVO;
|
}
|
|
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.setRiskUnitId(null);// todo 暂时未设置
|
|
|
//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(updateReqBO);
|
|
resultVO.setCount(result);
|
resultVO.setCode("200");
|
resultVO.setMsg("保存成功");
|
|
return resultVO;
|
}
|
|
@Override
|
public int deleteOverhaulLogByIds(String ids) {
|
return overhaulLogRepository.deleteOverhaulLogByIds(Convert.toStrArray(ids));
|
}
|
|
@Override
|
public List<PreventOverhaulLog> listReportOverhaulLog() {
|
return overhaulLogRepository.listReportOverhaulLog();
|
}
|
|
@Override
|
public int updateOverhaulReportStatus(HandlerReportParam handlerReportParam) {
|
return overhaulLogRepository.updateOverhaulReportStatus(handlerReportParam);
|
}
|
|
|
}
|