diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index 77cc073..beb2ce0 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -80,6 +80,17 @@ async function list (ctx) { } } + let alarmQueryOptionStr = ` + FROM + alarms + LEFT JOIN ${anxinyun}.t_structure + ON ${anxinyun}.t_structure.id = alarms.StructureId + LEFT JOIN ${anxinyun}.t_alarm_code + ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode + LEFT JOIN ${anxinyun}.t_alarm_type + ON ${anxinyun}.t_alarm_type.id = alarms.AlarmTypeId + ${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} + ` const alarmRes = await clickHouse.dataAlarm.query(` SELECT alarms.AlarmId AS AlarmId, @@ -92,15 +103,7 @@ async function list (ctx) { ${anxinyun}.t_structure.name AS StructureName, ${anxinyun}.t_alarm_code.name AS AlarmCodeName, AlarmContent - FROM - alarms - LEFT JOIN ${anxinyun}.t_structure - ON ${anxinyun}.t_structure.id = alarms.StructureId - LEFT JOIN ${anxinyun}.t_alarm_code - ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode - LEFT JOIN ${anxinyun}.t_alarm_type - ON ${anxinyun}.t_alarm_type.id = alarms.AlarmTypeId - ${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} + ${alarmQueryOptionStr} ORDER BY alarms.StartTime DESC ${limit ? 'LIMIT ' + limit : ''} ${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''} @@ -114,6 +117,12 @@ async function list (ctx) { // SourceType 0: 'DTU' / 1: '传感器' / 2: '测点' + const countAlarm = await clickHouse.dataAlarm.query(` + SELECT + count(alarms.AlarmId) AS count + ${alarmQueryOptionStr} + `).toPromise(); + const confirmedAlarm = alarmRes // TODO: 开发临时注释 // .filter(ar => ar.State && ar.State > 2) @@ -173,9 +182,15 @@ async function list (ctx) { // 告警详情的数量 ar.detailCount = (alarmDetailCount.find(adc => adc.AlarmId == ar.AlarmId) || { count: 0 }).count }) - ctx.body = alarmRes + ctx.body = { + count: countAlarm[0].count, + rows: alarmRes + } } else { - ctx.body = [] + ctx.body = { + count: 0, + rows: [] + } } ctx.status = 200; } catch (error) {