Browse Source

(*)数据告警, 应用告警, 视频告警确认日志记录

dev
wuqun 2 years ago
parent
commit
75ce97f64a
  1. 49
      api/app/lib/controllers/alarm/alarmConfirmLog.js
  2. 27
      api/app/lib/controllers/alarm/app.js
  3. 6
      api/app/lib/controllers/alarm/data.js
  4. 29
      api/app/lib/controllers/alarm/video.js
  5. 47
      web/client/src/sections/problem/containers/dataAlarm.jsx

49
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
};

27
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) {

6
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}`);

29
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) {

47
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 <div style={{ width: 195 }}>
{r.State < 3 || route && ['videoAbnormal', 'useAbnormal'].includes(route) && !r.confirmTime ?
<Button theme='borderless' style={{ width: 65 }} onClick={() => {
setConfirm(true)
setSelected([r.key])
setAlarmToConfirm(r)
}}>确认</Button>
: r.State == 3 || r.autoRestore || r.confirmAuto ?
<Button theme='borderless' style={{ width: 65 }} onClick={() => {
setConfirm(true)
setSelected([r.key])
}}>确认</Button>
: r.State == 3 || r.autoRestore || r.confirmAuto ?
<Button theme='borderless' style={{ width: 65 }} disabled>自动恢复</Button> :
<Button theme='borderless' style={{ width: 65 }} disabled>已确认</Button>
}
<Button theme='borderless' style={{ width: 65 }} disabled>已确认</Button>
}
{route && ['dataLnterrupt', 'dataAbnormal', 'strategyHit', 'deviceAbnormal'].includes(route) ? <>
<Button theme='borderless' style={{ width: 65 }} disabled>已派单</Button>
{route == 'deviceAbnormal' ? "" : <Button theme='borderless' style={{ width: 65 }} onClick={() => {
@ -384,18 +381,24 @@ const DataAlarm = ({ match, dispatch, actions, user, loading, socket, iotVcmpWeb
// console.log(selected);
const getAlarmConfirmItem = () => {
let source = route == 'useAbnormal' ? alarmToConfirm.appName : alarmToConfirm.SourceName;
let type = route == 'useAbnormal' ? alarmToConfirm.type : route == 'videoAbnormal' ? alarmToConfirm.AlarmContent : alarmToConfirm.AlarmGroupUnit;
return {
pepUserId: user.pomsUserInfo.pepUserId,
projectCorrelationIds: alarmToConfirm?.projectName?.map(p => p.id),
alarmInfo: {
id: alarmToConfirm.key,
source: source,//
type: type,//
const getAlarmConfirmItems = () => {
let confirmItems = [];
selected.map(s => {
let alarmInfo = tableData.find(td => td.key == s);
let source = route == 'useAbnormal' ? alarmInfo.appName : alarmInfo.SourceName;
let type = route == 'useAbnormal' ? alarmInfo.type : route == 'videoAbnormal' ? alarmInfo.AlarmContent : alarmInfo.AlarmGroupUnit;
let item = {
pepUserId: user.pomsUserInfo.pepUserId,
projectCorrelationIds: alarmInfo?.projectName?.map(p => p.id),
alarmInfo: {
id: alarmInfo.key,
source: source,//
type: type,//
}
}
};
confirmItems.push(item);
})
return confirmItems;
}
return (
@ -457,7 +460,7 @@ const DataAlarm = ({ match, dispatch, actions, user, loading, socket, iotVcmpWeb
width={600}
onCancel={() => setConfirm(false)}
onOk={() => {
let confirmPost = getAlarmConfirmItem();
let confirmPost = getAlarmConfirmItems();
if (route == 'useAbnormal') {
TextAreaApi.current.validate().then((v) => {
dispatch(problem.postApiConfirm({ appAlarmId: selected, confirm: content, confirmPost })).then(res => {

Loading…
Cancel
Save