|
|
|
@ -62,6 +62,9 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
MONITOR_FIELD_TO_DB_FIELD.put(3L, "vibration_displacement"); // 振动-位移(um)
|
|
|
|
|
MONITOR_FIELD_TO_DB_FIELD.put(4L, "vibration_acceleration"); // 振动-加速度(g)
|
|
|
|
|
MONITOR_FIELD_TO_DB_FIELD.put(5L, "vibration_temp"); // 振动-温度(℃)
|
|
|
|
|
MONITOR_FIELD_TO_DB_FIELD.put(6L, "noise"); // 噪音
|
|
|
|
|
MONITOR_FIELD_TO_DB_FIELD.put(7L, "illuminance"); // 照度
|
|
|
|
|
MONITOR_FIELD_TO_DB_FIELD.put(8L, "concentration"); // 气体浓度
|
|
|
|
|
|
|
|
|
|
// 字典值 -> 中文描述映射(用于异常记录的cause字段)
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(0L, "温度");
|
|
|
|
@ -70,6 +73,9 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(3L, "振动-位移(um)");
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(4L, "振动-加速度(g)");
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(5L, "振动-温度(℃)");
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(6L, "噪音");
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(7L, "照度");
|
|
|
|
|
MONITOR_FIELD_TO_DESC.put(8L, "气体浓度");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -395,6 +401,12 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
return record.getVibrationAcceleration();
|
|
|
|
|
case 5: // 振动-温度(℃)
|
|
|
|
|
return record.getVibrationTemp();
|
|
|
|
|
case 6: // 噪音
|
|
|
|
|
return record.getNoise();
|
|
|
|
|
case 7: // 照度
|
|
|
|
|
return record.getIlluminance();
|
|
|
|
|
case 8: // 气体浓度
|
|
|
|
|
return record.getConcentration();
|
|
|
|
|
default:
|
|
|
|
|
System.out.println("未知的监测字段: " + monitorField);
|
|
|
|
|
return null;
|
|
|
|
@ -498,8 +510,8 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
descriptions.add("温度");
|
|
|
|
|
descriptions.add("湿度");
|
|
|
|
|
descriptions.add("照度");
|
|
|
|
|
descriptions.add("噪声");
|
|
|
|
|
descriptions.add("浓度");
|
|
|
|
|
descriptions.add("噪音");
|
|
|
|
|
descriptions.add("气体浓度");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -534,8 +546,13 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
return monitorField == 0L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 其他设备类型暂不支持字段级规则
|
|
|
|
|
return false;
|
|
|
|
|
// 其他设备类型支持噪音(6)、照度(7)、气体浓度(8)字段
|
|
|
|
|
if (monitorField >= 6L && monitorField <= 8L) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 默认支持温度和湿度字段
|
|
|
|
|
return monitorField == 0L || monitorField == 1L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -755,7 +772,7 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 批量保存WebSocket告警数据
|
|
|
|
|
* 处理前端传来的告警数据列表,进行去重和批量插入
|
|
|
|
|
* 处理前端传来的告警数据列表,直接插入数据库
|
|
|
|
|
*
|
|
|
|
|
* @param alarmDataList 告警数据列表
|
|
|
|
|
* @return 实际插入的记录数量
|
|
|
|
@ -771,7 +788,10 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
|
|
|
|
|
// 设置默认值和创建时间
|
|
|
|
|
Date currentTime = DateUtils.getNowDate();
|
|
|
|
|
int insertedCount = 0;
|
|
|
|
|
|
|
|
|
|
for (EmsRecordAlarmData alarmData : alarmDataList) {
|
|
|
|
|
try {
|
|
|
|
|
// 设置创建时间
|
|
|
|
|
if (alarmData.getCreateTime() == null) {
|
|
|
|
|
alarmData.setCreateTime(currentTime);
|
|
|
|
@ -793,14 +813,24 @@ public class EmsRecordAlarmDataServiceImpl implements IEmsRecordAlarmDataService
|
|
|
|
|
alarmData.setCollectTime(currentTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("准备保存告警数据 - 设备:" + alarmData.getMonitorId() +
|
|
|
|
|
System.out.println("保存告警数据 - 设备:" + alarmData.getMonitorId() +
|
|
|
|
|
", 原因:" + alarmData.getCause() +
|
|
|
|
|
", 数值:" + alarmData.getAlarmData() +
|
|
|
|
|
", 告警类型:" + alarmData.getAlarmType());
|
|
|
|
|
|
|
|
|
|
// 直接插入数据库,不进行去重检查
|
|
|
|
|
int result = insertEmsRecordAlarmData(alarmData);
|
|
|
|
|
if (result > 0) {
|
|
|
|
|
insertedCount++;
|
|
|
|
|
System.out.println("成功保存告警数据 - 设备:" + alarmData.getMonitorId() +
|
|
|
|
|
", 原因:" + alarmData.getCause());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 复用现有的严格去重逻辑
|
|
|
|
|
int insertedCount = insertAlarmDataWithStrictDuplicateCheck(alarmDataList);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("保存告警数据时发生错误: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("WebSocket告警数据保存完成,实际插入: " + insertedCount + " 条记录");
|
|
|
|
|
System.out.println("==== WebSocket告警数据保存结束 ====");
|
|
|
|
|