diff --git a/api/app/lib/controllers/alarm/alarmConfirmLog.js b/api/app/lib/controllers/alarm/alarmConfirmLog.js new file mode 100644 index 0000000..5a91aea --- /dev/null +++ b/api/app/lib/controllers/alarm/alarmConfirmLog.js @@ -0,0 +1,49 @@ +'use strict'; + +const moment = require('moment') + +async function alarmConfirmLog(ctx, confirmPost, content) { + try { + const { models } = ctx.fs.dc; + //存日志 + let logDatas = []; + confirmPost.map(cp => { + let { pepUserId, projectCorrelationIds, alarmInfo } = cp; + projectCorrelationIds.map(id => { + logDatas.push({ + pepUserId, + projectCorrelationId: id, + alarmInfo,//包含告警id,type,source + confirmTime: moment().format(), + confirmContent: content + }) + }) + }) + let rslt = await models.AlarmConfirmLog.bulkCreate(logDatas, { returning: true }); + + //存最新动态 + let dynamics = rslt.map(r => { + return { + time: r.confirmTime, + alarmConfirmId: r.id, + projectCorrelationId: r.projectCorrelationId, + type: 4//告警确认 + } + }) + await models.LatestDynamicList.bulkCreate(dynamics); + + //TODO 消息推送到前端 + + + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + +module.exports = { + alarmConfirmLog +}; \ No newline at end of file diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 723435e..4472c04 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -1,7 +1,7 @@ 'use strict'; const moment = require('moment') - +const { alarmConfirmLog } = require('./alarmConfirmLog'); async function inspection(ctx) { // 巡查 try { @@ -328,7 +328,6 @@ async function confirmApiError(ctx) { try { const models = ctx.fs.dc.models; const { confirm, appAlarmId = [], confirmPost } = ctx.request.body - const { pepUserId, projectCorrelationIds, alarmInfo } = confirmPost await models.AppAlarm.update({ confirm, confirmTime: moment().format() @@ -338,29 +337,7 @@ async function confirmApiError(ctx) { } }) - //存日志 - let logDatas = projectCorrelationIds.map(id => { - return { - pepUserId, - projectCorrelationId: id, - alarmInfo,//包含告警id,type,source - confirmTime: moment().format(), - confirmContent: confirm - } - }) - let rslt = await models.AlarmConfirmLog.bulkCreate(logDatas, { returning: true }); - - //存最新动态 - let dynamics = rslt.map(r => { - return { - time: r.confirmTime, - alarmConfirmId: r.id, - projectCorrelationId: r.projectCorrelationId, - type: 4//告警确认 - } - }) - await models.LatestDynamicList.bulkCreate(dynamics); - + await alarmConfirmLog(ctx, confirmPost, confirm);//告警确认日志 ctx.status = 204; } catch (error) { diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index 595cd60..13f42fd 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -1,6 +1,6 @@ 'use strict'; const moment = require('moment'); - +const { alarmConfirmLog } = require('./alarmConfirmLog'); async function groupList (ctx) { try { const { models } = ctx.fs.dc; @@ -248,7 +248,6 @@ function confirm (opts) { const { utils: { kfkSendAsync } } = ctx.app.fs const { clickHouse } = ctx.app.fs const { content = '', alarmId, confirmPost } = ctx.request.body; - const { pepUserId, projectCorrelationIds, alarmInfo } = confirmPost; // 发送告警恢复通知 // Topic: alarm /* @@ -295,6 +294,9 @@ function confirm (opts) { await kfkSendAsync(payloads) } + + await alarmConfirmLog(ctx, confirmPost, content);//告警确认日志 + ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index a0d0096..8adf26b 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -1,6 +1,6 @@ 'use strict'; const moment = require('moment') - +const { alarmConfirmLog } = require('./alarmConfirmLog'); async function deviceType (ctx) { try { const { models } = ctx.fs.dc; @@ -129,7 +129,7 @@ async function alarmList (ctx, agg) { 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总书记任期 + 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(',')})`} ) @@ -268,9 +268,7 @@ async function alarmList (ctx, agg) { async function confirm (ctx) { try { - const { models } = ctx.fs.dc; const { alarmId, content, confirmPost } = ctx.request.body; - const { pepUserId, projectCorrelationIds, alarmInfo } = confirmPost; // TODO: 以视频·应用的秘钥进行鉴权 await ctx.app.fs.vcmpRequest.put('status/alarm/confirm', { data: { @@ -278,28 +276,7 @@ async function confirm (ctx) { } }) - //存日志 - let logDatas = projectCorrelationIds.map(id => { - return { - pepUserId, - projectCorrelationId: id, - alarmInfo,//包含告警id,type,source - confirmTime: moment().format(), - confirmContent: content - } - }) - let rslt = await models.AlarmConfirmLog.bulkCreate(logDatas, { returning: true }); - - //存最新动态 - let dynamics = rslt.map(r => { - return { - time: r.confirmTime, - alarmConfirmId: r.id, - projectCorrelationId: r.projectCorrelationId, - type: 4//告警确认 - } - }) - await models.LatestDynamicList.bulkCreate(dynamics); + await alarmConfirmLog(ctx, confirmPost, content);//告警确认日志 ctx.status = 204; } catch (error) { diff --git a/web/client/src/sections/problem/containers/dataAlarm.jsx b/web/client/src/sections/problem/containers/dataAlarm.jsx index 92689e8..04746d7 100644 --- a/web/client/src/sections/problem/containers/dataAlarm.jsx +++ b/web/client/src/sections/problem/containers/dataAlarm.jsx @@ -37,8 +37,6 @@ const DataAlarm = ({ match, dispatch, actions, user, loading, socket, iotVcmpWeb const [videoModal, setVideoModal] = useState(false) //视频播放弹框 const [videoData, setVideoData] = useState({}) //视频播放参数 const [videoToken, setVideoToken] = useState() //视频token - const [alarmToConfirm, setAlarmToConfirm] = useState(null) //告警确认 - const TextAreaApi = useRef('') @@ -306,15 +304,14 @@ const DataAlarm = ({ match, dispatch, actions, user, loading, socket, iotVcmpWeb name: '操作', sort: 25, value: 'text', render: (_, r, index) => { return
{r.State < 3 || route && ['videoAbnormal', 'useAbnormal'].includes(route) && !r.confirmTime ? - - : r.State == 3 || r.autoRestore || r.confirmAuto ? + + : r.State == 3 || r.autoRestore || r.confirmAuto ? : - - } + + } {route && ['dataLnterrupt', 'dataAbnormal', 'strategyHit', 'deviceAbnormal'].includes(route) ? <> {route == 'deviceAbnormal' ? "" :