运维服务中台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7 KiB

2 years ago
'use strict';
async function list (ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config
const { pepProjectId } = ctx.query
2 years ago
const isSuper = judgeSuper(ctx)
let anxinStrucIds = null
if (!isSuper || pepProjectId) {
anxinStrucIds = await anxinStrucIdRange({ ctx, pepProjectId })
}
const alarmRes = await clickHouse.dataAlarm.query(`
SELECT
AlarmId, SourceName, name AS StructureName, StructureId
FROM
alarms
LEFT JOIN ${anxinyun}.t_structure
ON ${anxinyun}.t_structure.id = alarms.StructureId
${anxinStrucIds ? 'WHERE ' + anxinyun + '.t_structure.id IN (' + anxinStrucIds.join(",") + ')' : ''}
`).toPromise();
ctx.status = 200;
ctx.body = []
2 years ago
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function detail (ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { alarmId } = ctx.query
const detailRes = await clickHouse.dataAlarm.query(`
SELECT * FROM alarm_details WHERE AlarmId = '${alarmId}' ORDER BY Time ASC
`).toPromise()
ctx.status = 200;
ctx.body = detailRes
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
2 years ago
module.exports = {
list,
detail
2 years ago
};