Browse Source

告警->详情数量

dev
巴林闲侠 2 years ago
parent
commit
36ebb0f66b
  1. 23
      api/app/lib/controllers/alarm/data.js

23
api/app/lib/controllers/alarm/data.js

@ -97,6 +97,11 @@ async function list (ctx) {
${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''}
`).toPromise();
// State = 3 是 自动恢复 / 4 是 人工恢复 / 其他数字 是 需要恢复
// state = 2 是 等级提升 / 1 是持续产生 / 0 是首次产生
// SourceType 0: 'DTU' / 1: '传感器' / 2: '测点'
const confirmedAlarm = alarmRes
// TODO: 开发临时注释
// .filter(ar => ar.State && ar.State > 2)
@ -113,9 +118,17 @@ async function list (ctx) {
`).toPromise() :
[];
// State = 3 是 自动恢复 / 4 是 人工恢复 / 其他数字 是 需要恢复
// state = 2 是 等级提升 / 1 是持续产生 / 0 是首次产生
// SourceType 0: 'DTU' / 1: '传感器' / 2: '测点'
const alarmDetailCount = await clickHouse.dataAlarm.query(`
SELECT
count(Time) AS count, AlarmId
FROM
alarm_details
WHERE
AlarmId IN (${confirmedAlarm.join(',')})
AND AlarmState < 3
GROUP BY AlarmId
`).toPromise()
alarmRes.forEach(ar => {
ar.pepProject = (anxinStruc.find(as => as.strucId == ar.StructureId) ||
@ -133,6 +146,7 @@ async function list (ctx) {
]
}).pepProject
// 最新告警详情 - 确认信息
let corConfirmedData = (confirmedAlarmDetailMax.find(cdm => cdm.AlarmId == ar.AlarmId) || {});
if (corConfirmedData.AlarmState && corConfirmedData.AlarmState > 2) {
@ -141,6 +155,9 @@ async function list (ctx) {
}
ar.confirmedContent = 'corConfirmedData.Content'
ar.confirmedTime = 'corConfirmedData.Time'
// 告警详情的数量
ar.detailCount = (alarmDetailCount.find(adc => adc.AlarmId == ar.AlarmId) || { count: 0 }).count
})
ctx.body = alarmRes
} else {

Loading…
Cancel
Save