|
|
@ -1,6 +1,5 @@ |
|
|
|
'use strict'; |
|
|
|
const moment = require('moment'); |
|
|
|
const { alarmList } = require('../alarm/video'); |
|
|
|
|
|
|
|
//BI分析-数据
|
|
|
|
async function getDataAlarmsAggDay(ctx) { |
|
|
@ -94,14 +93,10 @@ async function getAppAlarmsAggDay(ctx) { |
|
|
|
attributes: ['id', 'createTime', 'confirmTime'], |
|
|
|
include: [{ |
|
|
|
model: models.App, |
|
|
|
attributes: { |
|
|
|
exclude: ['projectId'] |
|
|
|
}, |
|
|
|
attributes: ['id'], |
|
|
|
include: [{ |
|
|
|
model: models.ProjectCorrelation, |
|
|
|
attributes: { |
|
|
|
exclude: ['id'] |
|
|
|
}, |
|
|
|
attributes: ['id'] |
|
|
|
}] |
|
|
|
}] |
|
|
|
} |
|
|
@ -136,9 +131,99 @@ async function getAppAlarmsAggDay(ctx) { |
|
|
|
//BI分析-视频异常
|
|
|
|
async function getVideoAlarmsAggDay(ctx) { |
|
|
|
try { |
|
|
|
let videoAlarms = await alarmList(ctx, 'day'); |
|
|
|
let aggDayMap = []; |
|
|
|
const { clickHouse, utils: { anxinStrucIdRange } } = ctx.app.fs |
|
|
|
const { database: anxinyun } = clickHouse.anxinyun.opts.config |
|
|
|
const { pepProjectId } = ctx.query |
|
|
|
let anxinStruc = await anxinStrucIdRange({ |
|
|
|
ctx, pepProjectId |
|
|
|
}) |
|
|
|
const anxinStrucIds = anxinStruc.map(a => a.strucId) |
|
|
|
let statusAlarmWhereOption = [] |
|
|
|
let start = moment().add(-1, 'year').format('YYYY-MM-DD HH:mm:ss');//最近一年
|
|
|
|
statusAlarmWhereOption.push(`camera_status_alarm.create_time >= '${start}'`) |
|
|
|
|
|
|
|
const videoAlarms = anxinStrucIds.length ? await clickHouse.vcmp.query( |
|
|
|
`SELECT
|
|
|
|
cameraAlarm.cameraId AS cameraId, |
|
|
|
cameraAlarm.alarmId AS alarmId, |
|
|
|
cameraAlarm.createTime AS createTime, |
|
|
|
cameraAlarm.confirmTime AS confirmTime, |
|
|
|
${'cameraAlarm.autoRestore AS autoRestore,'} |
|
|
|
anxinStruc.id AS strucId |
|
|
|
FROM |
|
|
|
( |
|
|
|
SELECT |
|
|
|
camera.id AS cameraId, |
|
|
|
camera_status_alarm.id AS alarmId, |
|
|
|
camera_status_alarm.create_time AS createTime, |
|
|
|
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.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 |
|
|
|
WHERE |
|
|
|
camera.delete = false |
|
|
|
AND camera.recycle_time is null |
|
|
|
${statusAlarmWhereOption.length ? 'AND ' + statusAlarmWhereOption.join(' AND ') : ''} |
|
|
|
AND alarmId IN ( |
|
|
|
SELECT camera_status_alarm.id AS alarmId |
|
|
|
FROM camera_status_alarm |
|
|
|
RIGHT JOIN ${anxinyun}.t_video_ipc |
|
|
|
ON toString(${anxinyun}.t_video_ipc.channel_no) = camera_status_alarm.channel_no |
|
|
|
AND ${anxinyun}.t_video_ipc.serial_no = camera_status_alarm.serial_no |
|
|
|
${`WHERE ${anxinyun}.t_video_ipc.structure IN (${anxinStrucIds.join(',')})`} |
|
|
|
) |
|
|
|
) 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 ${anxinyun}.t_video_ipc AS anxinIpc |
|
|
|
ON toString(anxinIpc.channel_no) = cameraAlarm.cameraChannelNo |
|
|
|
AND anxinIpc.serial_no = cameraAlarm.cameraSerialNo |
|
|
|
LEFT JOIN ${anxinyun}.t_structure AS anxinStruc |
|
|
|
ON anxinStruc.id = anxinIpc.structure |
|
|
|
AND anxinStruc.id IN (${anxinStrucIds.join(',')}) |
|
|
|
LEFT JOIN ${anxinyun}.t_video_ipc_station AS anxinIpcStation |
|
|
|
ON anxinIpcStation.ipc = anxinIpc.id |
|
|
|
`).toPromise() : []
|
|
|
|
|
|
|
|
let returnD = [] |
|
|
|
let positionD = {} |
|
|
|
// 每个设备一个告警
|
|
|
|
for (let a of videoAlarms) { |
|
|
|
if (positionD[a.cameraId]) { |
|
|
|
} else { |
|
|
|
let d = { |
|
|
|
cameraId: a.cameraId, |
|
|
|
autoRestore: a.autoRestore, |
|
|
|
createTime: a.createTime, |
|
|
|
alarmId: a.alarmId, |
|
|
|
confirmTime: a.confirmTime, |
|
|
|
} |
|
|
|
d.pomsProject = ( |
|
|
|
anxinStruc.find(as => as.strucId == a.strucId) || |
|
|
|
{ |
|
|
|
pomsProject: [ |
|
|
|
|
|
|
|
] |
|
|
|
} |
|
|
|
).pomsProject.map(d => d.id) |
|
|
|
returnD.push(d) |
|
|
|
positionD[a.cameraId] = { |
|
|
|
positionReturnD: returnD.length - 1 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
let aggDayMap = []; |
|
|
|
for (let a of returnD) { |
|
|
|
let exist = aggDayMap.find(ad => ad.day == moment(a.createTime).format('YYYY-MM-DD')); |
|
|
|
if (exist) { |
|
|
|
exist.total++;//总数
|
|
|
|