|
@@ -29,25 +29,24 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
if (sensorData == null) {
|
|
|
throw new IllegalArgumentException("传感器数据不能为空!");
|
|
|
}
|
|
|
-
|
|
|
// 获取传感器阈值配置
|
|
|
SensorThreshold threshold = thresholdService.getThresholdBySensorId(sensorData.getDeviceId(), sensorData.getRoads());
|
|
|
if (threshold == null) {
|
|
|
log.warn("没有找到设备 {} 的阈值配置", sensorData.getDeviceId());
|
|
|
return false;
|
|
|
}
|
|
|
+ final String deviceName = threshold.getMonitorTargetRegion().getDeviceName();
|
|
|
// 检查传感器数据并触发报警
|
|
|
boolean alarmTriggered = false;
|
|
|
if (sensorData.getTemperature() != null) {
|
|
|
- alarmTriggered = checkThreshold(sensorData.getTemperature(), threshold.getTemperatureUp(), threshold.getTemperatureDown(), "温度", sensorData);
|
|
|
+ alarmTriggered = checkThreshold(sensorData.getTemperature(), threshold.getTemperatureUp(), threshold.getTemperatureDown(), "温度", deviceName);
|
|
|
}
|
|
|
if (sensorData.getHumidity() != null) {
|
|
|
- alarmTriggered |= checkThreshold(sensorData.getHumidity(), threshold.getHumidityUp(), threshold.getHumidityDown(), "湿度", sensorData);
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getHumidity(), threshold.getHumidityUp(), threshold.getHumidityDown(), "湿度", deviceName);
|
|
|
}
|
|
|
if (sensorData.getCo2() != null) {
|
|
|
- alarmTriggered |= checkThreshold(sensorData.getCo2(), threshold.getCo2Up(), threshold.getCo2Down(), "二氧化碳", sensorData);
|
|
|
+ alarmTriggered |= checkThreshold(sensorData.getCo2(), threshold.getCo2Up(), threshold.getCo2Down(), "二氧化碳", deviceName);
|
|
|
}
|
|
|
-
|
|
|
return alarmTriggered;
|
|
|
}
|
|
|
|
|
@@ -58,12 +57,11 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
* @param upperThreshold 阈值上限
|
|
|
* @param lowerThreshold 阈值下限
|
|
|
* @param type 数据类型(温度、湿度、二氧化碳)
|
|
|
- * @param sensorData 传感器数据
|
|
|
+ * @param deviceName 设备名称
|
|
|
* @return 是否触发报警
|
|
|
*/
|
|
|
- private boolean checkThreshold(Float value, Float upperThreshold, Float lowerThreshold, String type, SensorData sensorData) {
|
|
|
+ private boolean checkThreshold(Float value, Float upperThreshold, Float lowerThreshold, String type, String deviceName) {
|
|
|
boolean alarmTriggered = false;
|
|
|
- String deviceName = "设备名称";
|
|
|
String time = DATE_FORMAT.format(new Date()); // 获取当前时间
|
|
|
String unit = getUnit(type);
|
|
|
if (value > upperThreshold) {
|
|
@@ -138,15 +136,11 @@ public class DefaultSensorAlarmChecker implements SensorAlarmChecker {
|
|
|
}
|
|
|
|
|
|
private String getUnit(String sensorType) {
|
|
|
- switch (sensorType) {
|
|
|
- case "温度":
|
|
|
- return "°C";
|
|
|
- case "湿度":
|
|
|
- return "%";
|
|
|
- case "二氧化碳":
|
|
|
- return "ppm";
|
|
|
- default:
|
|
|
- return "";
|
|
|
- }
|
|
|
+ return switch (sensorType) {
|
|
|
+ case "温度" -> "°C";
|
|
|
+ case "湿度" -> "%";
|
|
|
+ case "二氧化碳" -> "ppm";
|
|
|
+ default -> "";
|
|
|
+ };
|
|
|
}
|
|
|
}
|