Browse Source

(*)视频告警新增接口修改

dev
wuqun 2 years ago
parent
commit
a45bdf0ff6
  1. 90
      api/app/lib/controllers/alarm/video.js

90
api/app/lib/controllers/alarm/video.js

@ -284,47 +284,75 @@ async function confirm(ctx) {
} }
} }
let structsAche = {
dataList: [],
expireTime: null//10分钟更新一次结构物列表
}
async function getStructsAche(ctx) {
const { utils: { getAxyStructs } } = ctx.app.fs
try {
if (!structsAche.dataList.length || moment() > moment(structsAche.expireTime)) {
let structList = await getAxyStructs();
structsAche.dataList = structList;
structsAche.expireTime = moment().add(10, 'minute').format('YYYY-MM-DD HH:mm:ss');
}
return structsAche;
} catch (err) {
console.log(`获取结构物列表失败, error: ${err}`);
}
}
async function alarmAdded(ctx) { async function alarmAdded(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { utils: { anxinStrucIdRange, sendAppearToWeb } } = ctx.app.fs const { utils: { sendAppearToWeb } } = ctx.app.fs
let anxinStruc = await anxinStrucIdRange({ ctx })
const { serial_no, channel_no, create_time, description, status_id } = ctx.request.body; let structsAche = await getStructsAche(ctx);
if (structsAche) {
let anxinStruc = structsAche.dataList;//结构物列表
const { serial_no, channel_no, create_time, description, status_id } = ctx.request.body;
let belongToStruct = await clickHouse.anxinyun.query( let belongToStruct = await clickHouse.anxinyun.query(
`SELECT name, structure FROM t_video_ipc WHERE serial_no='${serial_no}' and channel_no='${channel_no}'`).toPromise() `SELECT name, structure FROM t_video_ipc WHERE serial_no='${serial_no}' and channel_no=${parseInt(channel_no)}`).toPromise()
let structId = belongToStruct.length ? belongToStruct[0].structure : null let structId = belongToStruct.length ? belongToStruct[0].structure : null
if (structId) { if (structId) {
let exist = anxinStruc.find(s => s.strucId == structId); let exist = anxinStruc.find(s => s.strucId == structId);
let projects = exist.pomsProject.filter(d => !d.del).map(p => p.id); if (exist) {
let datas = projects.map(d => {//需要 项目,告警源,异常类型,时间 let projects = exist.pomsProject.filter(d => !d.del).map(p => p.id);
return { let datas = projects.map(d => {//需要 项目,告警源,异常类型,时间
projectCorrelationId: d, return {
alarmInfo: { messageMode: 'AlarmGeneration', sourceName: belongToStruct[0].name, status_id, content: description },//AlarmGeneration代表告警首次产生 projectCorrelationId: d,
time: create_time, alarmInfo: { messageMode: 'AlarmGeneration', sourceName: belongToStruct[0].name, status_id, content: description },//AlarmGeneration代表告警首次产生
type: description time: create_time,
} type: description
}) }
let rslt = await models.AlarmAppearRecord.bulkCreate(datas, { returning: true }); })
let dynamics = rslt.map(r => { let rslt = await models.AlarmAppearRecord.bulkCreate(datas, { returning: true });
return { let dynamics = rslt.map(r => {
time: r.time, return {
alarmAppearId: r.id, time: r.time,
projectCorrelationId: r.projectCorrelationId, alarmAppearId: r.id,
type: 1//发现 projectCorrelationId: r.projectCorrelationId,
} type: 1//发现
}) }
await models.LatestDynamicList.bulkCreate(dynamics); })
await models.LatestDynamicList.bulkCreate(dynamics);
//消息推送到前端 //消息推送到前端
if (datas.length) { if (datas.length) {
await sendAppearToWeb(datas, 'video'); await sendAppearToWeb(datas, 'video');
}
}
}
ctx.status = 200;
} else {
ctx.status = 400;
ctx.body = {
message: `获取结构物列表失败`
} }
} }
ctx.status = 200;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400; ctx.status = 400;

Loading…
Cancel
Save