Browse Source

告警推送 筛选监测因素

dev
巴林闲侠 2 years ago
parent
commit
e01a73e227
  1. 1
      api/app/lib/controllers/alarm/data.js
  2. 72
      api/app/lib/schedule/alarms_push.js

1
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 ?

72
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
}

Loading…
Cancel
Save