From f4d11274a6d3353dc8c57ce4d54320d9f7f442c6 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Thu, 27 Oct 2022 18:12:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=BB=93=E6=9E=84=E7=89=A9=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E9=A1=B9=E7=9B=AE=E4=B8=8D=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 65 ++++++++++++----------------- api/app/lib/utils/dataRange.js | 43 +++++++++++++------ 2 files changed, 58 insertions(+), 50 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 4659d02..a0d8918 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -53,7 +53,7 @@ module.exports = function (app, opts) { for (let { dataValues: c } of configListRes) { if (c.tacticsParams && c.tactics) { - const { projectCorrelation, strucId } = c + const { projectCorrelation, strucId, pomsProjectId } = c const { interval, deviceProportion } = c.tacticsParams if ( @@ -70,7 +70,7 @@ module.exports = function (app, opts) { ) ) { // TODO 查当前 poms 下的结构物 并把不包含的去掉 - + const strucListRes = strucId.length ? await clickHouse.anxinyun.query(` SELECT id, iota_thing_id, name FROM t_structure @@ -83,14 +83,21 @@ module.exports = function (app, opts) { let videoAlarms = [] + let appAlarmWhereOption = { + confirmTime: null, + } + let appAlarms = [] + let deviceCount = 0 let cameraCount = 0 // 判断推送策略 let pointTime = moment().subtract(interval, 'minute').format('YYYY-MM-DD HH:mm:ss') if (c.tactics == 'immediately') { dataAlarmOption.push(`StartTime >= '${pointTime}'`); + appAlarmWhereOption.createTime = { $gte: pointTime } } else if (c.tactics == 'continue') { dataAlarmOption.push(`StartTime <= '${pointTime}'`); + appAlarmWhereOption.createTime = { $lte: pointTime } } else if (c.tactics == 'abnormal_rate') { dataAlarmOption.push(`StartTime <= '${pointTime}'`); if (c.alarmType.includes('data_outages') || c.alarmType.includes('data_exception')) { @@ -110,6 +117,7 @@ module.exports = function (app, opts) { `).toPromise())[0].count : 0 } + appAlarmWhereOption.createTime = { $lte: pointTime } } // 判断告警数据范围 @@ -135,9 +143,7 @@ module.exports = function (app, opts) { cameraAlarm.confirmContent AS confirmContent, cameraAlarm.confirmTime AS confirmTime, cameraAlarm.autoRestore AS autoRestore, - camera_status_resolve.id AS resolveId, camera_status.describe AS statusDescribe, - camera_status_resolve.resolve AS resolve, "gbCamera".online AS cameraOnline, anxinIpc.t_video_ipc.name AS anxinIpcPosition, anxinStation.id AS anxinStationId, @@ -155,7 +161,7 @@ module.exports = function (app, opts) { camera_status_alarm.serial_no AS cameraSerialNo, camera_status_alarm.channel_no AS cameraChannelNo, camera_status_alarm.confirm AS confirmContent, - ${'camera_status_alarm.auto_restore AS autoRestore,'} + camera_status_alarm.auto_restore AS autoRestore, camera_status_alarm.confirm_time AS confirmTime FROM camera_status_alarm INNER JOIN ${anxinyun}.t_video_ipc @@ -165,15 +171,13 @@ module.exports = function (app, opts) { INNER JOIN camera ON camera.serial_no = camera_status_alarm.serial_no AND camera.channel_no = camera_status_alarm.channel_no - WHERE - camera.delete = false + AND camera.delete = false AND camera.recycle_time is null + WHERE camera_status_alarm.confirm_time IS null ) AS cameraAlarm LEFT JOIN camera_status ON cameraAlarm.platform = camera_status.platform AND cameraAlarm.statusId = camera_status.id - LEFT JOIN camera_status_resolve - ON camera_status_resolve.status_id = camera_status.id LEFT JOIN "gbCamera" ON "gbCamera".id = cameraAlarm.gbId @@ -196,12 +200,7 @@ module.exports = function (app, opts) { for (let a of videoAlarms) { if (positionD[a.cameraId]) { let curD = returnD[positionD[a.cameraId].positionReturnD] - if (a.resolveId && !curD.resolve.some(r => r.id == a.resolveId)) { - curD.resolve.push({ - id: a.resolveId, - resolve: a.resolve - }) - } + if (a.strucId && !curD.struc.some(s => s.id == a.strucId)) { curD.struc.push({ id: a.strucId, @@ -231,32 +230,10 @@ module.exports = function (app, opts) { alarmId: a.alarmId, confirmContent: a.confirmContent, confirmTime: a.confirmTime, - - venderId: a.venderId, - venderName: a.venderName, - cameraKindId: a.cameraKindId, - - resolve: [], struc: [], station: [] } - // pep 项目 - // d.pomsProject = ( - // anxinStruc.find(as => as.strucId == a.strucId) || - // { - // pomsProject: [ - - // ] - // } - // ).pomsProject - - if (a.resolveId) { - d.resolve.push({ - id: a.resolveId, - resolve: a.resolve - }) - } if (a.strucId) { d.struc.push({ id: a.strucId, @@ -280,7 +257,19 @@ module.exports = function (app, opts) { let p = 1 } if (c.alarmType.includes('app_exception')) { - + appAlarms = await models.AppAlarm.findAll({ + where: appAlarmWhereOption, + include: [{ + model: models.App, + include: [{ + model: models.ProjectApp, + where: { + projectId: pomsProjectId + }, + }] + }] + }) + let a = 2 } if (c.alarmType.includes('device_exception')) { dataAlarmGroupOption.push(4) diff --git a/api/app/lib/utils/dataRange.js b/api/app/lib/utils/dataRange.js index ea1c4c6..14fcc6b 100644 --- a/api/app/lib/utils/dataRange.js +++ b/api/app/lib/utils/dataRange.js @@ -160,24 +160,43 @@ module.exports = function (app, opts) { // 并保存信息至数据 let undelStruc = [] for (let s of undelStrucRes) { - if (!undelStruc.some(us => us.strucId == s.strucId)) { - let pomsProject = [] - for (let { dataValues: br } of bindRes) { - if (br.anxinProjectId.some(braId => braId == s.projectId)) { - let corPepProject = pepProjectRes.find(pp => pp.id == br.pepProjectId) - pomsProject.push({ + let corStruc = undelStruc.find(us => us.strucId == s.strucId) + if (corStruc) { + if (!corStruc.project.some(cp => cp.id == s.projectId)) { + corStruc.project.push({ + id: s.projectId + }) + } + } else { + corStruc = { + strucId: s.strucId, + strucName: s.strucName, + projectId: s.projectId, + project: [{ + id: s.projectId, + }], + pomsProject: [] + } + undelStruc.push(corStruc) + } + + for (let { dataValues: br } of bindRes) { + if (br.anxinProjectId.some(braId => braId == s.projectId)) { + let corPepProject = pepProjectRes.find(pp => pp.id == br.pepProjectId) + let corPomsProject = corStruc.pomsProject.find(cp => cp.id == br.id) + + if (corPomsProject) { + // poms 的 project 和 pep 的 project 是一对一的关系 所以这个情况不用处理 + } else { + corStruc.pomsProject.push({ ...br, pepProject: corPepProject }) } + } - undelStruc.push({ - strucId: s.strucId, - strucName: s.strucName, - projectId: s.projectId, - pomsProject: pomsProject - }) } + } return undelStruc }