From 36ebb0f66b3c312f73069738d6e2de10584e1c7c Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Mon, 26 Sep 2022 10:48:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=8A=E8=AD=A6->=E8=AF=A6=E6=83=85=E6=95=B0?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/data.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index 9d4a0c5..b3196e1 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/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 {