RealTimeWarnJob.java
23.8 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
package com.skua.modules.alarm.quartz;
import com.skua.core.context.SpringContextUtils;
import com.skua.core.service.IFactoryInfoService;
import com.skua.core.service.ISequenceService;
import com.skua.core.util.ConvertUtils;
import com.skua.core.util.DateUtils;
import com.skua.core.util.DoubleOperaUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* <pre>
* 按照客户要求开发预警逻辑
* </pre>
* @author Li Yuanyuan
* @version V0.1, 2021年3月22日 下午1:32:26
*/
@Slf4j
public class RealTimeWarnJob implements Job {
@Autowired
private IFactoryInfoService factoryInfoService;
@Autowired
private ISequenceService sequenceService;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("********预警监测定时服务开启********");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date nowDate = new Date();
String nowDay = DateUtils.getTodayOrMonthDate("day");
Date afterDate = new Date(nowDate.getTime() - 600000);
//昨天
String yesterday = DateUtils.getYesterday();
String yesterdayStart = yesterday+" 00:00:00";
String yesterdayEnd = yesterday+" 23:59:59";
//前天
String qt = "";
try {
qt = DateUtils.formatAddTime(yesterday,"yyyy-MM-dd",Calendar.DATE,-1);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String qtStart = qt+" 00:00:00";
String qtEnd = qt+" 23:59:59";
//大前天
String dqt = "";
try {
dqt = DateUtils.formatAddTime(yesterday,"yyyy-MM-dd",Calendar.DATE,-2);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String dqtStart = dqt+" 00:00:00";
String dqtEnd = dqt+" 23:59:59";
JdbcTemplate masterDB = (JdbcTemplate) SpringContextUtils.getBean("master");
//获取预警规则配置表
List<Map<String,Object>> configList = masterDB.queryForList("select a.*,b.out_level,c.depart_name from alarm_warning_config a left join sys_factory_info b on a.factory_id=b.factory_id inner join sys_depart c on a.factory_id=c.id where use_flag='1'");
//出水阈值配置
Map<String,Object> outLevelMap = new HashMap<String,Object>();
outLevelMap.put("a_cod", "50");
outLevelMap.put("a_nh3_12s", "5");
outLevelMap.put("a_nh3_12x", "8");
outLevelMap.put("a_tn", "15");
outLevelMap.put("a_tp", "0.5");
outLevelMap.put("b_cod", "60");
outLevelMap.put("b_nh3_12s", "8");
outLevelMap.put("b_nh3_12x", "15");
outLevelMap.put("b_tn", "20");
outLevelMap.put("b_tp", "1");
//使用hashMap构造厂站规则对应关系
Map<String,Map<String,Object>> configMap = new HashMap<String,Map<String,Object>>();
for(Map<String,Object> map : configList) {
configMap.put(ConvertUtils.getString(map.get("factory_id")), map);
}
//获取参加预警的个厂站真实指标
Map<String,Map<String,Object>> fieldMap = new HashMap<String,Map<String,Object>>();
List<Map<String,Object>> fieldList = masterDB.queryForList("select a.id,a.metric_uid_tag,a.metric_name,a.metric_unit,a.fac_code from sys_monitor_metric_info a inner join sys_metric_dict b on a.metric_uid_tag = b.id where b.id in('CSCOD','CSNH3N','CSTP','CSTN','CSSW') and a.fac_code in (select factory_id from alarm_warning_config where use_flag='1')");
//使用hashMap构造指标厂站对应关系
for(Map<String,Object> map : fieldList) {
String factory_id = ConvertUtils.getString(map.get("fac_code"));
Map<String, Object> factoryFieldMap = fieldMap.get(factory_id);
if(factoryFieldMap==null) {
factoryFieldMap = new HashMap<String,Object>();
fieldMap.put(factory_id, factoryFieldMap);
}
factoryFieldMap.put(ConvertUtils.getString(map.get("metric_uid_tag")), map);
}
//获取报警表未处理的报警记录
List<String> warnRecordTagList = new ArrayList<String>();
List<Map<String, Object>> warnRecords = masterDB.queryForList("select factory_id,alarm_param_code from alarm_warning_record_history where DATE_FORMAT(record_time,'%Y-%m-%d') ='"+nowDay+"' and handle_status='0'");
for(Map<String, Object> warnRecord : warnRecords) {
warnRecordTagList.add(ConvertUtils.getString(warnRecord.get("factory_id"))+ConvertUtils.getString(warnRecord.get("alarm_param_code")));
}
Set<String> factroyIds = configMap.keySet();
for(String factoryId : factroyIds) {
//获取厂站下的所有未处理预警通知,如果通知未处理,则不进行再次预警
//根据厂站获取厂站报警规则
Map<String, Object> config = configMap.get(factoryId);
String out_level = ConvertUtils.getString(config.get("out_level"),"B").toLowerCase();
String factory_name = ConvertUtils.getString(config.get("depart_name"));
//获取厂站下的数据采集指标
Map<String, Object> map = fieldMap.get(factoryId);
if(map==null) {
continue;
}
Set<String> fieldSet=map.keySet();
String fields = "";
for(String key : fieldSet) {
fields = fields+","+((Map)map.get(key)).get("id");
}
if(!StringUtils.isEmpty(fields)) {
fields = fields.substring(1);
//获取厂站10分钟的数据,遍历数据,只要有一条预警了,后面数据均不参加预警计算
List<Map<String, Object>> dataList = factoryInfoService.queryFactoryInfos(factoryId, fields, sdf.format(afterDate), sdf.format(nowDate), "0");
List<Map<String, Object>> yesterdayHourList = factoryInfoService.queryFactoryInfos(factoryId, fields, yesterdayStart, yesterdayEnd, "1");
List<Map<String, Object>> yesterdayList = factoryInfoService.handleResult(yesterdayHourList, "d", fields);
List<Map<String, Object>> qtHourList = factoryInfoService.queryFactoryInfos(factoryId, fields, qtStart, qtEnd, "1");
List<Map<String, Object>> qtList = factoryInfoService.handleResult(qtHourList, "d", fields);
List<Map<String, Object>> dqtHourList = factoryInfoService.queryFactoryInfos(factoryId, fields, dqtStart, dqtEnd, "1");
List<Map<String, Object>> dqtList = factoryInfoService.handleResult(dqtHourList, "d", fields);
Map<String, Object> yesterdayMap = null;
if(yesterdayList!=null&&yesterdayList.size()>0) {
yesterdayMap = yesterdayList.get(0);
}
Map<String, Object> qtMap = null;
if(qtList!=null&&qtList.size()>0) {
qtMap = qtList.get(0);
}
Map<String, Object> dqtMap = null;
if(dqtList!=null&&dqtList.size()>0) {
dqtMap = dqtList.get(0);
}
//预警规则,获取采集频率时间段内的数据
for(Map<String,Object> dataMap : dataList) {
String time = DateUtils.formatDate(DateUtils.getDate(Long.valueOf(dataMap.get("time").toString()+"000")), "yyyy-MM-dd HH:mm:ss");
//处理实时数据
//温度
Map<String,Object> csswMap = (Map<String,Object>)map.get("CSSW");
if(csswMap!=null&&!warnRecordTagList.contains(factoryId+csswMap.get("id"))) {
double csswVal = ConvertUtils.getDouble(dataMap.get(csswMap.get("id")),-999);
double one_upper = ConvertUtils.getDouble(config.get("sw_one_s_wd"), 0.0);
double one_lower = ConvertUtils.getDouble(config.get("sw_one_x_wd"), 0.0);
if(csswVal>0&&csswVal<one_lower) {
StringBuffer csswWarnMessage = new StringBuffer();
csswWarnMessage.append(time+","+factory_name+"采集数据触发预警机制,");
csswWarnMessage.append("出水水温:瞬时值"+csswVal+ConvertUtils.getString(csswMap.get("metric_unit"))+"小于阈值"+one_lower+",");
csswWarnMessage.append("请尽快处理。");
executeSql(masterDB,warnRecordTagList,factoryId,csswWarnMessage.toString(),time,csswMap);
}
if((csswVal>one_upper&&csswVal<50)) {
StringBuffer csswWarnMessage = new StringBuffer();
csswWarnMessage.append(time+","+factory_name+"采集数据触发预警机制,");
csswWarnMessage.append("出水水温:瞬时值"+csswVal+ConvertUtils.getString(csswMap.get("metric_unit"))+"大于阈值"+one_upper+",");
csswWarnMessage.append("请尽快处理。");
executeSql(masterDB,warnRecordTagList,factoryId,csswWarnMessage.toString(),time,csswMap);
}
}
//cod
//获取出水cod的实时值
Map<String,Object> codMap = (Map<String,Object>)map.get("CSCOD");
if(codMap!=null&&!warnRecordTagList.contains(factoryId+codMap.get("id"))) {
//如果预警存在未处理的情况则不进行预警插入
double codVal = ConvertUtils.getDouble(dataMap.get(codMap.get("id")),-999);
if(codVal == -999) {
log.info("cod数据采集断线");
}else {
StringBuffer codWarnMessage = new StringBuffer();
codWarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
boolean codWarnTag = false;
//判断规则1
double one_upper = ConvertUtils.getDouble(config.get("cod_one_"+out_level+"_ssz"), 0.0);
double one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_cod"), 0.0);
if(codVal>one_upper&&codVal<one_alarm_upper) {
codWarnTag = true;
codWarnMessage.append("出水COD:瞬时值"+codVal+ConvertUtils.getString(codMap.get("metric_unit"))+"大于阈值"+one_upper+",");
}
//判断规则2
double second_upper = ConvertUtils.getDouble(config.get("cod_second_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0) {
double rjz = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")+"_tag"), 1), 2);
double diffVal = codVal - rjz;
if(diffVal>second_upper) {
codWarnTag = true;
codWarnMessage.append("出水COD:瞬时值【"+codVal+"】-昨日日均值【"+rjz+"】="+diffVal+ConvertUtils.getString(codMap.get("metric_unit"))+"大于阈值"+second_upper+",");
}
}
//判断规则3
double three_rjz_upper = ConvertUtils.getDouble(config.get("cod_three_rjz"), 0.0);
double three_ssz_upper = ConvertUtils.getDouble(config.get("cod_three_"+out_level+"_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(codMap.get("id")+"_tag"), 1), 2);
double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(codMap.get("id")+"_tag"), 1), 2);
double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(codMap.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(codMap.get("id")+"_tag"), 1), 2);
if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&codVal>three_ssz_upper) {
codWarnTag = true;
codWarnMessage.append("出水COD:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+codVal+ConvertUtils.getString(codMap.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
}
}
//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
if(codWarnTag) {
codWarnMessage.append("请尽快处理。");
executeSql(masterDB,warnRecordTagList,factoryId,codWarnMessage.toString(),time,codMap);
}
}
}
//获取出水氨氮的实时值
Map<String,Object> nh3Map = (Map<String,Object>)map.get("CSNH3N");
if(nh3Map!=null&&!warnRecordTagList.contains(factoryId+nh3Map.get("id"))) {
double nh3Val = ConvertUtils.getDouble(dataMap.get(nh3Map.get("id")),-999);
Map<String,Object> swMap = (Map<String,Object>)map.get("CSSW");
double swVal = 13;
if(swMap!=null&&swMap.size()>0) {
swVal = ConvertUtils.getDouble(dataMap.get(swMap.get("id")),13);
}
//获取水温
if(nh3Val == -999) {
log.info("氨氮数据采集断线");
}else {
StringBuffer nh3WarnMessage = new StringBuffer();
nh3WarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
boolean nh3WarnTag = false;
//判断规则1
double one_upper = 0;
double one_alarm_upper = 0;
if(swVal>12) {
one_upper = ConvertUtils.getDouble(config.get("nh3_one_"+out_level+"_12s_ssz"), 0.0);
one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_nh3_12s"), 0.0);
}else {
one_upper = ConvertUtils.getDouble(config.get("nh3_one_"+out_level+"_12x_ssz"), 0.0);
one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_nh3_12x"), 0.0);
}
if(nh3Val>one_upper&&nh3Val<one_alarm_upper) {
nh3WarnMessage.append("出水氨氮:瞬时值"+nh3Val+ConvertUtils.getString(nh3Map.get("metric_unit"))+"大于阈值"+one_upper+",");
nh3WarnTag = true;
}
//判断规则2
double second_upper = ConvertUtils.getDouble(config.get("nh3_second_"+out_level+"_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0) {
double rjz = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")+"_tag"), 1), 2);
double diffVal = nh3Val - rjz;
if(diffVal>second_upper) {
nh3WarnMessage.append("出水氨氮:瞬时值【"+nh3Val+"】-昨日日均值【"+rjz+"】="+diffVal+ConvertUtils.getString(nh3Map.get("metric_unit"))+"大于阈值"+second_upper+",");
nh3WarnTag = true;
}
}
//判断规则3
double three_rjz_upper = ConvertUtils.getDouble(config.get("nh3_three_rjz"), 0.0);
double three_ssz_upper = ConvertUtils.getDouble(config.get("nh3_three_"+out_level+"_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(nh3Map.get("id")+"_tag"), 1), 2);
double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(nh3Map.get("id")+"_tag"), 1), 2);
double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(nh3Map.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(nh3Map.get("id")+"_tag"), 1), 2);
if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&nh3Val>three_ssz_upper) {
nh3WarnMessage.append("出水氨氮:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+nh3Val+ConvertUtils.getString(nh3Map.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
nh3WarnTag = true;
}
}
//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
if(nh3WarnTag) {
nh3WarnMessage.append("请尽快处理。");
executeSql(masterDB,warnRecordTagList,factoryId,nh3WarnMessage.toString(),time,nh3Map);
}
}
}
//总磷
//获取出水总磷的实时值
Map<String,Object> tpMap = (Map<String,Object>)map.get("CSTP");
if(tpMap!=null&&!warnRecordTagList.contains(factoryId+tpMap.get("id"))) {
double tpVal = ConvertUtils.getDouble(dataMap.get(tpMap.get("id")),-999);
if(tpVal == -999) {
log.info("总磷数据采集断线");
}else {
StringBuffer tpWarnMessage = new StringBuffer();
tpWarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
boolean tpWarnTag = false;
//判断规则1
double one_upper = ConvertUtils.getDouble(config.get("tp_one_"+out_level+"_ssz"), 0.0);
double one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_tp"), 0.0);
if(tpVal>one_upper&&tpVal<one_alarm_upper) {
tpWarnMessage.append("出水总磷:瞬时值"+tpVal+ConvertUtils.getString(tpMap.get("metric_unit"))+"大于阈值"+one_upper+",");
tpWarnTag = true;
}
//判断规则3
double three_rjz_upper = ConvertUtils.getDouble(config.get("tp_three_rjz"), 0.0);
double three_ssz_upper = ConvertUtils.getDouble(config.get("tp_three_"+out_level+"_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(tpMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(tpMap.get("id")+"_tag"), 1), 2);
double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(tpMap.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(tpMap.get("id")+"_tag"), 1), 2);
double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(tpMap.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(tpMap.get("id")+"_tag"), 1), 2);
if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&tpVal>three_ssz_upper) {
tpWarnMessage.append("出水总磷:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+tpVal+ConvertUtils.getString(tpMap.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
tpWarnTag = true;
}
}
//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
if(tpWarnTag) {
tpWarnMessage.append("请尽快处理。");
executeSql(masterDB,warnRecordTagList,factoryId,tpWarnMessage.toString(),time,tpMap);
}
}
}
//总氮
//获取出水总氮的实时值
Map<String,Object> tnMap = (Map<String,Object>)map.get("CSTN");
if(tnMap!=null&&!warnRecordTagList.contains(factoryId+tnMap.get("id"))) {
double tnVal = ConvertUtils.getDouble(dataMap.get(tnMap.get("id")),-999);
if(tnVal == -999) {
log.info("总氮数据采集断线");
}else {
StringBuffer tnWarnMessage = new StringBuffer();
tnWarnMessage.append(""+time+","+factory_name+"采集数据触发预警机制,");
boolean tnWarnTag = false;
//判断规则1
double one_upper = ConvertUtils.getDouble(config.get("tn_one_"+out_level+"_ssz"), 0.0);
double one_alarm_upper = ConvertUtils.getDouble(outLevelMap.get(out_level+"_tn"), 0.0);
if(tnVal>one_upper&&tnVal<one_alarm_upper) {
tnWarnMessage.append("出水总氮:瞬时值"+tnVal+ConvertUtils.getString(tnMap.get("metric_unit"))+"大于阈值"+one_upper+",");
tnWarnTag = true;
}
//判断规则2
double second_upper = ConvertUtils.getDouble(config.get("tn_second_"+out_level+"_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0) {
double rjz = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")+"_tag"), 1), 2);
double diffVal = tnVal - rjz;
if(diffVal>second_upper) {
tnWarnMessage.append("出水总氮:瞬时值【"+tnVal+"】-昨日日均值【"+rjz+"】="+diffVal+ConvertUtils.getString(tnMap.get("metric_unit"))+"大于阈值"+second_upper+",");
tnWarnTag = true;
}
}
//判断规则3
double three_rjz_upper = ConvertUtils.getDouble(config.get("tn_three_rjz"), 0.0);
double three_ssz_upper = ConvertUtils.getDouble(config.get("tn_three_"+out_level+"_ssz"), 0.0);
if(yesterdayMap!=null&&yesterdayMap.size()>0&&qtMap!=null&&qtMap.size()>0&&dqtMap!=null&&dqtMap.size()>0) {
double yesDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(yesterdayMap.get(tnMap.get("id")+"_tag"), 1), 2);
double qtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(qtMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(qtMap.get(tnMap.get("id")+"_tag"), 1), 2);
double dqtDiffVal = DoubleOperaUtils.bigDecimalRound(ConvertUtils.getDouble(dqtMap.get(tnMap.get("id")), 0.0)/ConvertUtils.getDouble(dqtMap.get(tnMap.get("id")+"_tag"), 1), 2);
if(((yesDiffVal-qtDiffVal)/qtDiffVal*100)>three_rjz_upper&&((qtDiffVal-dqtDiffVal)/dqtDiffVal*100)>three_rjz_upper&&tnVal>three_ssz_upper) {
tnWarnMessage.append("出水总氮:日均值连续两天上涨大于"+three_rjz_upper+"%,且瞬时值"+tnVal+ConvertUtils.getString(tnMap.get("metric_unit"))+"大于阈值"+three_ssz_upper+",");
tnWarnTag = true;
}
}
//预警入库操作,判断条件,如果该指标未处理,则不进行数据插入
if(tnWarnTag) {
tnWarnMessage.append("请尽快处理。");
executeSql(masterDB,warnRecordTagList,factoryId,tnWarnMessage.toString(),time,tnMap);
}
}
}
}
}
}
System.out.println("********预警监测定时服务结束********");
}
/**
* <pre>
* 预警插入逻辑
* </pre>
* @param masterDB
* @param warnRecordTagList
* @param factoryId
* @param warnMessage
* @param time
* @param fieldMap
* @author Li Yuanyuan, 2021年3月23日 下午3:31:17
*/
public void executeSql(JdbcTemplate masterDB,List<String> warnRecordTagList,String factoryId,String warnMessage,String time,Map<String,Object> fieldMap) {
String sql="insert into alarm_warning_record_history(id,alarm_param_code,alarm_param_name,alarm_param_unit,factory_id,record_time,handle_status,alarm_content,create_time)VALUES('"+sequenceService.nextId()+"','"+fieldMap.get("id")+"','"+fieldMap.get("metric_name")+"','"+ConvertUtils.getString(fieldMap.get("metric_unit"))+"','"+factoryId+"','"+time+"','0','"+warnMessage+"','"+DateUtils.now()+"')";
masterDB.execute(sql);
warnRecordTagList.add(factoryId+fieldMap.get("id"));
}
}