From 8ac96e8ec4ff9e519ad22a6d86b7ed3d639cc978 Mon Sep 17 00:00:00 2001 From: wenlele Date: Wed, 19 Oct 2022 16:13:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=A6=BB=E7=BA=BF=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/control/toolLink.js | 99 ++++++++++++++++++- .../sections/problem/containers/dataAlarm.jsx | 5 +- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/api/app/lib/controllers/control/toolLink.js b/api/app/lib/controllers/control/toolLink.js index 6ce934d..685b2f6 100644 --- a/api/app/lib/controllers/control/toolLink.js +++ b/api/app/lib/controllers/control/toolLink.js @@ -1,4 +1,5 @@ 'use strict'; +const moment = require('moment'); async function list (ctx) { try { @@ -118,16 +119,108 @@ async function del (ctx) { async function count (ctx) { try { const { models } = ctx.fs.dc; - const { userId, pepUserId , userInfo} = ctx.fs.api + const { userId, pepUserId, userInfo = {}, pepUserInfo } = ctx.fs.api const { clickHouse } = ctx.app.fs const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs const { database: anxinyun } = clickHouse.anxinyun.opts.config const { pepProjectId } = ctx.request.body + let anxinStruc = await anxinStrucIdRange({ + ctx, pepProjectId + }) + if (anxinStruc.length) { + + const anxinStrucIds = anxinStruc.map(a => a.strucId) || [] + + const dataAlarm = await clickHouse.dataAlarm.query(` + SELECT + AlarmId,State,StartTime + FROM + alarms + WHERE + alarms.StructureId IN (${anxinStrucIds.join(",")}) + `).toPromise(); + + //数据告警总数 + const alarm = await clickHouse.dataAlarm.query(` + SELECT + count(alarms.AlarmId) AS count + FROM + alarms + WHERE + alarms.StructureId IN (${anxinStrucIds.join(",")}) + `).toPromise(); + + + const confirmedAlarm = dataAlarm + // TODO: 开发临时注释 + .filter(ar => ar.State && ar.State > 2) + .map(ar => "'" + ar.AlarmId + "'") + + //剩余数据告警 + const alarmSurplus = dataAlarm.filter(ar => ar.State && ar.State < 3).length || 0 + + //今日新增数据告警 + const alarmNewAdd = await clickHouse.dataAlarm.query(` + SELECT + count(alarms.StartTime) AS count + FROM + alarms + WHERE + alarms.StructureId IN (${anxinStrucIds.join(",")}) + AND + alarms.StartTime >= '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' + AND + alarms.StartTime <= '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' + + `).toPromise(); + + //今日确认数据告警 + const confirmedAlarmDetailMax = confirmedAlarm.length ? + await clickHouse.dataAlarm.query(` + SELECT + max(Time) AS Time, AlarmId , max(Content) AS Content + FROM + alarm_details + WHERE + AlarmId IN (${confirmedAlarm.join(',')}) + AND + alarm_details.Time >= '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' + AND + alarm_details.Time <= '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' + GROUP BY AlarmId + `).toPromise() : + []; + + + + + + + + + + ctx.status = 200; + ctx.body = { + dataAlarm: { + alarm: alarm[0].count || 0, + alarmSurplus: alarmSurplus, + alarmNewAdd: alarmNewAdd[0].count || 0, + confirmedAlarmDetailMax: confirmedAlarmDetailMax.length || 0, + }, + videoAlarm:{ + + } + + } + } else { + ctx.body = { + dataAlarm: 0, + } + } ctx.status = 200; - ctx.body = {} } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; @@ -139,8 +232,6 @@ async function count (ctx) { - - module.exports = { list, edit, del, count }; \ No newline at end of file diff --git a/web/client/src/sections/problem/containers/dataAlarm.jsx b/web/client/src/sections/problem/containers/dataAlarm.jsx index e0599dc..1703abb 100644 --- a/web/client/src/sections/problem/containers/dataAlarm.jsx +++ b/web/client/src/sections/problem/containers/dataAlarm.jsx @@ -161,9 +161,9 @@ const DataAlarm = ({ match, dispatch, actions, user, loading, socket, iotVcmpWeb //表格设置信息 const tableList = { dataLnterrupt: ['index', 'projectName', 'StructureName', 'SourceName', 'AlarmGroupUnit', 'AlarmCodeName', 'sustainTime', 'createTime', 'AlarmContent', 'CurrentLevel', 'updateTime', 'detailCount', 'confirm', 'confirmTime',], - dataAbnormal: ['index', 'projectName', 'StructureName', 'SourceName', 'type', 'createTime', 'sustainTime', 'AlarmContent', 'CurrentLevel', 'updateTime', 'detailCount', 'confirm', 'confirmTime'], + dataAbnormal: ['index', 'projectName', 'StructureName', 'SourceName', 'type', 'createTime', 'sustainTime', 'AlarmContent', 'CurrentLevel', 'updateTime', 'detailCount', 'confirm', 'confirmTime'], strategyHit: ['index', 'projectName', 'StructureName', 'SourceName', 'Strategy', 'State', 'createTime', 'sustainTime', 'AlarmContent', 'CurrentLevel', 'updateTime', 'detailCount', 'confirm', 'confirmTime'], - videoAbnormal: ['index', 'projectName', 'StructureName', 'SourceName', 'station', 'cameraKindId', 'sustainTime', 'venderName', 'point', 'cameraSerialNo', 'cameraChannelNo', 'platform', 'AlarmContent', 'resolve', 'createTime', 'updateTime', 'confirm', 'confirmTime', 'camerOnline'], + videoAbnormal: ['index', 'projectName', 'StructureName', 'SourceName', 'station', 'cameraKindId', 'sustainTime', 'venderName', 'point', 'cameraSerialNo', 'cameraChannelNo', 'platform', 'AlarmContent', 'resolve', 'createTime', 'updateTime', 'confirm', 'confirmTime',], useAbnormal: ['index', 'projectName', 'appName', 'url', 'type', 'alarmContent', 'createTime', 'sustainTime', 'updateTime', 'confirm', 'confirmTime'], deviceAbnormal: ['index', 'projectName', 'StructureName', 'SourceName', 'station', 'type', 'cameraKindId', 'sustainTime', 'venderName', 'AlarmContent', 'AlarmCodeName', 'createTime', 'updateTime', 'confirm', 'confirmTime'], } @@ -524,6 +524,7 @@ const DataAlarm = ({ match, dispatch, actions, user, loading, socket, iotVcmpWeb : ""} + {/* 视频的播放 */} {videoModal ?