接收 全局推送告警 处理告警 优化控制逻辑

This commit is contained in:
mmc
2026-11-16 21:36:53 +08:00
parent d9f4b752dd
commit 2a429722d9
9 changed files with 489 additions and 229 deletions

View File

@@ -51,6 +51,7 @@ export default class DeviceController {
this.onIsExecuting = null;
this.handleArrivedPoint = null;
this.onDetectionReport = null;
this.onDeviceErrorPush = null;
// 全量设备实时状态(mapPush)连接
this.mapPushWs = null;
@@ -172,6 +173,53 @@ export default class DeviceController {
this.deviceStatusChangedMsg?.(msg);
}
if (msg?.type == 'device_error_push') {
console.log('device_error_push', msg);
const list = Array.isArray(msg?.alarms)
? msg.alarms
: Array.isArray(msg?.data?.alarms)
? msg.data.alarms
: Array.isArray(msg?.data) ? msg.data : [];
const levelMap = { 1: 'ERROR', 2: 'WARNING', 3: 'INFO', 4: 'INFO' };
// 后端 LocalDateTime 以数组 [年,月,日,时,分,秒,纳秒] 下发,需单独转换
const formatAlarmTime = (time) => {
if (time === null || time === undefined || time === '') return '';
if (Array.isArray(time)) {
const [y, mo, d, h = 0, mi = 0, se = 0] = time;
if (!y) return '';
const dt = dayjs(new Date(y, mo - 1, d, h, mi, se));
return dt.isValid() ? dt.format('YYYY-MM-DD HH:mm:ss') : '';
}
const dt = dayjs(time);
return dt.isValid() ? dt.format('YYYY-MM-DD HH:mm:ss') : String(time);
};
// alarmTitle 若为编码(如 SAFETY_FAULT_HEARTBEAT_TIMEOUT),改用 alarmContent 中文描述
const isAlarmCode = (val) => typeof val === 'string' && /^[A-Z][A-Z0-9_]*$/.test(val);
const alarms = list.map((a) => {
if (!a || typeof a !== 'object') return null;
// 统一告警级别:后端 ErrorLevel 1严重/2重要/3一般/4提示 → ERROR/WARNING/INFO
const rawLevel = a.alertLevel ?? a.alarmLevel;
const alertLevel = typeof rawLevel === 'number'
? (levelMap[rawLevel] || 'INFO')
: String(rawLevel || 'INFO').toUpperCase();
const rawTitle = a.alarmTitle;
const alarmTitle = (isAlarmCode(rawTitle) ? (a.alarmContent || rawTitle) : (rawTitle || a.alarmContent)) || a.alarmNo || '';
return {
...a,
alertLevel,
alarmTitle,
handleStatus: a.handleStatus ?? 1,
alarmTime: formatAlarmTime(a.alarmTime),
};
}).filter(Boolean);
if (alarms.length) {
this.onDeviceErrorPush?.({
deviceId: msg?.deviceId || msg?.data?.deviceId,
alarms,
});
}
}
if (msg?.type == 'route_post') {
console.log('route_post');
this.onRoutePost?.(msg);