From 2fec8133c7ef4b11234603c3048ea65a00b44a85 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Tue, 29 Nov 2022 18:05:36 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=91=E6=B5=8B=E9=A1=B9=E5=91=8A=E8=AD=A6?= =?UTF-8?q?=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 111 +++++++++++++++++++--------- 1 file changed, 78 insertions(+), 33 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 7d75d08..aa4d859 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -1,11 +1,14 @@ const moment = require('moment') +let isDev = false +isDev = true + module.exports = function (app, opts) { const alarmsPush = app.fs.scheduleInit( { interval: '12 */1 * * * *', - // immediate: true, // dev - proRun: true, + immediate: isDev, + proRun: !isDev, }, async () => { try { @@ -140,7 +143,9 @@ module.exports = function (app, opts) { }) // !开发测试用的数据 - // searchStrucIds = searchStrucIds.concat([991, 1052, 700]) + if (isDev) { + searchStrucIds = searchStrucIds.concat([991, 1052, 700]) + } if (searchStrucIds.length) { searchStrucIds.unshift(-1) @@ -350,18 +355,19 @@ module.exports = function (app, opts) { } } else { - if (pomsStrucFactorId) { - if (!a.strucId || !a.anxinStationFactorId) { - // 当前告警没有绑定结构物或者摄像头没有绑定测点 - continue - } else if (!pomsStrucFactorId[a.strucId]) { - // 推送配置没配置这个结构物 - continue - } else if (!pomsStrucFactorId[a.strucId].includes(a.anxinStationFactorId)) { - // 不包含这个监测因素 - continue - } - } + /**按监测因素 factor 筛选告警*/ + // if (pomsStrucFactorId) { + // if (!a.strucId || !a.anxinStationFactorId) { + // // 当前告警没有绑定结构物或者摄像头没有绑定测点 + // continue + // } else if (!pomsStrucFactorId[a.strucId]) { + // // 推送配置没配置这个结构物 + // continue + // } else if (!pomsStrucFactorId[a.strucId].includes(a.anxinStationFactorId)) { + // // 不包含这个监测因素 + // continue + // } + // } let d = { cameraId: a.cameraId, @@ -660,30 +666,65 @@ module.exports = function (app, opts) { let dataAlarmG3 = []; let dataAlarmG45 = []; let deviceStatistic = new Set() + let dataAlarmDetails = [] + if (dataAlarms.length) { + dataAlarmDetails = + await clickHouse.dataAlarm.query(` + SELECT * FROM alarm_details + WHERE AlarmId IN (${dataAlarms.map(da => da.AlarmId).join(',')}, '-1') + AND AlarmState = 0 + `) + } for (let d of dataAlarms) { - if (pomsStrucFactorId && d.SourceTypeId == 2) { - // 做了监测因素筛选 且当前告警有监测因素 - if (!d.factor || d.factor == 0) { - // 监测因素不对劲 - continue - } else if (!d.StructureId) { - // 当前告警没有绑定结构物 - continue - } else if (!pomsStrucFactorId[d.StructureId]) { - // 推送配置没配置这个结构物 - continue - } else if (!pomsStrucFactorId[d.StructureId].includes(d.factor)) { - // 不包含这个监测因素 - continue - } - } + /** 按监测因素筛选 且为测点告警 */ + // if (pomsStrucFactorId && d.SourceTypeId == 2) { + // // 做了监测因素筛选 且当前告警有监测因素 + // if (!d.factor || d.factor == 0) { + // // 监测因素不对劲 + // continue + // } else if (!d.StructureId) { + // // 当前告警没有绑定结构物 + // continue + // } else if (!pomsStrucFactorId[d.StructureId]) { + // // 推送配置没配置这个结构物 + // continue + // } else if (!pomsStrucFactorId[d.StructureId].includes(d.factor)) { + // // 不包含这个监测因素 + // continue + // } + // } if (d.AlarmGroup == 1) { dataAlarmG1.push(d) } else if (d.AlarmGroup == 2) { dataAlarmG2.push(d) } else if (d.AlarmGroup == 3) { + + /** 按监测因项 factor-item 的名称筛选*/ + if (pomsStrucFactorId) { + // 兼容之前的设置 有这个信息才进行判断 + if (!d.StructureId) { + // 当前告警没有绑定结构物 + continue + } else if (!pomsStrucFactorId[d.StructureId]) { + // 推送配置没配置这个结构物 + continue + } else { + let corDetail = dataAlarmDetails.find(da => da.AlarmId == d.AlarmId) + if (corDetail) { + // 判断告警详情信息里有没有监测项关键字 + if (!pomsStrucFactorId[d.StructureId].some(factorItemName => { + return corDetail.Content.includes(factorItemName) + })) { + continue + } + } else { + continue + } + } + } + dataAlarmG3.push(d) } else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) { dataAlarmG45.push(d) @@ -780,8 +821,12 @@ module.exports = function (app, opts) { } return arr }, []) - // !开发测试用的数据 - // emails = ['1650192445@qq.com'] + + if (isDev) { + // !开发测试用的数据 + emails = ['1650192445@qq.com'] + } + if (emails.length) { await pushByEmail({ email: emails,