|
@@ -386,6 +386,9 @@ public class LiveDataTask {
|
|
|
* "s12": "0"
|
|
* "s12": "0"
|
|
|
* }
|
|
* }
|
|
|
* }
|
|
* }
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 1.现在系统中新增设备信息、传感器编号
|
|
|
|
|
+ * 2.现根据设备编号从数据库里获取传感器编号,然后根据传感器编号存数据、判断阈值
|
|
|
*
|
|
*
|
|
|
* @param liveData
|
|
* @param liveData
|
|
|
* @return
|
|
* @return
|
|
@@ -398,19 +401,19 @@ public class LiveDataTask {
|
|
|
String deviceId = deviceData.get("deviceId");//获取设备编号
|
|
String deviceId = deviceData.get("deviceId");//获取设备编号
|
|
|
DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
if (deviceInfo != null) {
|
|
if (deviceInfo != null) {
|
|
|
- String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
|
|
- String endTime = deviceInfo.getWorkTimeTo();
|
|
|
|
|
|
|
+ List<String> sensorIds = sensorInfoService.getAllSensorIdByDeviceId(deviceId);//获取该设备下的所有传感器编号
|
|
|
|
|
+// String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
|
|
+// 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());//获取当前时间
|
|
|
Date nowDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(reportTime);
|
|
Date nowDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(reportTime);
|
|
|
//如果未设置时间或者当前时间在工作范围内
|
|
//如果未设置时间或者当前时间在工作范围内
|
|
|
- if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
|
|
// int count = sensorInfoService.getSensorCount(deviceId);//获取该设备下的传感器数量
|
|
// int count = sensorInfoService.getSensorCount(deviceId);//获取该设备下的传感器数量
|
|
|
// 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) + "");
|
|
|
|
|
|
|
+ for (String seq : sensorIds) {//遍历传感器
|
|
|
|
|
+ double val = Double.valueOf(deviceData.get(seq));
|
|
|
LiveData data = new LiveData();
|
|
LiveData data = new LiveData();
|
|
|
data.setDeviceId(deviceId);
|
|
data.setDeviceId(deviceId);
|
|
|
data.setReportTime(reportTime);
|
|
data.setReportTime(reportTime);
|
|
@@ -421,9 +424,9 @@ public class LiveDataTask {
|
|
|
data1.setReportTime(reportTime);
|
|
data1.setReportTime(reportTime);
|
|
|
data1.setSensorId(seq);
|
|
data1.setSensorId(seq);
|
|
|
data1.setDataValue(val);
|
|
data1.setDataValue(val);
|
|
|
-// String dateTime = (String) liveData.get("CreateDataTime");
|
|
|
|
|
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);
|
|
@@ -450,112 +453,177 @@ 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(0);
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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
|
|
|
-// 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);
|
|
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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(0);
|
|
|
|
|
+ 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(0);
|
|
data.setStatus(0);
|
|
|
data1.setStatus(0);
|
|
data1.setStatus(0);
|
|
|
}
|
|
}
|
|
|
- liveDataService.acceptLiveData(data);
|
|
|
|
|
- historyDataService.save(data1);
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// }
|
|
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|