From 518fb3d974c191b9c5e16c00e4573cbf01bb82a4 Mon Sep 17 00:00:00 2001 From: wuqun Date: Wed, 26 Oct 2022 17:44:35 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E5=91=8A=E8=AD=A6=E5=A4=84=E7=BD=AE?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1,=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/schedule/alarms_handle_statistics.js | 168 +++++++----------- 1 file changed, 66 insertions(+), 102 deletions(-) diff --git a/api/app/lib/schedule/alarms_handle_statistics.js b/api/app/lib/schedule/alarms_handle_statistics.js index f4e945f..37097ae 100644 --- a/api/app/lib/schedule/alarms_handle_statistics.js +++ b/api/app/lib/schedule/alarms_handle_statistics.js @@ -8,7 +8,7 @@ module.exports = function (app, opts) { const { database: anxinyun } = clickHouse.anxinyun.opts.config const alarmHandleStatistics = app.fs.scheduleInit( { - interval: '40 8 15 * * *', + interval: '10 41 17 * * *', // immediate: true, //proRun: true, }, @@ -42,10 +42,10 @@ module.exports = function (app, opts) { //算单个项目 //pomsProject.map(p => { //let pid = p.id; - let pid = 26 - let pDataAlarms = dataAlarms.filter(da => da.pomsProject.map(dap => dap.id).indexOf(pid) != -1) + let pid = 22 + let pDataAlarms = dataAlarms.filter(da => da.pomsProject.indexOf(pid) != -1) let pAppAlarms = appAlarms.filter(aa => aa.app.projectCorrelations.map(ap => ap.id).indexOf(pid) != -1) - let pVideoAlarms = videoAlarms.filter(va => va.pomsProject.map(dap => dap.id).indexOf(pid) != -1) + let pVideoAlarms = videoAlarms.filter(va => va.pomsProject.indexOf(pid) != -1) let pDataMap = calculate(pDataAlarms, pAppAlarms, pVideoAlarms) let sm = pDataAlarms.length + pAppAlarms.length + pVideoAlarms.length; @@ -154,14 +154,14 @@ module.exports = function (app, opts) { alarms.AlarmId AS AlarmId, alarms.State AS State, alarms.StructureId AS StructureId, - SourceName, StartTime, EndTime + StartTime, EndTime ${alarmQueryOptionStr}`).toPromise(); const confirmedAlarm = alarmRes.filter(ar => ar.State && ar.State > 2).map(ar => "'" + ar.AlarmId + "'"); const confirmedAlarmDetailMax = confirmedAlarm.length ? await clickHouse.dataAlarm.query(` SELECT - max(Time) AS Time, AlarmId , max(Content) AS Content + max(Time) AS Time, AlarmId FROM alarm_details WHERE @@ -177,7 +177,7 @@ module.exports = function (app, opts) { // TODO: 开发临时添加 ] } - ).pomsProject + ).pomsProject.map(p => p.id) // 最新告警详情 - 确认信息 let corConfirmedData = (confirmedAlarmDetailMax.find(cdm => cdm.AlarmId == ar.AlarmId) || {}); @@ -199,9 +199,7 @@ module.exports = function (app, opts) { attributes: ['id', 'createTime', 'confirmTime'], include: [{ model: models.App, - attributes: { - exclude: ['projectId'] - }, + attributes: ['id'], include: [{ model: models.ProjectCorrelation, attributes: ['id'] @@ -228,55 +226,27 @@ module.exports = function (app, opts) { ` SELECT cameraAlarm.cameraId AS cameraId, - cameraAlarm.cameraName AS cameraName, - cameraAlarm.cameraKindId AS cameraKindId, - cameraAlarm.venderId AS venderId, - cameraAlarm.venderName AS venderName, - cameraAlarm.cameraSerialNo AS cameraSerialNo, - cameraAlarm.cameraChannelNo AS cameraChannelNo, cameraAlarm.alarmId AS alarmId, cameraAlarm.createTime AS createTime, - cameraAlarm.updateTime AS updateTime, - cameraAlarm.platform AS platform, - 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, - secret_yingshi.token AS yingshiToken, - anxinIpc.t_video_ipc.name AS anxinIpcPosition, - anxinStation.id AS anxinStationId, - anxinStation.name AS anxinStationName, - anxinStruc.name AS strucName, - anxinStruc.id AS strucId + anxinStruc.id AS strucId FROM ( SELECT camera.id AS cameraId, - camera.gb_id AS gbId, - camera.name AS cameraName, - camera.kind_id AS cameraKindId, - camera.vender_id AS venderId, - camera.yingshi_secret_id AS yingshiSecretId, - vender.name AS venderName, camera_status_alarm.id AS alarmId, camera_status_alarm.create_time AS createTime, - camera_status_alarm.update_time AS updateTime, camera_status_alarm.platform AS platform, camera_status_alarm.status_id AS statusId, 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.confirm_time AS confirmTime FROM camera_status_alarm INNER JOIN camera ON camera.serial_no = camera_status_alarm.serial_no AND camera.channel_no = camera_status_alarm.channel_no - LEFT JOIN vender - ON vender.id = camera.vender_id WHERE camera.delete = false AND camera.recycle_time is null @@ -295,10 +265,6 @@ module.exports = function (app, opts) { 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 - LEFT JOIN "secret_yingshi" - ON "secret_yingshi".id = cameraAlarm.yingshiSecretId LEFT JOIN ${anxinyun}.t_video_ipc AS anxinIpc ON toString(anxinIpc.channel_no) = cameraAlarm.cameraChannelNo @@ -308,8 +274,6 @@ module.exports = function (app, opts) { AND anxinStruc.id IN (${anxinStrucIds.join(',')}) LEFT JOIN ${anxinyun}.t_video_ipc_station AS anxinIpcStation ON anxinIpcStation.ipc = anxinIpc.id - LEFT JOIN ${anxinyun}.t_sensor AS anxinStation - ON anxinStation.id = anxinIpcStation.station `).toPromise() : [] let returnD = [] @@ -317,51 +281,51 @@ module.exports = function (app, opts) { // 每个设备一个告警 for (let a of alarmRes) { 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, - projectId: a.projectId, - name: a.strucName - }) - } - if (a.anxinStationId && !curD.station.some(s => s.id == a.anxinStationId)) { - curD.station.push({ - id: a.anxinStationId, - name: a.anxinStationName, - position: a.anxinIpcPosition - }) - } + //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, + // projectId: a.projectId, + // name: a.strucName + // }) + // } + // if (a.anxinStationId && !curD.station.some(s => s.id == a.anxinStationId)) { + // curD.station.push({ + // id: a.anxinStationId, + // name: a.anxinStationName, + // position: a.anxinIpcPosition + // }) + // } } else { let d = { cameraId: a.cameraId, - cameraName: a.cameraName, - camerOnline: a.cameraOnline, - cameraSerialNo: a.cameraSerialNo, - cameraChannelNo: a.cameraChannelNo, + //cameraName: a.cameraName, + //camerOnline: a.cameraOnline, + //cameraSerialNo: a.cameraSerialNo, + //cameraChannelNo: a.cameraChannelNo, autoRestore: a.autoRestore, createTime: a.createTime, - updateTime: a.updateTime, - platform: a.platform, - statusDescribe: a.statusDescribe, + //updateTime: a.updateTime, + //platform: a.platform, + //statusDescribe: a.statusDescribe, alarmId: a.alarmId, - confirmContent: a.confirmContent, + //confirmContent: a.confirmContent, confirmTime: a.confirmTime, - venderId: a.venderId, - venderName: a.venderName, - cameraKindId: a.cameraKindId, - yingshiToken: a.yingshiToken, + // venderId: a.venderId, + // venderName: a.venderName, + // cameraKindId: a.cameraKindId, + // yingshiToken: a.yingshiToken, - resolve: [], - struc: [], - station: [] + // resolve: [], + // struc: [], + // station: [] } // pep 项目 @@ -372,28 +336,28 @@ module.exports = function (app, opts) { ] } - ).pomsProject + ).pomsProject.map(d => d.id) - if (a.resolveId) { - d.resolve.push({ - id: a.resolveId, - resolve: a.resolve - }) - } - if (a.strucId) { - d.struc.push({ - id: a.strucId, - projectId: a.projectId, - name: a.strucName - }) - } - if (a.anxinStationId) { - d.station.push({ - id: a.anxinStationId, - name: a.anxinStationName, - position: a.anxinIpcPosition - }) - } + // if (a.resolveId) { + // d.resolve.push({ + // id: a.resolveId, + // resolve: a.resolve + // }) + // } + // if (a.strucId) { + // d.struc.push({ + // id: a.strucId, + // projectId: a.projectId, + // name: a.strucName + // }) + // } + // if (a.anxinStationId) { + // d.station.push({ + // id: a.anxinStationId, + // name: a.anxinStationName, + // position: a.anxinIpcPosition + // }) + // } returnD.push(d) positionD[a.cameraId] = { positionReturnD: returnD.length - 1