package com.gk.hotwork.specialWork.service.impl; import cn.hutool.core.util.IdUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gk.hotwork.Domain.Enum.ResultCodes; import com.gk.hotwork.Domain.Exception.AusinessException; import com.gk.hotwork.Domain.Exception.E; import com.gk.hotwork.Domain.Vo.PageQuery; import com.gk.hotwork.Domain.Vo.SearchResultVO; import com.gk.hotwork.Domain.co.ContextCacheUser; import com.gk.hotwork.specialWork.entity.WorkApplyInfo; import com.gk.hotwork.specialWork.entity.WorkApplyReportableDO; import com.gk.hotwork.specialWork.entity.WorkProcessDetectionInfo; import com.gk.hotwork.specialWork.entity.WorkProcessWarningInfo; import com.gk.hotwork.specialWork.enums.*; import com.gk.hotwork.specialWork.model.dto.req.WorkProcessDetectionReqDTO; import com.gk.hotwork.specialWork.model.dto.resp.WorkApplyReportableRespDTO; import com.gk.hotwork.specialWork.model.dto.resp.WorkProcessDetectionInfoRespDTO; import com.gk.hotwork.specialWork.model.query.WorkProcessDetectionPageQuery; import com.gk.hotwork.specialWork.model.query.WorkProcessWorkApplyQuery; import com.gk.hotwork.specialWork.model.query.db.WorkProcessDetectionPageDBQuery; import com.gk.hotwork.specialWork.model.query.db.WorkProcessWorkApplyDBQuery; import com.gk.hotwork.specialWork.service.SpecialWorkMinoService; import com.gk.hotwork.specialWork.service.WorkProcessService; import com.gk.hotwork.specialWork.service.baseService.WorkApplyInfoService; import com.gk.hotwork.specialWork.service.baseService.WorkProcessDetectionInfoService; import com.gk.hotwork.specialWork.service.baseService.WorkProcessWarningInfoService; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @Service("workProcessService") public class WorkProcessServiceImpl implements WorkProcessService { @Autowired private WorkApplyInfoService workApplyInfoService; @Autowired private WorkProcessDetectionInfoService workProcessDetectionInfoService; @Autowired private WorkProcessWarningInfoService workProcessWarningInfoService; @Transactional @Override public void detectionReport(ContextCacheUser currentUser, WorkProcessDetectionReqDTO reqDTO) { if (StringUtils.isBlank(reqDTO.getWorkPermitNo())) { throw new AusinessException(E.DATA_PARAM_NULL,"作业编号为空"); } if (reqDTO.getOxygen() == null && reqDTO.getCarbonMonoxide() == null && reqDTO.getCombustible() == null && reqDTO.getHydrogenSulfide() == null) { throw new AusinessException(E.DATA_PARAM_NULL,"至少传入一个数据"); } if (WorkReportSourceEnum.parse(reqDTO.getSource()) == null) { throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "数据状态非法"); } StringBuffer sb = new StringBuffer(); // 数据异常状态判断 WorkProcessDetectionResultEnum detectionResult = WorkProcessDetectionResultEnum.NORMAL; // 氧气 if (reqDTO.getOxygen() != null && reqDTO.getOxygen().compareTo(new BigDecimal("18")) < 0) { detectionResult = WorkProcessDetectionResultEnum.ABNORMAL; sb.append("氧气浓度低于"); sb.append("18"); sb.append(","); } // 可燃气 if (reqDTO.getCombustible() != null && reqDTO.getCombustible().compareTo(new BigDecimal("1")) > 0) { detectionResult = WorkProcessDetectionResultEnum.ABNORMAL; sb.append("可燃气浓度超过"); sb.append("18"); sb.append(","); } // 一氧化碳 if (reqDTO.getCarbonMonoxide() != null && reqDTO.getCarbonMonoxide().compareTo(new BigDecimal("24")) > 0) { detectionResult = WorkProcessDetectionResultEnum.ABNORMAL; sb.append("一氧化碳浓度超过"); sb.append("24"); sb.append(","); } // 硫化氢 if (reqDTO.getHydrogenSulfide() != null && reqDTO.getHydrogenSulfide().compareTo(new BigDecimal("10")) > 0) { detectionResult = WorkProcessDetectionResultEnum.ABNORMAL; sb.append("硫化氢浓度超过"); sb.append("10"); sb.append(","); } sb.deleteCharAt(sb.length() - 1); String workPermitNo = reqDTO.getWorkPermitNo().trim(); WorkApplyInfo workApplyInfo = workApplyInfoService.getApplyInfoByWorkPermitNo(workPermitNo); if (workApplyInfo == null) { throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "作业编号不存在"); } // 审批结束 if (!workApplyInfo.getStatus().equals(WorkStatusEnum.STATU_FINISH.getStatus())) { throw new AusinessException(E.DATA_STATUS_CHECK_INVALID, "未结束审批作业状态无法上报"); } LocalDateTime operationTime = LocalDateTime.now(); // 时间校验 if (operationTime.isBefore(workApplyInfo.getExpStartTime()) || operationTime.isAfter(workApplyInfo.getExpEndTime())) { throw new AusinessException(E.DATA_PARAM_CHECK_INVALID, "上报时间不在作业时间内"); } // exc WorkProcessDetectionInfo detectionEntity = new WorkProcessDetectionInfo(); detectionEntity.setId(IdUtil.getSnowflake(0,0).nextId()); detectionEntity.setWorkApplyId(workApplyInfo.getId()); detectionEntity.setWorkPermitNo(workPermitNo); detectionEntity.setWorkType(workApplyInfo.getWorkType()); detectionEntity.setWorkLevel(workApplyInfo.getWorkLevel()); detectionEntity.setOperationTime(operationTime); detectionEntity.setOperatorUid(currentUser.getUid()); detectionEntity.setOperatorUname(currentUser.getRealName()); detectionEntity.setOperationTime(operationTime); detectionEntity.setInfo(reqDTO.getInfo()); detectionEntity.setCombustible(reqDTO.getCombustible()); detectionEntity.setOxygen(reqDTO.getOxygen()); detectionEntity.setCarbonMonoxide(reqDTO.getCarbonMonoxide()); detectionEntity.setHydrogenSulfide(reqDTO.getHydrogenSulfide()); detectionEntity.setStatus(WorkProcessDetectionStatusEnum.VALID.code); detectionEntity.setSource(reqDTO.getSource()); detectionEntity.setResult(detectionResult.code); workProcessDetectionInfoService.saveWorkProcessDetectionInfo(detectionEntity); // 异常 => 预警 if (detectionResult == WorkProcessDetectionResultEnum.ABNORMAL) { WorkProcessWarningInfo warningInfo = new WorkProcessWarningInfo(); warningInfo.setId(IdUtil.getSnowflake(0,0).nextId()); warningInfo.setWorkApplyId(workApplyInfo.getId()); warningInfo.setWorkPermitNo(workApplyInfo.getWorkPermitNo()); warningInfo.setWarningContent(sb.toString()); warningInfo.setWarningType(WorkProcessWarningTypeEnum.CHECK.code); warningInfo.setWarningInfo(detectionEntity.getInfo()); warningInfo.setOperatorUid(currentUser.getUid()); warningInfo.setOperatorUname(currentUser.getRealName()); warningInfo.setOperationTime(operationTime); warningInfo.setStatus(WorkProcessWarningStatusEnum.VALID.code); warningInfo.setSource(reqDTO.getSource()); warningInfo.setWorkType(workApplyInfo.getWorkType()); warningInfo.setWorkLevel(workApplyInfo.getWorkLevel()); warningInfo.setOriginalId(detectionEntity.getId()); workProcessWarningInfoService.saveWorkProcessWarningInfo(warningInfo); } } @Override public SearchResultVO> listDetectionByPage(ContextCacheUser currentUser, PageQuery pageQuery) { WorkProcessDetectionPageDBQuery dbQuery = new WorkProcessDetectionPageDBQuery(); if (pageQuery.getSearchParams() != null) { dbQuery.setResult(pageQuery.getSearchParams().getResult()); dbQuery.setWorkPermitNo(pageQuery.getSearchParams().getWorkPermitNo()); dbQuery.setWorkType(pageQuery.getSearchParams().getWorkType()); } Page page = new Page<>(pageQuery.getPageIndex(), pageQuery.getPageSize()); List dbData = workProcessDetectionInfoService.listWorkDetectionInfoByPage(page, dbQuery); List result = new ArrayList<>(dbData.size()); if (dbData.size() > 0) { WorkProcessDetectionInfoRespDTO respDTO; WorkTypeEnum workTypeEnum; WorkLevelEnum workLevelEnum; WorkProcessDetectionStatusEnum statusEnum; WorkProcessDetectionResultEnum resultEnum; WorkReportSourceEnum sourceEnum; for (WorkProcessDetectionInfo detectionInfo : dbData) { respDTO = new WorkProcessDetectionInfoRespDTO(); respDTO.setWorkProcessDetectionId(detectionInfo.getId()); respDTO.setWorkApplyId(detectionInfo.getWorkApplyId()); respDTO.setWorkPermitNo(detectionInfo.getWorkPermitNo()); respDTO.setWorkType(detectionInfo.getWorkType()); workTypeEnum = WorkTypeEnum.parse(detectionInfo.getWorkType()); if (workTypeEnum != null) { respDTO.setWorkTypeDesc(workTypeEnum.getName()); } respDTO.setWorkLevel(detectionInfo.getWorkLevel()); workLevelEnum = WorkLevelEnum.parse(detectionInfo.getWorkLevel()); if (workLevelEnum != null) { respDTO.setWorkLevelDesc(workLevelEnum.getTitle()); } respDTO.setOperationTime(detectionInfo.getOperationTime()); respDTO.setOperatorUname(detectionInfo.getOperatorUname()); respDTO.setOperatorUid(detectionInfo.getOperatorUid()); respDTO.setInfo(detectionInfo.getInfo()); respDTO.setCombustible(detectionInfo.getCombustible()); respDTO.setOxygen(detectionInfo.getOxygen()); respDTO.setCarbonMonoxide(detectionInfo.getCarbonMonoxide()); respDTO.setHydrogenSulfide(detectionInfo.getHydrogenSulfide()); respDTO.setStatus(detectionInfo.getStatus()); statusEnum = WorkProcessDetectionStatusEnum.parse(detectionInfo.getStatus()); if (statusEnum != null) { respDTO.setStatusDesc(statusEnum.value); } respDTO.setResult(detectionInfo.getResult()); resultEnum = WorkProcessDetectionResultEnum.parse(detectionInfo.getResult()); if (resultEnum != null) { respDTO.setResultDesc(resultEnum.value); } respDTO.setSource(detectionInfo.getSource()); sourceEnum = WorkReportSourceEnum.parse(detectionInfo.getSource()); if (sourceEnum != null) { respDTO.setSourceDesc(sourceEnum.value); } result.add(respDTO); } } return new SearchResultVO<>( true, page.getCurrent(), page.getSize(), page.getPages(), page.getTotal(), result, ResultCodes.OK); } @Override public List listReportableWorkApply(ContextCacheUser currentUser, WorkProcessWorkApplyQuery query) { WorkProcessWorkApplyDBQuery dbQuery = new WorkProcessWorkApplyDBQuery(); dbQuery.setWorkPermitNo(query.getWorkPermitNo()); dbQuery.setWorkType(query.getWorkType()); dbQuery.setNow(LocalDateTime.now()); dbQuery.setStatus(WorkStatusEnum.STATU_FINISH.getStatus()); List dbData = workApplyInfoService.listReportableWorkApply(dbQuery); List result = new ArrayList<>(dbData.size()); if (dbData.size() > 0) { WorkApplyReportableRespDTO respDTO; WorkTypeEnum typeEnum; WorkLevelEnum levelEnum; WorkStatusEnum statusEnum; for (WorkApplyReportableDO workApplyInfo : dbData) { respDTO = new WorkApplyReportableRespDTO(); respDTO.setWorkApplyId(workApplyInfo.getId()); respDTO.setWorkType(workApplyInfo.getWorkType()); respDTO.setWorkLevel(workApplyInfo.getWorkLevel()); respDTO.setWorkPermitNo(workApplyInfo.getWorkPermitNo()); respDTO.setWorkContent(workApplyInfo.getWorkContent()); respDTO.setWorkLocation(workApplyInfo.getWorkLocation()); respDTO.setHazardIdentification(workApplyInfo.getHazardIdentification()); respDTO.setStatus(workApplyInfo.getStatus()); typeEnum = WorkTypeEnum.parse(workApplyInfo.getWorkType()); if (typeEnum != null) { respDTO.setWorkTypeDesc(typeEnum.getName()); } levelEnum = WorkLevelEnum.parse(workApplyInfo.getWorkLevel()); if (levelEnum != null) { respDTO.setWorkLevelDesc(levelEnum.getTitle()); } statusEnum = WorkStatusEnum.parse(workApplyInfo.getStatus()); if (statusEnum != null) { respDTO.setStatusDesc(statusEnum.getDesc()); } respDTO.setExpStartTime(workApplyInfo.getExpStartTime()); respDTO.setExpEndTime(workApplyInfo.getExpEndTime()); result.add(respDTO); } } return result; } }