package com.gk.hotwork.Scheduls.warning;
|
|
import com.gk.hotwork.Domain.*;
|
import com.gk.hotwork.Domain.Enum.TaskType;
|
import com.gk.hotwork.Domain.Vo.TaskVo;
|
import com.gk.hotwork.Domain.Vo.TaskWorkerVo;
|
import com.gk.hotwork.Scheduls.uploadUser.uploadUserTask;
|
import com.gk.hotwork.Service.TaskGasService;
|
import com.gk.hotwork.Service.TaskService;
|
import com.gk.hotwork.Service.WarningService;
|
import org.apache.log4j.LogManager;
|
import org.apache.log4j.Logger;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* @author : jingjy
|
* @date : 2021/9/9 10:38
|
*/
|
//@Configuration
|
//@EnableScheduling
|
//@ConditionalOnProperty(prefix = "scheduling", name = "enabled", havingValue = "true")
|
public class Warning {
|
@Autowired
|
private TaskGasService taskGasService;
|
@Autowired
|
private WarningService warningService;
|
@Autowired
|
private TaskService taskService;
|
|
@Scheduled(cron = "0/30 * * * * ?") //每隔30秒执行一次
|
public void setWarning(){
|
Date now = new Date();
|
Date startTime = new Date(now.getTime() - 2*60*1000);
|
List<TaskVo> taskVos = taskService.getDoingTask();
|
if (taskVos == null || taskVos.size() < 1){
|
return;
|
}
|
for (TaskVo taskVo : taskVos){
|
List<TaskWorkerVo>taskWorkers = taskVo.getTaskWorkers();
|
for (TaskWorkerVo taskWorkerVo : taskWorkers){
|
//检查设备是否齐全
|
boolean result = hasNecessaryEquipment(taskWorkerVo);
|
//判断当前动火人是否有设备,没有则不进行下面判断
|
if (!result){
|
continue;
|
}
|
//报警
|
List<TaskGasInfo>taskGasInfos = taskGasService.getWarnList(taskVo.getCode(),taskWorkerVo.getWorker(),startTime,now);
|
dealWarn(taskGasInfos,taskWorkerVo,"报警",now);
|
|
//预警
|
List<TaskGasInfo>taskGasInfoList = taskGasService.getEarlyWarnList(taskVo.getCode(),taskWorkerVo.getWorker(),startTime,now);
|
dealWarn(taskGasInfoList,taskWorkerVo,"预警",now);
|
|
//故障
|
boolean isEquipmentError = taskGasService.isEquipmentError(taskVo.getCode(),taskWorkerVo.getWorker(),startTime,now);
|
if (isEquipmentError){
|
WarningInfo warningInfo = new WarningInfo();
|
String content = "在任务 "+taskWorkerVo.getTaskcode()+" 中,动火人:"+taskWorkerVo.getWorker()+"气体探测器故障";
|
warningInfo.setCreatedat(now);
|
warningInfo.setTaskcode(taskWorkerVo.getTaskcode());
|
warningInfo.setTasktype(TaskType.getTaskType(taskWorkerVo.getTasktype()));
|
warningInfo.setContent(content);
|
warningInfo.setType(WarningInfo.FAULT);
|
warningInfo.setWorker(taskWorkerVo.getWorker());
|
warningService.save(warningInfo);
|
}else {
|
String type = "故障";
|
List<WarningInfo>warningInfos = warningService.getBeforeWarn(taskWorkerVo.getTaskcode(),taskWorkerVo.getWorker(),type,now);
|
if (warningInfos != null && warningInfos.size() > 0){
|
for (WarningInfo warningInfo : warningInfos){
|
warningInfo.setIsdeal((byte)1);
|
}
|
warningService.updateBatchById(warningInfos);
|
}
|
}
|
}
|
|
}
|
|
}
|
|
private void dealWarn(List<TaskGasInfo> taskGasInfos, TaskWorkerVo taskWorkerVo, String type, Date now) {
|
if (taskGasInfos != null && taskGasInfos.size() > 0){
|
for (TaskGasInfo taskGasInfo : taskGasInfos){
|
String content = "在任务 "+taskWorkerVo.getTaskcode()+" 中,动火人:"+taskWorkerVo.getWorker()+"气体探测器数据异常,"
|
+taskGasInfo.getGastype()+":"+taskGasInfo.getGasvalue()+taskGasInfo.getGasunit();
|
WarningInfo warningInfo = new WarningInfo();
|
warningInfo.setCreatedat(taskGasInfo.getUpdatetime());
|
warningInfo.setTaskcode(taskGasInfo.getTaskcode());
|
warningInfo.setWorker(taskWorkerVo.getWorker());
|
warningInfo.setTasktype(TaskType.getTaskType(taskWorkerVo.getTasktype()));
|
if (taskGasInfo.getIswarn() == 1){
|
warningInfo.setContent(content);
|
warningInfo.setType(WarningInfo.WARNING);
|
WarningInfo warningInfoExist = warningService.getByContent(taskWorkerVo.getTaskcode(),taskWorkerVo.getWorker(),content);
|
if (warningInfoExist == null){
|
warningService.save(warningInfo);
|
}
|
}
|
if (taskGasInfo.getIsyujing() == 1){
|
warningInfo.setContent(content);
|
warningInfo.setType(WarningInfo.EARLY_WARNING);
|
WarningInfo warningInfoExist = warningService.getByContent(taskWorkerVo.getTaskcode(),taskWorkerVo.getWorker(),content);
|
if (warningInfoExist == null){
|
warningService.save(warningInfo);
|
}
|
}
|
}
|
}else {
|
List<WarningInfo>warningInfos = warningService.getBeforeWarn(taskWorkerVo.getTaskcode(),taskWorkerVo.getWorker(),type,now);
|
if (warningInfos != null && warningInfos.size() > 0){
|
for (WarningInfo warningInfo : warningInfos){
|
warningInfo.setIsdeal((byte)1);
|
}
|
warningService.updateBatchById(warningInfos);
|
}
|
}
|
}
|
|
private boolean hasNecessaryEquipment(TaskWorkerVo taskWorkerVo) {
|
List<EquipmentInfo> equipmentInfos = taskWorkerVo.getEquipments();
|
if (equipmentInfos == null || equipmentInfos.size() < 1){
|
return false;
|
}
|
boolean hasGasDetector = false;
|
boolean hasHelmet = false;
|
String content;
|
for (EquipmentInfo equipmentInfo : equipmentInfos){
|
if (equipmentInfo.getName().equals("气体探测器")){
|
hasGasDetector = true;
|
}
|
if (equipmentInfo.getName().equals("头盔")){
|
hasHelmet = true;
|
}
|
}
|
|
WarningInfo warningInfo = new WarningInfo();
|
warningInfo.setCreatedat(new Date());
|
warningInfo.setTaskcode(taskWorkerVo.getTaskcode());
|
warningInfo.setTasktype(TaskType.getTaskType(taskWorkerVo.getTasktype()));
|
warningInfo.setType(WarningInfo.WARNING);
|
warningInfo.setWorker(taskWorkerVo.getWorker());
|
if (!hasGasDetector){
|
content = "在任务 "+taskWorkerVo.getTaskcode()+" 中,动火人:"+taskWorkerVo.getWorker()+"缺少气体探测器";
|
warningInfo.setContent(content);
|
WarningInfo warningInfoExist = warningService.getByContent(taskWorkerVo.getTaskcode(), taskWorkerVo.getWorker(), content);
|
if (warningInfoExist == null){
|
warningService.save(warningInfo);
|
}
|
}
|
if (!hasHelmet){
|
content = "在任务 "+taskWorkerVo.getTaskcode()+" 中,动火人:"+taskWorkerVo.getWorker()+"缺少头盔";
|
warningInfo.setContent(content);
|
WarningInfo warningInfoExist = warningService.getByContent(taskWorkerVo.getTaskcode(),taskWorkerVo.getWorker(),content);
|
if (warningInfoExist == null){
|
warningService.save(warningInfo);
|
}
|
}
|
|
return true;
|
}
|
|
|
|
}
|