Browse Source

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

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

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

@ -284,21 +284,42 @@ 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) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { utils: { anxinStrucIdRange, sendAppearToWeb } } = ctx.app.fs
let anxinStruc = await anxinStrucIdRange({ ctx })
const { utils: { sendAppearToWeb } } = ctx.app.fs
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(
`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
if (structId) {
let exist = anxinStruc.find(s => s.strucId == structId);
if (exist) {
let projects = exist.pomsProject.filter(d => !d.del).map(p => p.id);
let datas = projects.map(d => {//需要 项目,告警源,异常类型,时间
return {
@ -324,7 +345,14 @@ async function alarmAdded(ctx) {
await sendAppearToWeb(datas, 'video');
}
}
}
ctx.status = 200;
} else {
ctx.status = 400;
ctx.body = {
message: `获取结构物列表失败`
}
}
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;

Loading…
Cancel
Save