diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index e6afd6c..da8d3a5 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -176,8 +176,8 @@ async function list (ctx) { } else { corConfirmedData = {} } - ar.confirmedContent = 'corConfirmedData.Content' - ar.confirmedTime = 'corConfirmedData.Time' + ar.confirmedContent = corConfirmedData.Content + ar.confirmedTime = corConfirmedData.Time // 告警详情的数量 ar.detailCount = (alarmDetailCount.find(adc => adc.AlarmId == ar.AlarmId) || { count: 0 }).count diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index 05a9645..3d8521a 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -18,34 +18,101 @@ async function alarmList (ctx) { try { const { models } = ctx.fs.dc; const { clickHouse } = ctx.app.fs - const { keyword } = cyx.query + const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs + const { database: anxinyun } = clickHouse.anxinyun.opts.config + const { pepProjectId, keywordTarget, keyword } = ctx.query - const alarmRes = await clickHouse.vcmp.query(` - SELECT - camera.id AS cameraId, - camera.name AS cameraName, - 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_resolve.resolve AS resolve - 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 - LEFT JOIN camera_status - ON camera_status_alarm.platform = camera_status.platform - AND camera_status_alarm.status_id = camera_status.id - LEFT JOIN camera_status_resolve - ON camera_status_resolve.status_id = camera_status.id - `).toPromise() + let anxinStruc = await anxinStrucIdRange({ + ctx, pepProjectId, keywordTarget, keyword + }) + + const alarmRes = await clickHouse.vcmp.query( + ` + SELECT + cameraAlarm.cameraId AS cameraId, + cameraAlarm.cameraName AS cameraName, + cameraAlarm.cameraSerialNo AS cameraSerialNo, + cameraAlarm.cameraChannelNo AS cameraChannelNo, + cameraAlarm.alarmId AS alarmId, + cameraAlarm.createTime AS createTime, + cameraAlarm.updateTime AS updateTime, + cameraAlarm.platform AS platform, + 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, + anxinStruc.name AS strucName, + anxinStruc.id AS strucId + FROM + ( + SELECT + camera.id AS cameraId, + camera.gb_id AS gbId, + camera.name AS cameraName, + 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 + 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 + 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)` + '' + } + + ) + ) 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 + + 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 + ` + ).toPromise() let returnD = [] + let positionD = {} // 每个设备一个告警 - // for (let a of alarmRes) { - // if () - // } + for (let a of alarmRes) { + if (positionD[a.cameraId]) { + + } else { + let d = { + cameraId: a.cameraId, + alarmId: a.alarmId, + resolve: [], + struc: [] + } + if (a.resolveId) { + d.resolve.push({ + id: a.resolveId, + resolve: a.resolve + }) + } + returnD.push(d) + } + } ctx.status = 200; ctx.body = [] @@ -61,7 +128,7 @@ async function alarmList (ctx) { async function confirm (ctx) { try { const { models } = ctx.fs.dc; - + ctx.status = 20; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); diff --git a/api/app/lib/utils/dataRange.js b/api/app/lib/utils/dataRange.js index 02eb797..b542b4e 100644 --- a/api/app/lib/utils/dataRange.js +++ b/api/app/lib/utils/dataRange.js @@ -38,7 +38,7 @@ module.exports = function (app, opts) { // 根据 poms 的项目绑定关系查相关联的项企项目、安心云项目id信息 const bindRes = await models.ProjectCorrelation.findAll(findOption) - // 获取不重复的 安心云项目id + // 获取不重复的 项企项目id let pepProjectIds = [] for (let b of bindRes) { if (b.pepProjectId) { @@ -74,6 +74,7 @@ module.exports = function (app, opts) { [] + // 获取不重复的 安心云项目 id const anxinProjectIds = [ ...( bindRes.filter(b => pepProjectRes.some(pp => pp.id == b.pepProjectId)) @@ -99,25 +100,25 @@ module.exports = function (app, opts) { const undelStrucRes = anxinProjectIds.length ? await clickHouse.anxinyun.query( ` - SELECT - t_project.id AS projectId, - t_structure.id AS strucId, - t_structure.name AS strucName, - project_state - FROM - t_project - LEFT JOIN - t_project_structure - ON t_project_structure.project = t_project.id - RIGHT JOIN - t_structure - ON t_structure.id = t_project_structure.structure - WHERE - project_state != -1 - AND - t_project.id IN (${anxinProjectIds.join(',')}) - ${undelStrucWhereOptions.length ? `AND ${undelStrucWhereOptions.join(' AND ')}` : ''} - ` + SELECT + t_project.id AS projectId, + t_structure.id AS strucId, + t_structure.name AS strucName, + project_state + FROM + t_project + LEFT JOIN + t_project_structure + ON t_project_structure.project = t_project.id + RIGHT JOIN + t_structure + ON t_structure.id = t_project_structure.structure + WHERE + project_state != -1 + AND + t_project.id IN (${anxinProjectIds.join(',')}) + ${undelStrucWhereOptions.length ? `AND ${undelStrucWhereOptions.join(' AND ')}` : ''} + ` ).toPromise() : [] @@ -129,9 +130,10 @@ module.exports = function (app, opts) { undelStruc.push({ strucId: s.strucId, strucName: s.strucName, + // projectId: s.projectId, pepProject: pepProjectRes.filter(pp => { - return bindRes.find(br => { - return br.pepProjectId == pp.id && br.anxinProjectId.some(braId => braId == s.strucId) + return bindRes.some(br => { + return br.pepProjectId == pp.id && br.anxinProjectId.some(braId => braId == s.projectId) }) }) })