|
|
@ -6,7 +6,8 @@ async function list (ctx) { |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs |
|
|
|
const { database: anxinyun } = clickHouse.anxinyun.opts.config |
|
|
|
const { pepProjectId, groupId, sustainTimeStart, sustainTimeEnd } = ctx.query |
|
|
|
|
|
|
|
const { pepProjectId, groupId, groupUnitId, sustainTimeStart, sustainTimeEnd } = ctx.query |
|
|
|
|
|
|
|
const isSuper = judgeSuper(ctx) |
|
|
|
let anxinStrucIds = null |
|
|
@ -15,28 +16,48 @@ async function list (ctx) { |
|
|
|
} |
|
|
|
let whereOption = [] |
|
|
|
if (anxinStrucIds) { |
|
|
|
whereOption.push(`${anxinyun}.t_structure.id IN (${anxinStrucIds.join(",")})`) |
|
|
|
whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`) |
|
|
|
} |
|
|
|
if (groupId) { |
|
|
|
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`) |
|
|
|
whereOption.push(`alarms.AlarmGroup=${groupId}`) |
|
|
|
} |
|
|
|
if (groupUnitId) { |
|
|
|
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`) |
|
|
|
whereOption.push(`alarms.AlarmGroupUnit=${groupId}`) |
|
|
|
} |
|
|
|
if (sustainTimeStart && sustainTimeEnd) { |
|
|
|
whereOption.push(``) |
|
|
|
let momentStart = moment(sustainTimeStart).format() |
|
|
|
let momentEnd = moment(sustainTimeEnd).format() |
|
|
|
whereOption.push(` |
|
|
|
( |
|
|
|
alarms."StartTime" |
|
|
|
BETWEEN '${momentStart}' AND '${momentEnd}' |
|
|
|
OR |
|
|
|
"alarms"."EndTime" BETWEEN '${momentStart}' AND '${momentEnd}' |
|
|
|
OR ( |
|
|
|
"alarms"."StartTime" <= '${momentStart}' |
|
|
|
AND |
|
|
|
"alarms"."EndTime" >= '${momentEnd}' |
|
|
|
) |
|
|
|
) |
|
|
|
`)
|
|
|
|
} |
|
|
|
const alarmRes = await clickHouse.dataAlarm.query(` |
|
|
|
SELECT |
|
|
|
AlarmId, SourceName, |
|
|
|
alarms.AlarmId, alarms.State, SourceName, StartTime, EndTime, alarms.CurrentLevel, SourceTypeId, AlarmAdviceProblem,AlarmGroup, AlarmGroupUnit, AlarmAdviceProblem, |
|
|
|
${anxinyun}.t_structure.name AS StructureName, StructureId, |
|
|
|
${anxinyun}.t_alarm_code.name AS AlarmCodeDescribe |
|
|
|
${anxinyun}.t_alarm_code.name AS AlarmCodeName, |
|
|
|
alarm_details.Time, alarm_details.Content |
|
|
|
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 alarm_details |
|
|
|
ON alarms.AlarmId = alarm_details.AlarmId |
|
|
|
AND alarm_details.Time = ( |
|
|
|
SELECT MAX(alarm_details.Time) from alarm_details WHERE AlarmId = alarms.AlarmId |
|
|
|
) |
|
|
|
${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} |
|
|
|
`).toPromise();
|
|
|
|
|
|
|
|