From e01a73e2273cf8d31d488ba260f9d86d1ff50afe Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Mon, 28 Nov 2022 09:28:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=8E=A8=E9=80=81=20?= =?UTF-8?q?=E7=AD=9B=E9=80=89=E7=9B=91=E6=B5=8B=E5=9B=A0=E7=B4=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/data.js | 1 - api/app/lib/schedule/alarms_push.js | 72 +++++++++++++++++++++------ 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index f1d2b82..87ac48f 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -149,7 +149,6 @@ async function list (ctx) { `).toPromise(); const confirmedAlarm = alarmRes - // TODO: 开发临时注释 .filter(ar => ar.State && ar.State > 2) .map(ar => "'" + ar.AlarmId + "'") const confirmedAlarmDetailMax = confirmedAlarm.length ? diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 44eca5e..7d75d08 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -60,7 +60,7 @@ module.exports = function (app, opts) { for (let { dataValues: c } of configListRes) { if (c.tacticsParams && c.tactics) { // pomsProjectId 是个数组 [] - const { strucId, pomsProjectId, } = c + const { strucId, pomsProjectId, pomsStrucFactorId } = c const { interval, deviceProportion } = c.tacticsParams if ( @@ -274,6 +274,7 @@ module.exports = function (app, opts) { anxinIpc.t_video_ipc.name AS anxinIpcPosition, anxinStation.id AS anxinStationId, anxinStation.name AS anxinStationName, + anxinStation.factor AS anxinStationFactorId, anxinStruc.name AS strucName, anxinStruc.id AS strucId FROM ( @@ -348,6 +349,20 @@ 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 + } + } + let d = { cameraId: a.cameraId, cameraName: a.cameraName, @@ -363,6 +378,7 @@ module.exports = function (app, opts) { confirmContent: a.confirmContent, confirmTime: a.confirmTime, cameraKind: a.cameraKind, + factorId: a.anxinStationFactorId, struc: [], station: [] } @@ -387,28 +403,28 @@ module.exports = function (app, opts) { } } } - let p = 1 videoAlarms = returnD } if (c.alarmType.includes('app_exception')) { if (c.alarmSubType) { appAlarmWhereOption.type = { $in: c.alarmSubType['app_exception'] || [] } } - appAlarms = c.alarmSubType && c.alarmSubType['app_exception'].length ? await models.AppAlarm.findAll({ - where: appAlarmWhereOption, - order: [['createTime', 'DESC']], - include: [{ - model: models.App, - required: true, + appAlarms = c.alarmSubType && c.alarmSubType['app_exception'].length ? + await models.AppAlarm.findAll({ + where: appAlarmWhereOption, + order: [['createTime', 'DESC']], include: [{ - model: models.ProjectApp, - where: { - projectId: { $in: pomsProjectId } - }, + model: models.App, required: true, + include: [{ + model: models.ProjectApp, + where: { + projectId: { $in: pomsProjectId } + }, + required: true, + }] }] - }] - }) : [] + }) : [] } if (c.alarmType.includes('device_exception')) { dataAlarmGroupOption.push(4) @@ -424,15 +440,20 @@ module.exports = function (app, opts) { dataAlarmSubType.push(-1) dataAlarmOption.push(`AlarmGroupUnit IN (${dataAlarmSubType.join(',')})`) } - dataAlarms = (!c.alarmSubType || dataAlarmSubType.length) ? await clickHouse.dataAlarm.query(` + dataAlarms = + !c.alarmSubType || dataAlarmSubType.length ? + await clickHouse.dataAlarm.query(` SELECT * FROM alarms + LEFT JOIN ${anxinyun}.t_sensor + AS anxinStation + ON toString(anxinStation.id) = alarms.SourceId + AND alarms.SourceTypeId = 2 WHERE ${`State NOT IN (3, 4) AND `} StructureId IN (${searchStrucIds.join(',')}) ${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} ORDER BY StartTime DESC `).toPromise() : [] - console.log(dataAlarms); } let dataAlarmTitle = [{ @@ -640,6 +661,24 @@ module.exports = function (app, opts) { let dataAlarmG45 = []; let deviceStatistic = new Set() 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 (d.AlarmGroup == 1) { dataAlarmG1.push(d) } else if (d.AlarmGroup == 2) { @@ -655,6 +694,7 @@ module.exports = function (app, opts) { let rate = ((deviceStatistic.size + videoAlarms.length) / (parseInt(deviceCount) + parseInt(cameraCount))); if (rate < parseFloat(deviceProportion)) { + // 设备异常率低于设定值 continue }