|
|
@ -6,21 +6,38 @@ 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 } = ctx.query |
|
|
|
const { pepProjectId, groupId, sustainTimeStart, sustainTimeEnd } = ctx.query |
|
|
|
|
|
|
|
const isSuper = judgeSuper(ctx) |
|
|
|
let anxinStrucIds = null |
|
|
|
if (!isSuper || pepProjectId) { |
|
|
|
anxinStrucIds = await anxinStrucIdRange({ ctx, pepProjectId }) |
|
|
|
} |
|
|
|
let whereOption = [] |
|
|
|
if (anxinStrucIds) { |
|
|
|
whereOption.push(`${anxinyun}.t_structure.id IN (${anxinStrucIds.join(",")})`) |
|
|
|
} |
|
|
|
if (groupId) { |
|
|
|
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`) |
|
|
|
} |
|
|
|
if (groupUnitId) { |
|
|
|
whereOption.push(`${anxinyun}.t_alarm_code.alarm_group=${groupId}`) |
|
|
|
} |
|
|
|
if (sustainTimeStart && sustainTimeEnd) { |
|
|
|
whereOption.push(``) |
|
|
|
} |
|
|
|
const alarmRes = await clickHouse.dataAlarm.query(` |
|
|
|
SELECT |
|
|
|
AlarmId, SourceName, name AS StructureName, StructureId |
|
|
|
AlarmId, SourceName, |
|
|
|
${anxinyun}.t_structure.name AS StructureName, StructureId, |
|
|
|
${anxinyun}.t_alarm_code.name AS AlarmCodeDescribe |
|
|
|
FROM |
|
|
|
alarms |
|
|
|
LEFT JOIN ${anxinyun}.t_structure |
|
|
|
ON ${anxinyun}.t_structure.id = alarms.StructureId |
|
|
|
${anxinStrucIds ? 'WHERE ' + anxinyun + '.t_structure.id IN (' + anxinStrucIds.join(",") + ')' : ''} |
|
|
|
LEFT JOIN ${anxinyun}.t_alarm_code |
|
|
|
ON ${anxinyun}.t_alarm_code.code = alarms.AlarmTypeCode |
|
|
|
${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} |
|
|
|
`).toPromise();
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|