You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.4 KiB
57 lines
1.4 KiB
2 years ago
|
'use strict';
|
||
|
const moment = require('moment');
|
||
|
|
||
|
async function record (ctx) {
|
||
|
try {
|
||
|
const { models } = ctx.fs.dc;
|
||
|
const { statusCode, description = '', cameraId, platform = 'yingshi' } = ctx.request.body;
|
||
|
|
||
|
let statusRes = await models.CameraStatus.findOne({
|
||
|
where: {
|
||
|
status: statusCode
|
||
|
}
|
||
|
})
|
||
|
let alarmRes = null;
|
||
|
if (!statusRes) {
|
||
|
statusRes = await models.CameraStatus.create({
|
||
|
platform: platform,
|
||
|
status: statusCode,
|
||
|
describe: description,
|
||
|
forbidden: false,
|
||
|
})
|
||
|
} else {
|
||
|
alarmRes = await models.CameraStatusAlarm.findOne({
|
||
|
where: {
|
||
|
statusId: statusRes.id,
|
||
|
description,
|
||
|
cameraId,
|
||
|
confirm: null
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
if (alarmRes) {
|
||
|
await models.CameraStatusAlarm.update({
|
||
|
updateTime: moment().format()
|
||
|
})
|
||
|
} else {
|
||
|
await models.CameraStatusAlarm.create({
|
||
|
statusId: statusRes.id,
|
||
|
description,
|
||
|
createTime: moment().format(),
|
||
|
cameraId,
|
||
|
})
|
||
|
}
|
||
|
|
||
|
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,
|
||
|
};
|