|
|
@ -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,13 +35,16 @@ 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, |
|
|
@ -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, |
|
|
|
}; |