|
@@ -52,6 +52,13 @@ public class LiveDataTask {
|
|
|
|
|
|
|
|
//获取异步结果
|
|
//获取异步结果
|
|
|
//处理安监平台数据
|
|
//处理安监平台数据
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 8小时内只生成1条告警信息
|
|
|
|
|
+ * 实时数据和历史数据不需要全部记录,相同值只记录开始点和结束点
|
|
|
|
|
+ * @param liveData
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Future<String> alarmTask(String liveData) {
|
|
public Future<String> alarmTask(String liveData) {
|
|
|
try {
|
|
try {
|
|
@@ -70,12 +77,12 @@ public class LiveDataTask {
|
|
|
// + oldData[9] + ":" + oldData[10];// 上报时间
|
|
// + oldData[9] + ":" + oldData[10];// 上报时间
|
|
|
String deviceId = oldData[4];//设备编号
|
|
String deviceId = oldData[4];//设备编号
|
|
|
int len = Integer.parseInt(oldData[11]);
|
|
int len = Integer.parseInt(oldData[11]);
|
|
|
- //根据设备id获取设备信息
|
|
|
|
|
- DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
|
|
- String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
|
|
- String endTime = deviceInfo.getWorkTimeTo();
|
|
|
|
|
- SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
|
|
|
- String now = sf.format(new Date());//获取当前时间
|
|
|
|
|
|
|
+// //根据设备id获取设备信息
|
|
|
|
|
+// DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
|
|
+// String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
|
|
+// String endTime = deviceInfo.getWorkTimeTo();
|
|
|
|
|
+// SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
|
|
|
+// String now = sf.format(new Date());//获取当前时间
|
|
|
for (int i = 0; i < len; i++) {
|
|
for (int i = 0; i < len; i++) {
|
|
|
String seq = oldData[12 + 6 * i] + oldData[13 + 6 * i];// 设备类型+编号(传感器编号)
|
|
String seq = oldData[12 + 6 * i] + oldData[13 + 6 * i];// 设备类型+编号(传感器编号)
|
|
|
String str = oldData[14 + 6 * i];// 03 第一位0正数 1负数;第二位表示有几位小数
|
|
String str = oldData[14 + 6 * i];// 03 第一位0正数 1负数;第二位表示有几位小数
|
|
@@ -98,35 +105,35 @@ public class LiveDataTask {
|
|
|
data1.setSensorId(seq);
|
|
data1.setSensorId(seq);
|
|
|
data1.setDataValue(val);
|
|
data1.setDataValue(val);
|
|
|
//如果当前时间在工作范围内,判断异常以及推送。如果不在工作时间段,则标记数据
|
|
//如果当前时间在工作范围内,判断异常以及推送。如果不在工作时间段,则标记数据
|
|
|
- if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
|
|
- 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
|
|
|
|
|
|
|
+// if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
|
|
+ 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());
|
|
@@ -147,34 +154,15 @@ 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
|
|
|
|
|
-// 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.save(event);
|
|
|
|
|
- data.setStatus(2);
|
|
|
|
|
- data1.setStatus(2);
|
|
|
|
|
- }
|
|
|
|
|
- if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
|
|
|
|
|
+ data.setStatus(1);
|
|
|
|
|
+ data1.setStatus(1);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
|
|
|
+
|
|
|
|
|
+ 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());
|
|
@@ -195,10 +183,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());
|
|
@@ -219,10 +207,10 @@ 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);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ data.setStatus(4);
|
|
|
|
|
+ data1.setStatus(4);
|
|
|
}
|
|
}
|
|
|
|
|
+// }
|
|
|
} else {
|
|
} else {
|
|
|
data.setStatus(5);
|
|
data.setStatus(5);
|
|
|
data1.setStatus(5);
|
|
data1.setStatus(5);
|