|
|
@ -1,13 +1,39 @@ |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
async function groupList (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
|
|
|
|
const groupRes = await clickHouse.anxinyun.query(` |
|
|
|
SELECT * FROM t_alarm_group |
|
|
|
`).toPromise();
|
|
|
|
|
|
|
|
for (let g of groupRes) { |
|
|
|
g.unit = await await clickHouse.anxinyun.query(` |
|
|
|
SELECT * FROM t_alarm_group_unit WHERE group_id = ${g.id} |
|
|
|
`).toPromise();
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = groupRes |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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, groupId, groupUnitId, sustainTimeStart, sustainTimeEnd } = ctx.query |
|
|
|
|
|
|
|
const { pepProjectId, groupId, groupUnitId, sustainTimeStart, sustainTimeEnd, limit, page } = ctx.query |
|
|
|
|
|
|
|
const isSuper = judgeSuper(ctx) |
|
|
|
let anxinStrucIds = null |
|
|
@ -19,7 +45,7 @@ async function list (ctx) { |
|
|
|
whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`) |
|
|
|
} |
|
|
|
if (groupId) { |
|
|
|
whereOption.push(`alarms.AlarmGroup=${groupId}`) |
|
|
|
whereOption.push(`alarms.AlarmGroup IN (${groupId})`) |
|
|
|
} |
|
|
|
if (groupUnitId) { |
|
|
|
whereOption.push(`alarms.AlarmGroupUnit=${groupId}`) |
|
|
@ -29,7 +55,7 @@ async function list (ctx) { |
|
|
|
let momentEnd = moment(sustainTimeEnd).format() |
|
|
|
whereOption.push(` |
|
|
|
( |
|
|
|
alarms."StartTime" |
|
|
|
alarms."StartTime" |
|
|
|
BETWEEN '${momentStart}' AND '${momentEnd}' |
|
|
|
OR |
|
|
|
"alarms"."EndTime" BETWEEN '${momentStart}' AND '${momentEnd}' |
|
|
@ -43,26 +69,39 @@ async function list (ctx) { |
|
|
|
} |
|
|
|
const alarmRes = await clickHouse.dataAlarm.query(` |
|
|
|
SELECT |
|
|
|
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 AlarmCodeName, |
|
|
|
alarm_details.Time, alarm_details.Content |
|
|
|
alarms.AlarmId AS AlarmId, |
|
|
|
alarms.State AS State, |
|
|
|
SourceName, StartTime, EndTime, |
|
|
|
alarms.CurrentLevel AS CurrentLevel, |
|
|
|
SourceTypeId, |
|
|
|
AlarmAdviceProblem, AlarmGroup, AlarmGroupUnit, AlarmAdviceProblem, |
|
|
|
${anxinyun}.t_structure.name AS StructureName, |
|
|
|
StructureId, |
|
|
|
${anxinyun}.t_alarm_code.name AS AlarmCodeName |
|
|
|
|
|
|
|
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 ') : ''} |
|
|
|
ORDER BY alarms.StartTime DESC |
|
|
|
${limit ? 'LIMIT ' + limit : ''} |
|
|
|
${limit && page ? 'OFFSET ' + parseInt(limit) * parseInt(page) : ''} |
|
|
|
`).toPromise();
|
|
|
|
|
|
|
|
// alarm_details.Time, alarm_details.Content
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// )
|
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = [] |
|
|
|
ctx.body = alarmRes |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
@ -93,7 +132,51 @@ async function detail (ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function confirm (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
// 发送告警恢复通知
|
|
|
|
// Topic: alarm
|
|
|
|
/* |
|
|
|
* { |
|
|
|
* messageMode: "AlarmManElimination", |
|
|
|
* sourceId: "", |
|
|
|
* alarmTypeCode: "", |
|
|
|
* sponsor: userId, |
|
|
|
* content: "确认消息", |
|
|
|
* time: "YYYY-MM-DDTHH:mm:ss.SSSZ" |
|
|
|
* } |
|
|
|
*/ |
|
|
|
|
|
|
|
ctx.status = 204; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function detailAggregation (ctx) { |
|
|
|
try { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = [] |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
module.exports = { |
|
|
|
list, |
|
|
|
detail |
|
|
|
detail, |
|
|
|
groupList, |
|
|
|
confirm, |
|
|
|
detailAggregation, |
|
|
|
}; |