郑永安
2023-09-19 69185134fcfaf913ea45f1255677225a2cc311a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
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;
    }
 
 
 
}