|
@@ -56,6 +56,7 @@ public class LiveDataTask {
|
|
|
/**
|
|
/**
|
|
|
* 8小时内只生成1条告警信息
|
|
* 8小时内只生成1条告警信息
|
|
|
* 实时数据和历史数据不需要全部记录,相同值只记录开始点和结束点
|
|
* 实时数据和历史数据不需要全部记录,相同值只记录开始点和结束点
|
|
|
|
|
+ *
|
|
|
* @param liveData
|
|
* @param liveData
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
@@ -78,7 +79,7 @@ public class LiveDataTask {
|
|
|
String deviceId = oldData[4];//设备编号
|
|
String deviceId = oldData[4];//设备编号
|
|
|
int len = Integer.parseInt(oldData[11]);
|
|
int len = Integer.parseInt(oldData[11]);
|
|
|
// //根据设备id获取设备信息
|
|
// //根据设备id获取设备信息
|
|
|
-// DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
|
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
// String startTime = deviceInfo.getWorkTimeFrom();
|
|
// String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
// String endTime = deviceInfo.getWorkTimeTo();
|
|
// String endTime = deviceInfo.getWorkTimeTo();
|
|
|
// SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
// SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
@@ -108,6 +109,7 @@ public class LiveDataTask {
|
|
|
// if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
// 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);//获取传感器信息
|
|
|
|
|
+ AlarmEvent alarmEvent = alarmEventService.checkExist(deviceId, seq);//8小时内是否有告警信息,如果有,只更新,不推送
|
|
|
if (thresholds.size() > 0) {
|
|
if (thresholds.size() > 0) {
|
|
|
//code:0
|
|
//code:0
|
|
|
DeviceThreshold thresholds_0 = thresholds.get(0);
|
|
DeviceThreshold thresholds_0 = thresholds.get(0);
|
|
@@ -134,89 +136,176 @@ public class LiveDataTask {
|
|
|
data1.setStatus(0);
|
|
data1.setStatus(0);
|
|
|
}
|
|
}
|
|
|
if ((val < low_0 && val >= low_1) || (val > high_0 && val <= high_1)) {//状态1
|
|
if ((val < low_0 && val >= low_1) || (val > high_0 && val <= high_1)) {//状态1
|
|
|
-// ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
-// alarm.setToken(token);
|
|
|
|
|
-// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
-// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
-// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
-// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
-// alarm.setAlarmData(val + "");
|
|
|
|
|
-// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
-// alarm.setDataLevel(1 + "");
|
|
|
|
|
-// alarm.setAlarmTime(reportTime);
|
|
|
|
|
-// String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
-// AlarmEvent event = new AlarmEvent();
|
|
|
|
|
-// event.setDeviceId(deviceId);
|
|
|
|
|
-// event.setSensorId(seq);
|
|
|
|
|
-// event.setAlarmTime(nowDate);
|
|
|
|
|
-// event.setAlarmLevel(1 + "");
|
|
|
|
|
-// event.setEventStatus(1);
|
|
|
|
|
-// event.setIsreport(1);
|
|
|
|
|
-// event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
-// alarmEventService.save(event);
|
|
|
|
|
|
|
+ if (alarmEvent != null) {//不为空 更新数据
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(1 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
+ alarm.setToken(token);
|
|
|
|
|
+ alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
+ alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
+ alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
+ alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
+ alarm.setAlarmData(val + "");
|
|
|
|
|
+ alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
+ alarm.setDataLevel(1 + "");
|
|
|
|
|
+ alarm.setAlarmTime(reportTime);
|
|
|
|
|
+ String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(1 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
data.setStatus(1);
|
|
data.setStatus(1);
|
|
|
data1.setStatus(1);
|
|
data1.setStatus(1);
|
|
|
}
|
|
}
|
|
|
if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
|
-
|
|
|
|
|
|
|
+ if (alarmEvent != null && Integer.parseInt(alarmEvent.getAlarmLevel()) < 2) {//不为空并且告警级别低于当前 更新数据
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(2 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
+ alarm.setToken(token);
|
|
|
|
|
+ alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
+ alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
+ alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
+ alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
+ alarm.setAlarmData(val + "");
|
|
|
|
|
+ alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
+ alarm.setDataLevel(2 + "");
|
|
|
|
|
+ alarm.setAlarmTime(reportTime);
|
|
|
|
|
+ String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(2 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ }
|
|
|
data.setStatus(2);
|
|
data.setStatus(2);
|
|
|
data1.setStatus(2);
|
|
data1.setStatus(2);
|
|
|
}
|
|
}
|
|
|
if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
|
-// ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
-// alarm.setToken(token);
|
|
|
|
|
-// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
-// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
-// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
-// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
-// alarm.setAlarmData(val + "");
|
|
|
|
|
-// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
-// alarm.setDataLevel(3 + "");
|
|
|
|
|
-// alarm.setAlarmTime(reportTime);
|
|
|
|
|
-// String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
-// AlarmEvent event = new AlarmEvent();
|
|
|
|
|
-// event.setDeviceId(deviceId);
|
|
|
|
|
-// event.setSensorId(seq);
|
|
|
|
|
-// event.setAlarmTime(nowDate);
|
|
|
|
|
-// event.setAlarmLevel(3 + "");
|
|
|
|
|
-// event.setEventStatus(1);
|
|
|
|
|
-// event.setIsreport(1);
|
|
|
|
|
-// event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
-// alarmEventService.save(event);
|
|
|
|
|
|
|
+ if (alarmEvent != null && Integer.parseInt(alarmEvent.getAlarmLevel()) < 3) {//不为空并且告警级别低于当前 更新数据
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(3 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
+ alarm.setToken(token);
|
|
|
|
|
+ alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
+ alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
+ alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
+ alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
+ alarm.setAlarmData(val + "");
|
|
|
|
|
+ alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
+ alarm.setDataLevel(3 + "");
|
|
|
|
|
+ alarm.setAlarmTime(reportTime);
|
|
|
|
|
+ String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(3 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ }
|
|
|
data.setStatus(3);
|
|
data.setStatus(3);
|
|
|
data1.setStatus(3);
|
|
data1.setStatus(3);
|
|
|
}
|
|
}
|
|
|
if ((val < low_3 && val >= low_4) || (val > high_3 && val <= high_4)) {//状态4
|
|
if ((val < low_3 && val >= low_4) || (val > high_3 && val <= high_4)) {//状态4
|
|
|
-// ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
-// alarm.setToken(token);
|
|
|
|
|
-// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
-// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
-// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
-// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
-// alarm.setAlarmData(val + "");
|
|
|
|
|
-// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
-// alarm.setDataLevel(4 + "");
|
|
|
|
|
-// alarm.setAlarmTime(reportTime);
|
|
|
|
|
-// String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
-// AlarmEvent event = new AlarmEvent();
|
|
|
|
|
-// event.setDeviceId(deviceId);
|
|
|
|
|
-// event.setSensorId(seq);
|
|
|
|
|
-// event.setAlarmTime(nowDate);
|
|
|
|
|
-// event.setAlarmLevel(4 + "");
|
|
|
|
|
-// event.setEventStatus(1);
|
|
|
|
|
-// event.setIsreport(1);
|
|
|
|
|
-// event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
-// alarmEventService.save(event);
|
|
|
|
|
|
|
+ if (alarmEvent != null && Integer.parseInt(alarmEvent.getAlarmLevel()) < 4) {//不为空并且告警级别低于当前 更新数据
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(4 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ServerAlarm alarm = new ServerAlarm();
|
|
|
|
|
+ alarm.setToken(token);
|
|
|
|
|
+ alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
|
|
+ alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
|
|
+ alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
|
|
+ alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
|
|
+ alarm.setAlarmData(val + "");
|
|
|
|
|
+ alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
|
|
+ alarm.setDataLevel(4 + "");
|
|
|
|
|
+ alarm.setAlarmTime(reportTime);
|
|
|
|
|
+ String thirdPartyId = alarmPost(alarm);
|
|
|
|
|
+ AlarmEvent event = new AlarmEvent();
|
|
|
|
|
+ event.setDeviceId(deviceId);
|
|
|
|
|
+ event.setSensorId(seq);
|
|
|
|
|
+ event.setAlarmTime(nowDate);
|
|
|
|
|
+ event.setAlarmLevel(4 + "");
|
|
|
|
|
+ event.setEventStatus(1);
|
|
|
|
|
+ event.setIsreport(1);
|
|
|
|
|
+ event.setThirdPartyId(thirdPartyId);
|
|
|
|
|
+ alarmEventService.generateAlarmEvent(event);
|
|
|
|
|
+ }
|
|
|
data.setStatus(4);
|
|
data.setStatus(4);
|
|
|
data1.setStatus(4);
|
|
data1.setStatus(4);
|
|
|
}
|
|
}
|
|
|
// }
|
|
// }
|
|
|
} else {
|
|
} else {
|
|
|
- data.setStatus(5);
|
|
|
|
|
- data1.setStatus(5);
|
|
|
|
|
|
|
+ data.setStatus(0);
|
|
|
|
|
+ data1.setStatus(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ LiveData ld = liveDataService.checkExist(deviceId, seq);//检查是否有数据,如果有检查跟上次是否相同,相同则不保存,不同则保存两个数据,当前值和上一次值
|
|
|
|
|
+ if (ld != null) {//如果有数据
|
|
|
|
|
+ //判断是否相同,相同只更新实时数据表,不存历史数据,不相同需要判断两种情况:1.上一次值与上上次值是否相同,是则保存上次数据与最新数据,否则只保存最新数据
|
|
|
|
|
+ if (val == ld.getDataValue()) {
|
|
|
|
|
+ data.setEqual(1);
|
|
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
|
|
+ } else if (ld.getEqual() == 1) {//上一次值与上上次值相同,保存上一次数据和最新数据到历史数据表中,同时更新最新实时数据
|
|
|
|
|
+ data.setEqual(0);
|
|
|
|
|
+ HistoryData lhd = new HistoryData();
|
|
|
|
|
+ lhd.setDeviceId(ld.getDeviceId());
|
|
|
|
|
+ lhd.setReportTime(ld.getReportTime());
|
|
|
|
|
+ lhd.setSensorId(ld.getSensorId());
|
|
|
|
|
+ lhd.setDataValue(ld.getDataValue());
|
|
|
|
|
+ lhd.setStatus(ld.getStatus());
|
|
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
|
|
+ historyDataService.save(lhd);
|
|
|
|
|
+ historyDataService.save(data1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
|
|
+ historyDataService.save(data1);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
|
|
+ historyDataService.save(data1);
|
|
|
}
|
|
}
|
|
|
- liveDataService.acceptLiveData(data);
|
|
|
|
|
- historyDataService.save(data1);
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|