diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index 167b3ec..33e3560 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -2,9 +2,14 @@ async function deviceType (ctx) { try { const { models } = ctx.fs.dc; + const { clickHouse } = ctx.app.fs + + const kindRes = await clickHouse.vcmp.query(` + SELECT * FROM camera_kind + `).toPromise() ctx.status = 200; - ctx.body = [] + ctx.body = kindRes } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; @@ -20,12 +25,44 @@ async function alarmList (ctx) { const { clickHouse } = ctx.app.fs const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs const { database: anxinyun } = clickHouse.anxinyun.opts.config - const { pepProjectId, keywordTarget, keyword } = ctx.query + const { pepProjectId, keywordTarget, keyword, state, kindId, sustainTimeStart, sustainTimeEnd, } = ctx.query let anxinStruc = await anxinStrucIdRange({ ctx, pepProjectId, keywordTarget, keyword }) + const anxinStrucIds = anxinStruc.map(a => a.strucId) + let cameraWhereOption = [] + if (keywordTarget == 'source' && keyword) { + cameraWhereOption.push(`camera.name LIKE '%${keyword}%'`) + } + if (state) { + if (state == 'new') { + cameraWhereOption.push(`camera_status_alarm.confirm_time IS null`) + } else if (state == 'histroy') { + cameraWhereOption.push(`camera_status_alarm.confirm_time IS NOT null`) + } + } + if (kindId) { + cameraWhereOption.push(`camera.kind_id = ${kindId}`) + } + if (sustainTimeStart && sustainTimeEnd) { + let momentStart = moment(sustainTimeStart).format('YYYY-MM-DD HH:mm:ss') + let momentEnd = moment(sustainTimeEnd).format('YYYY-MM-DD HH:mm:ss') + whereOption.push(` + ( + camera_status_alarm.create_time + BETWEEN '${momentStart}' AND '${momentEnd}' + OR + camera_status_alarm.update_time BETWEEN '${momentStart}' AND '${momentEnd}' + OR ( + camera_status_alarm.create_time <= '${momentStart}' + AND + camera_status_alarm.update_time >= '${momentEnd}' + ) + ) + `) + } const alarmRes = await clickHouse.vcmp.query( ` SELECT @@ -37,6 +74,8 @@ async function alarmList (ctx) { cameraAlarm.createTime AS createTime, cameraAlarm.updateTime AS updateTime, cameraAlarm.platform AS platform, + cameraAlarm.confirmContent AS confirmContent, + cameraAlarm.confirmTime AS confirmTime, camera_status_resolve.id AS resolveId, camera_status.describe AS statusDescribe, camera_status_resolve.resolve AS resolve, @@ -56,23 +95,25 @@ async function alarmList (ctx) { 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.channel_no AS cameraChannelNo, + camera_status_alarm.confirm AS confirmContent, + camera_status_alarm.confirm_time AS confirmTime FROM camera_status_alarm LEFT 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 + ${cameraWhereOption.length ? 'AND ' + cameraWhereOption.join(' AND ') : ''} + WHERE + camera.delete = false + AND camera.recycle_time is null 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 (422)` - '' + ${`WHERE ${anxinyun}.t_video_ipc.structure IN (${anxinStrucIds.join(',')})` } - ) ) AS cameraAlarm LEFT JOIN camera_status @@ -121,6 +162,8 @@ async function alarmList (ctx) { platform: a.platform, statusDescribe: a.statusDescribe, alarmId: a.alarmId, + confirmContent: a.confirmContent, + confirmTime: a.confirmTime, resolve: [], struc: [] } diff --git a/api/app/lib/routes/alarm/index.js b/api/app/lib/routes/alarm/index.js index 0deeb98..a811f88 100644 --- a/api/app/lib/routes/alarm/index.js +++ b/api/app/lib/routes/alarm/index.js @@ -46,6 +46,9 @@ module.exports = function (app, router, opts) { router.put('/alarm/data/confirm', dataAlarm.confirm(opts)); // 视频告警 + app.fs.api.logAttr['GET/alarm/video/device_kind'] = { content: '查询视频设备类型', visible: true }; + router.get('/alarm/video/device_kind', videoAlarm.deviceType); + app.fs.api.logAttr['GET/alarm/video/list'] = { content: '查询视频告警列表', visible: true }; router.get('/alarm/video/list', videoAlarm.alarmList); };