|
@ -6,14 +6,19 @@ async function record (ctx) { |
|
|
const { models } = ctx.fs.dc; |
|
|
const { models } = ctx.fs.dc; |
|
|
const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; |
|
|
const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; |
|
|
|
|
|
|
|
|
let statusRes = await models.CameraStatus.findOne({ |
|
|
// statusCode == 0 是自动恢复
|
|
|
where: { |
|
|
|
|
|
status: statusCode, |
|
|
const isRestore = statusCode == 0 |
|
|
platform, |
|
|
let statusRes = isRestore ? null : |
|
|
} |
|
|
await models.CameraStatus.findOne({ |
|
|
}) |
|
|
where: { |
|
|
|
|
|
status: statusCode, |
|
|
|
|
|
platform, |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
let alarmRes = null; |
|
|
let alarmRes = null; |
|
|
if (!statusRes) { |
|
|
if (!statusRes && !isRestore) { |
|
|
|
|
|
// 没有这种告警状态就新建一个
|
|
|
statusRes = await models.CameraStatus.create({ |
|
|
statusRes = await models.CameraStatus.create({ |
|
|
platform: platform, |
|
|
platform: platform, |
|
|
status: statusCode, |
|
|
status: statusCode, |
|
@ -21,26 +26,43 @@ async function record (ctx) { |
|
|
forbidden: false, |
|
|
forbidden: false, |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
} else { |
|
|
alarmRes = await models.CameraStatusAlarm.findOne({ |
|
|
let findWhere = { |
|
|
where: { |
|
|
confirmTime: null, |
|
|
statusId: statusRes.id, |
|
|
serialNo, |
|
|
description, |
|
|
channelNo, |
|
|
confirm: null, |
|
|
platform, |
|
|
serialNo, |
|
|
} |
|
|
channelNo, |
|
|
if (isRestore) { |
|
|
platform, |
|
|
|
|
|
} |
|
|
} else { |
|
|
|
|
|
findWhere.description = description |
|
|
|
|
|
} |
|
|
|
|
|
if (statusRes) { |
|
|
|
|
|
findWhere.statusId = statusRes.id |
|
|
|
|
|
} |
|
|
|
|
|
alarmRes = await models.CameraStatusAlarm[isRestore ? 'findAll' : 'findOne']({ |
|
|
|
|
|
where: findWhere |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
if (alarmRes) { |
|
|
if ( |
|
|
await models.CameraStatusAlarm.update({ |
|
|
(!isRestore && alarmRes) |
|
|
updateTime: moment().format() |
|
|
|| (isRestore && alarmRes && alarmRes.length) |
|
|
}, { |
|
|
) { |
|
|
|
|
|
let updateD = { |
|
|
|
|
|
updateTime: moment().format(), |
|
|
|
|
|
confirmTime: moment().format(), |
|
|
|
|
|
} |
|
|
|
|
|
if (isRestore) { |
|
|
|
|
|
updateD.autoRestore = true |
|
|
|
|
|
} |
|
|
|
|
|
await models.CameraStatusAlarm.update(updateD, { |
|
|
where: { |
|
|
where: { |
|
|
id: alarmRes.id |
|
|
id: { |
|
|
|
|
|
$in: isRestore ? alarmRes.map(a => a.id) : [alarmRes.id] |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
} else { |
|
|
} else if (!isRestore) { |
|
|
alarmRes = await models.CameraStatusAlarm.create({ |
|
|
alarmRes = await models.CameraStatusAlarm.create({ |
|
|
statusId: statusRes.id, |
|
|
statusId: statusRes.id, |
|
|
description, |
|
|
description, |
|
|