Browse Source

应用告警自动恢复

dev
巴林闲侠 2 years ago
parent
commit
e311cc6065
  1. 64
      api/app/lib/controllers/alarm/app.js
  2. 4
      api/app/lib/controllers/alarm/video.js

64
api/app/lib/controllers/alarm/app.js

@ -140,33 +140,55 @@ async function apiError (ctx) {
throw '请标明告警类型 type'
}
let storageData = {
projectAppId, alarmContent, router, statusCode, type
}
const existRes = await models.AppAlarm.findOne({
where: {
projectAppId, alarmContent, router, statusCode,
confirm: null, type
}
})
if (existRes) {
await models.AppAlarm.update({
updateTime: now
}, {
const isRestore = statusCode == 200 || statusCode == 204
if (isRestore) {
const existRes = await models.AppAlarm.findAll({
where: {
id: existRes.id
projectAppId, router,
confirmTime: null, type
}
})
if (existRes.length) {
await models.AppAlarm.update({
updateTime: now,
confirmTime: now,
confirmAuto: true,
}, {
where: {
id: { $in: existRes.map(e => e.id) }
}
})
}
} else {
const existCount = await models.AppAlarm.count({
let storageData = {
projectAppId, alarmContent, router, statusCode, type
}
const existRes = await models.AppAlarm.findOne({
where: {
projectAppId, alarmContent, router, statusCode,
confirmTime: null, type,
}
})
storageData.serialNumber = 'WEB' + (existCount < 9 ? '0' + (existCount + 1) : existCount)
storageData.createTime = now
storageData.screenshot = screenshot
await models.AppAlarm.create(storageData)
if (existRes) {
await models.AppAlarm.update({
updateTime: now
}, {
where: {
id: existRes.id
}
})
} else {
const existCount = await models.AppAlarm.count({
where: {
}
})
storageData.serialNumber = 'WEB' + (existCount < 9 ? '0' + (existCount + 1) : existCount)
storageData.createTime = now
storageData.screenshot = screenshot
await models.AppAlarm.create(storageData)
}
}
ctx.status = 200;
@ -248,7 +270,7 @@ async function apiErrorList (ctx) {
// findOption.where.screenshot = null
// }
// }
if(errType){
if (errType) {
findOption.where.type = errType
}
if (confirmState) {

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

@ -83,6 +83,7 @@ async function alarmList (ctx) {
cameraAlarm.platform AS platform,
cameraAlarm.confirmContent AS confirmContent,
cameraAlarm.confirmTime AS confirmTime,
cameraAlarm.autoRestore AS autoRestore,
camera_status_resolve.id AS resolveId,
camera_status.describe AS statusDescribe,
camera_status_resolve.resolve AS resolve,
@ -109,7 +110,8 @@ async function alarmList (ctx) {
camera_status_alarm.serial_no AS cameraSerialNo,
camera_status_alarm.channel_no AS cameraChannelNo,
camera_status_alarm.confirm AS confirmContent,
camera_status_alarm.confirm_time AS confirmTime
camera_status_alarm.confirm_time AS confirmTime,
camera_status_alarm.auto_restore AS autoRestore
FROM camera_status_alarm
LEFT JOIN camera
ON camera.serial_no = camera_status_alarm.serial_no

Loading…
Cancel
Save