Browse Source

告警数量返回

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

37
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(` const alarmRes = await clickHouse.dataAlarm.query(`
SELECT SELECT
alarms.AlarmId AS AlarmId, alarms.AlarmId AS AlarmId,
@ -92,15 +103,7 @@ async function list (ctx) {
${anxinyun}.t_structure.name AS StructureName, ${anxinyun}.t_structure.name AS StructureName,
${anxinyun}.t_alarm_code.name AS AlarmCodeName, ${anxinyun}.t_alarm_code.name AS AlarmCodeName,
AlarmContent AlarmContent
FROM ${alarmQueryOptionStr}
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 ') : ''}
ORDER BY alarms.StartTime DESC ORDER BY alarms.StartTime DESC
${limit ? 'LIMIT ' + limit : ''} ${limit ? 'LIMIT ' + limit : ''}
${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''} ${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''}
@ -114,6 +117,12 @@ async function list (ctx) {
// SourceType 0: 'DTU' / 1: '传感器' / 2: '测点' // SourceType 0: 'DTU' / 1: '传感器' / 2: '测点'
const countAlarm = await clickHouse.dataAlarm.query(`
SELECT
count(alarms.AlarmId) AS count
${alarmQueryOptionStr}
`).toPromise();
const confirmedAlarm = alarmRes const confirmedAlarm = alarmRes
// TODO: 开发临时注释 // TODO: 开发临时注释
// .filter(ar => ar.State && ar.State > 2) // .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 ar.detailCount = (alarmDetailCount.find(adc => adc.AlarmId == ar.AlarmId) || { count: 0 }).count
}) })
ctx.body = alarmRes ctx.body = {
count: countAlarm[0].count,
rows: alarmRes
}
} else { } else {
ctx.body = [] ctx.body = {
count: 0,
rows: []
}
} }
ctx.status = 200; ctx.status = 200;
} catch (error) { } catch (error) {

Loading…
Cancel
Save