|
@@ -27,7 +27,7 @@ import java.util.concurrent.Future;
|
|
|
* 实时数据异步处理
|
|
* 实时数据异步处理
|
|
|
* 1.告警规则判断
|
|
* 1.告警规则判断
|
|
|
* 2.存储数据到数据库
|
|
* 2.存储数据到数据库
|
|
|
- * 3.如有告警,推送告警并且存入告警事件表
|
|
|
|
|
|
|
+ * 3.如有告警,推送告警并且存入告警事件表,8小时内同一设备(传感器)只生成一条告警信息,如果告警级别升级,则再次推送
|
|
|
*/
|
|
*/
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
@Component
|
|
@Component
|
|
@@ -51,7 +51,7 @@ public class LiveDataTask {
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取异步结果
|
|
//获取异步结果
|
|
|
- //处理案件平台数据
|
|
|
|
|
|
|
+ //处理安监平台数据
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Future<String> alarmTask(String liveData) {
|
|
public Future<String> alarmTask(String liveData) {
|
|
|
try {
|
|
try {
|
|
@@ -76,29 +76,29 @@ public class LiveDataTask {
|
|
|
String endTime = deviceInfo.getWorkTimeTo();
|
|
String endTime = deviceInfo.getWorkTimeTo();
|
|
|
SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
|
String now = sf.format(new Date());//获取当前时间
|
|
String now = sf.format(new Date());//获取当前时间
|
|
|
- //如果未设置时间或者当前时间在工作范围内
|
|
|
|
|
- if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
|
|
- for (int i = 0; i < len; i++) {
|
|
|
|
|
- String seq = oldData[12 + 6 * i] + oldData[13 + 6 * i];// 设备类型+编号(传感器编号)
|
|
|
|
|
- String str = oldData[14 + 6 * i];// 03 第一位0正数 1负数;第二位表示有几位小数
|
|
|
|
|
- String num = str.substring(0, 1);
|
|
|
|
|
- String num2 = str.substring(1, 2);
|
|
|
|
|
- String value = oldData[15 + 6 * i] + oldData[16 + 6 * i] + oldData[17 + 6 * i];// 对应参数值 00 00 68
|
|
|
|
|
- double val = Double.parseDouble(value.substring(0, (value.length() - Integer.parseInt(num2))) + "."
|
|
|
|
|
- + value.substring((value.length() - Integer.parseInt(num2)), value.length()));
|
|
|
|
|
- if ("1".equals(num)) {
|
|
|
|
|
- val = -val;
|
|
|
|
|
- }
|
|
|
|
|
- LiveData data = new LiveData();
|
|
|
|
|
- data.setDeviceId(deviceId);
|
|
|
|
|
- data.setReportTime(reportTime);
|
|
|
|
|
- data.setSensorId(seq);
|
|
|
|
|
- data.setDataValue(val);
|
|
|
|
|
- HistoryData data1 = new HistoryData();
|
|
|
|
|
- data1.setDeviceId(deviceId);
|
|
|
|
|
- data1.setReportTime(reportTime);
|
|
|
|
|
- data1.setSensorId(seq);
|
|
|
|
|
- data1.setDataValue(val);
|
|
|
|
|
|
|
+ for (int i = 0; i < len; i++) {
|
|
|
|
|
+ String seq = oldData[12 + 6 * i] + oldData[13 + 6 * i];// 设备类型+编号(传感器编号)
|
|
|
|
|
+ String str = oldData[14 + 6 * i];// 03 第一位0正数 1负数;第二位表示有几位小数
|
|
|
|
|
+ String num = str.substring(0, 1);
|
|
|
|
|
+ String num2 = str.substring(1, 2);
|
|
|
|
|
+ String value = oldData[15 + 6 * i] + oldData[16 + 6 * i] + oldData[17 + 6 * i];// 对应参数值 00 00 68
|
|
|
|
|
+ double val = Double.parseDouble(value.substring(0, (value.length() - Integer.parseInt(num2))) + "."
|
|
|
|
|
+ + value.substring((value.length() - Integer.parseInt(num2)), value.length()));
|
|
|
|
|
+ if ("1".equals(num)) {
|
|
|
|
|
+ val = -val;
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveData data = new LiveData();
|
|
|
|
|
+ data.setDeviceId(deviceId);
|
|
|
|
|
+ data.setReportTime(reportTime);
|
|
|
|
|
+ data.setSensorId(seq);
|
|
|
|
|
+ data.setDataValue(val);
|
|
|
|
|
+ HistoryData data1 = new HistoryData();
|
|
|
|
|
+ data1.setDeviceId(deviceId);
|
|
|
|
|
+ data1.setReportTime(reportTime);
|
|
|
|
|
+ data1.setSensorId(seq);
|
|
|
|
|
+ data1.setDataValue(val);
|
|
|
|
|
+ //如果当前时间在工作范围内,判断异常以及推送。如果不在工作时间段,则标记数据
|
|
|
|
|
+ if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
|
|
List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
|
|
|
SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
|
|
SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
|
|
|
if (thresholds.size() > 0) {
|
|
if (thresholds.size() > 0) {
|
|
@@ -222,14 +222,14 @@ public class LiveDataTask {
|
|
|
data.setStatus(4);
|
|
data.setStatus(4);
|
|
|
data1.setStatus(4);
|
|
data1.setStatus(4);
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- data.setStatus(0);
|
|
|
|
|
- data1.setStatus(0);
|
|
|
|
|
}
|
|
}
|
|
|
- liveDataService.acceptLiveData(data);
|
|
|
|
|
- historyDataService.save(data1);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ data.setStatus(5);
|
|
|
|
|
+ data1.setStatus(5);
|
|
|
}
|
|
}
|
|
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
|
|
+ historyDataService.save(data1);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error(e.getMessage());
|
|
log.error(e.getMessage());
|
|
@@ -332,47 +332,47 @@ public class LiveDataTask {
|
|
|
// if (count > 0) {
|
|
// if (count > 0) {
|
|
|
// for (int i = 0; i < count; i++) {//循环插入数据库
|
|
// for (int i = 0; i < count; i++) {//循环插入数据库
|
|
|
// String seq = "m" + (i + 1);//传感器编号
|
|
// String seq = "m" + (i + 1);//传感器编号
|
|
|
- String seq = "m1";//传感器编号
|
|
|
|
|
- double val = Double.valueOf(deviceData.get(seq) + "");
|
|
|
|
|
- LiveData data = new LiveData();
|
|
|
|
|
- data.setDeviceId(deviceId);
|
|
|
|
|
- data.setReportTime(reportTime);
|
|
|
|
|
- data.setSensorId(seq);
|
|
|
|
|
- data.setDataValue(val);
|
|
|
|
|
- HistoryData data1 = new HistoryData();
|
|
|
|
|
- data1.setDeviceId(deviceId);
|
|
|
|
|
- data1.setReportTime(reportTime);
|
|
|
|
|
- data1.setSensorId(seq);
|
|
|
|
|
- data1.setDataValue(val);
|
|
|
|
|
|
|
+ String seq = "m1";//传感器编号
|
|
|
|
|
+ double val = Double.valueOf(deviceData.get(seq) + "");
|
|
|
|
|
+ LiveData data = new LiveData();
|
|
|
|
|
+ data.setDeviceId(deviceId);
|
|
|
|
|
+ data.setReportTime(reportTime);
|
|
|
|
|
+ data.setSensorId(seq);
|
|
|
|
|
+ data.setDataValue(val);
|
|
|
|
|
+ HistoryData data1 = new HistoryData();
|
|
|
|
|
+ data1.setDeviceId(deviceId);
|
|
|
|
|
+ data1.setReportTime(reportTime);
|
|
|
|
|
+ data1.setSensorId(seq);
|
|
|
|
|
+ data1.setDataValue(val);
|
|
|
// String dateTime = (String) liveData.get("CreateDataTime");
|
|
// String dateTime = (String) liveData.get("CreateDataTime");
|
|
|
- List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
|
|
|
|
|
- SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
|
|
|
|
|
- if (thresholds.size() > 0) {
|
|
|
|
|
- //code:0
|
|
|
|
|
- DeviceThreshold thresholds_0 = thresholds.get(0);
|
|
|
|
|
- double low_0 = thresholds_0.getLowValue();
|
|
|
|
|
- double high_0 = thresholds_0.getHighValue();
|
|
|
|
|
- //code:1
|
|
|
|
|
- DeviceThreshold thresholds_1 = thresholds.get(1);
|
|
|
|
|
- double low_1 = thresholds_1.getLowValue();
|
|
|
|
|
- double high_1 = thresholds_1.getHighValue();
|
|
|
|
|
- //code:2
|
|
|
|
|
- DeviceThreshold thresholds_2 = thresholds.get(2);
|
|
|
|
|
- double low_2 = thresholds_2.getLowValue();
|
|
|
|
|
- double high_2 = thresholds_2.getHighValue();
|
|
|
|
|
- //code:3
|
|
|
|
|
- DeviceThreshold thresholds_3 = thresholds.get(3);
|
|
|
|
|
- double low_3 = thresholds_3.getLowValue();
|
|
|
|
|
- double high_3 = thresholds_3.getHighValue();
|
|
|
|
|
- //code:4
|
|
|
|
|
- DeviceThreshold thresholds_4 = thresholds.get(4);
|
|
|
|
|
- double low_4 = thresholds_4.getLowValue();
|
|
|
|
|
- double high_4 = thresholds_4.getHighValue();
|
|
|
|
|
- if (val >= low_0 && val <= high_0) {//状态0
|
|
|
|
|
- data.setStatus(0);
|
|
|
|
|
- data1.setStatus(0);
|
|
|
|
|
- }
|
|
|
|
|
- if ((val < low_0 && val >= low_1) || (val > high_0 && val <= high_1)) {//状态1
|
|
|
|
|
|
|
+ List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
|
|
|
|
|
+ SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
|
|
|
|
|
+ if (thresholds.size() > 0) {
|
|
|
|
|
+ //code:0
|
|
|
|
|
+ DeviceThreshold thresholds_0 = thresholds.get(0);
|
|
|
|
|
+ double low_0 = thresholds_0.getLowValue();
|
|
|
|
|
+ double high_0 = thresholds_0.getHighValue();
|
|
|
|
|
+ //code:1
|
|
|
|
|
+ DeviceThreshold thresholds_1 = thresholds.get(1);
|
|
|
|
|
+ double low_1 = thresholds_1.getLowValue();
|
|
|
|
|
+ double high_1 = thresholds_1.getHighValue();
|
|
|
|
|
+ //code:2
|
|
|
|
|
+ DeviceThreshold thresholds_2 = thresholds.get(2);
|
|
|
|
|
+ double low_2 = thresholds_2.getLowValue();
|
|
|
|
|
+ double high_2 = thresholds_2.getHighValue();
|
|
|
|
|
+ //code:3
|
|
|
|
|
+ DeviceThreshold thresholds_3 = thresholds.get(3);
|
|
|
|
|
+ double low_3 = thresholds_3.getLowValue();
|
|
|
|
|
+ double high_3 = thresholds_3.getHighValue();
|
|
|
|
|
+ //code:4
|
|
|
|
|
+ DeviceThreshold thresholds_4 = thresholds.get(4);
|
|
|
|
|
+ double low_4 = thresholds_4.getLowValue();
|
|
|
|
|
+ double high_4 = thresholds_4.getHighValue();
|
|
|
|
|
+ if (val >= low_0 && val <= high_0) {//状态0
|
|
|
|
|
+ data.setStatus(0);
|
|
|
|
|
+ data1.setStatus(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((val < low_0 && val >= low_1) || (val > high_0 && val <= high_1)) {//状态1
|
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
|
// alarm.setToken(token);
|
|
// alarm.setToken(token);
|
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
@@ -393,10 +393,10 @@ public class LiveDataTask {
|
|
|
// event.setIsreport(1);
|
|
// event.setIsreport(1);
|
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
|
// alarmEventService.save(event);
|
|
// alarmEventService.save(event);
|
|
|
- data.setStatus(1);
|
|
|
|
|
- data1.setStatus(1);
|
|
|
|
|
- }
|
|
|
|
|
- if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
|
|
|
|
|
+ data.setStatus(1);
|
|
|
|
|
+ data1.setStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
|
// alarm.setToken(token);
|
|
// alarm.setToken(token);
|
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
@@ -417,10 +417,10 @@ public class LiveDataTask {
|
|
|
// event.setIsreport(1);
|
|
// event.setIsreport(1);
|
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
|
// alarmEventService.save(event);
|
|
// alarmEventService.save(event);
|
|
|
- data.setStatus(2);
|
|
|
|
|
- data1.setStatus(2);
|
|
|
|
|
- }
|
|
|
|
|
- if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
|
|
|
|
|
+ data.setStatus(2);
|
|
|
|
|
+ data1.setStatus(2);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
|
// alarm.setToken(token);
|
|
// alarm.setToken(token);
|
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
@@ -441,10 +441,10 @@ public class LiveDataTask {
|
|
|
// event.setIsreport(1);
|
|
// event.setIsreport(1);
|
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
|
// alarmEventService.save(event);
|
|
// alarmEventService.save(event);
|
|
|
- data.setStatus(3);
|
|
|
|
|
- data1.setStatus(3);
|
|
|
|
|
- }
|
|
|
|
|
- if ((val < low_3 && val >= low_4) || (val > high_3 && val <= high_4)) {//状态4
|
|
|
|
|
|
|
+ data.setStatus(3);
|
|
|
|
|
+ data1.setStatus(3);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((val < low_3 && val >= low_4) || (val > high_3 && val <= high_4)) {//状态4
|
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
// ServerAlarm alarm = new ServerAlarm();
|
|
|
// alarm.setToken(token);
|
|
// alarm.setToken(token);
|
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
@@ -465,16 +465,16 @@ public class LiveDataTask {
|
|
|
// event.setIsreport(1);
|
|
// event.setIsreport(1);
|
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
// event.setThirdPartyId(thirdPartyId);
|
|
|
// alarmEventService.save(event);
|
|
// alarmEventService.save(event);
|
|
|
- data.setStatus(4);
|
|
|
|
|
- data1.setStatus(4);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- data.setStatus(0);
|
|
|
|
|
- data1.setStatus(0);
|
|
|
|
|
- }
|
|
|
|
|
- liveDataService.acceptLiveData(data);
|
|
|
|
|
- historyDataService.save(data1);
|
|
|
|
|
|
|
+ data.setStatus(4);
|
|
|
|
|
+ data1.setStatus(4);
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ data.setStatus(0);
|
|
|
|
|
+ data1.setStatus(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
|
|
+ historyDataService.save(data1);
|
|
|
|
|
+ }
|
|
|
//
|
|
//
|
|
|
// }
|
|
// }
|
|
|
//
|
|
//
|