Browse Source

监测项告警筛选

dev
巴林闲侠 2 years ago
parent
commit
2fec8133c7
  1. 103
      api/app/lib/schedule/alarms_push.js

103
api/app/lib/schedule/alarms_push.js

@ -1,11 +1,14 @@
const moment = require('moment') const moment = require('moment')
let isDev = false
isDev = true
module.exports = function (app, opts) { module.exports = function (app, opts) {
const alarmsPush = app.fs.scheduleInit( const alarmsPush = app.fs.scheduleInit(
{ {
interval: '12 */1 * * * *', interval: '12 */1 * * * *',
// immediate: true, // dev immediate: isDev,
proRun: true, proRun: !isDev,
}, },
async () => { async () => {
try { 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) { if (searchStrucIds.length) {
searchStrucIds.unshift(-1) searchStrucIds.unshift(-1)
@ -350,18 +355,19 @@ module.exports = function (app, opts) {
} }
} else { } else {
if (pomsStrucFactorId) { /**按监测因素 factor 筛选告警*/
if (!a.strucId || !a.anxinStationFactorId) { // if (pomsStrucFactorId) {
// 当前告警没有绑定结构物或者摄像头没有绑定测点 // if (!a.strucId || !a.anxinStationFactorId) {
continue // // 当前告警没有绑定结构物或者摄像头没有绑定测点
} else if (!pomsStrucFactorId[a.strucId]) { // continue
// 推送配置没配置这个结构物 // } else if (!pomsStrucFactorId[a.strucId]) {
continue // // 推送配置没配置这个结构物
} else if (!pomsStrucFactorId[a.strucId].includes(a.anxinStationFactorId)) { // continue
// 不包含这个监测因素 // } else if (!pomsStrucFactorId[a.strucId].includes(a.anxinStationFactorId)) {
continue // // 不包含这个监测因素
} // continue
} // }
// }
let d = { let d = {
cameraId: a.cameraId, cameraId: a.cameraId,
@ -660,30 +666,65 @@ module.exports = function (app, opts) {
let dataAlarmG3 = []; let dataAlarmG3 = [];
let dataAlarmG45 = []; let dataAlarmG45 = [];
let deviceStatistic = new Set() 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) { for (let d of dataAlarms) {
if (pomsStrucFactorId && d.SourceTypeId == 2) { /** 按监测因素筛选 且为测点告警 */
// 做了监测因素筛选 且当前告警有监测因素 // if (pomsStrucFactorId && d.SourceTypeId == 2) {
if (!d.factor || d.factor == 0) { // // 做了监测因素筛选 且当前告警有监测因素
// 监测因素不对劲 // if (!d.factor || d.factor == 0) {
continue // // 监测因素不对劲
} else if (!d.StructureId) { // 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 continue
} else if (!pomsStrucFactorId[d.StructureId]) { } else if (!pomsStrucFactorId[d.StructureId]) {
// 推送配置没配置这个结构物 // 推送配置没配置这个结构物
continue continue
} else if (!pomsStrucFactorId[d.StructureId].includes(d.factor)) { } 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 continue
} }
} }
}
if (d.AlarmGroup == 1) {
dataAlarmG1.push(d)
} else if (d.AlarmGroup == 2) {
dataAlarmG2.push(d)
} else if (d.AlarmGroup == 3) {
dataAlarmG3.push(d) dataAlarmG3.push(d)
} else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) { } else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) {
dataAlarmG45.push(d) dataAlarmG45.push(d)
@ -780,8 +821,12 @@ module.exports = function (app, opts) {
} }
return arr return arr
}, []) }, [])
if (isDev) {
// !开发测试用的数据 // !开发测试用的数据
// emails = ['1650192445@qq.com'] emails = ['1650192445@qq.com']
}
if (emails.length) { if (emails.length) {
await pushByEmail({ await pushByEmail({
email: emails, email: emails,

Loading…
Cancel
Save