diff --git a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js index 75d0b88..894aa48 100644 --- a/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js +++ b/code/VideoAccess-VCMP/api/app/lib/controllers/status/alarm.js @@ -4,7 +4,7 @@ const moment = require('moment'); async function record (ctx) { try { const { models } = ctx.fs.dc; - const { statusCode, description = '', cameraId, platform = 'yingshi', serialNo, channelNo } = ctx.request.body; + const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; let statusRes = await models.CameraStatus.findOne({ where: { @@ -25,7 +25,6 @@ async function record (ctx) { where: { statusId: statusRes.id, description, - cameraId, confirm: null, serialNo, channelNo, @@ -36,19 +35,22 @@ async function record (ctx) { if (alarmRes) { await models.CameraStatusAlarm.update({ updateTime: moment().format() + }, { + where: { + id: alarmRes.id + } }) } else { alarmRes = await models.CameraStatusAlarm.create({ statusId: statusRes.id, description, createTime: moment().format(), - cameraId, serialNo, channelNo, platform, }) } - + ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); @@ -59,6 +61,32 @@ async function record (ctx) { } } +async function confirm (ctx) { + try { + const { models } = ctx.fs.dc; + const { alarmId, content } = ctx.request.body; + + await models.CameraStatusAlarm.findOne({ + confirm: content, + confirmTime: moment().format(), + }, { + where: { + id: { $in: alarmId }, + confirmTime: null + } + }) + + ctx.status = 204; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + module.exports = { record, + confirm, }; \ No newline at end of file diff --git a/code/VideoAccess-VCMP/api/app/lib/routes/status/index.js b/code/VideoAccess-VCMP/api/app/lib/routes/status/index.js index 07911a9..0349dc1 100644 --- a/code/VideoAccess-VCMP/api/app/lib/routes/status/index.js +++ b/code/VideoAccess-VCMP/api/app/lib/routes/status/index.js @@ -46,4 +46,7 @@ module.exports = function (app, router, opts) { // 状态告警 app.fs.api.logAttr['POST/status/alarm'] = { content: '保存或更新告警信息', visible: false }; router.post('/status/alarm', alarm.record); + + app.fs.api.logAttr['PUT/status/alarm/confirm'] = { content: '确认告警信息', visible: false }; + router.put('/status/alarm/confirm', alarm.confirm); }; diff --git a/code/VideoAccess-VCMP/api/config.js b/code/VideoAccess-VCMP/api/config.js index 7bfbc54..c21ff25 100644 --- a/code/VideoAccess-VCMP/api/config.js +++ b/code/VideoAccess-VCMP/api/config.js @@ -96,6 +96,7 @@ const product = { { p: '/application/check', o: 'GET' }, // 暂时滴 { p: '/status/alarm', o: 'POST' }, { p: '/camera/unique/all', o: 'GET' }, + { p: '/status/alarm/confirm', o: 'PUT' }, ], // 不做认证的路由,也可以使用 exclude: ["*"] 跳过所有路由 redis: { host: IOTA_REDIS_SERVER_HOST,