From 537f9d1e773afa1122b1a71b39db04a559746261 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Wed, 21 Sep 2022 17:10:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=95=B0=E6=8D=AE=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/alarm/app.js | 8 ++++--- api/app/lib/controllers/alarm/data.js | 31 +++++++++++++++++++++++---- api/app/lib/routes/alarm/index.js | 3 +++ api/app/lib/utils/dataRange.js | 5 +++-- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 32e3e1c..7600c14 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -235,10 +235,12 @@ async function apiErrorList (ctx) { } if (errType) { - if (errType = 'element') { + if (errType == 'element') { + findOption.where.screenshot = { $ne: null } + } else if (errType == 'timeout') { + + } else if (errType == 'apiError') { findOption.where.screenshot = null - } else { - findOption.where.statusCode = errType } } if (confirmState) { diff --git a/api/app/lib/controllers/alarm/data.js b/api/app/lib/controllers/alarm/data.js index d57245a..3618f3a 100644 --- a/api/app/lib/controllers/alarm/data.js +++ b/api/app/lib/controllers/alarm/data.js @@ -6,15 +6,16 @@ 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 isSuper = judgeSuper(ctx) let anxinStrucIds = null - if (!isSuper) { - anxinStrucIds = await anxinStrucIdRange(ctx) + if (!isSuper || pepProjectId) { + anxinStrucIds = await anxinStrucIdRange({ ctx, pepProjectId }) } const alarmRes = await clickHouse.dataAlarm.query(` SELECT - AlarmId, SourceName, name + AlarmId, SourceName, name AS StructureName, StructureId FROM alarms LEFT JOIN ${anxinyun}.t_structure @@ -33,6 +34,28 @@ async function list (ctx) { } } +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 + } + } +} + module.exports = { - list + list, + detail }; \ No newline at end of file diff --git a/api/app/lib/routes/alarm/index.js b/api/app/lib/routes/alarm/index.js index 9fe8165..c535a31 100644 --- a/api/app/lib/routes/alarm/index.js +++ b/api/app/lib/routes/alarm/index.js @@ -28,4 +28,7 @@ module.exports = function (app, router, opts) { // 数据告警 app.fs.api.logAttr['GET/alarm/data/list'] = { content: '查询数据告警列表', visible: true }; router.get('/alarm/data/list', dataAlarm.list); + + app.fs.api.logAttr['GET/alarm/data/detail'] = { content: '查询数据告警详情', visible: true }; + router.get('/alarm/data/detail', dataAlarm.detail); }; diff --git a/api/app/lib/utils/dataRange.js b/api/app/lib/utils/dataRange.js index 0c2d515..7a605d2 100644 --- a/api/app/lib/utils/dataRange.js +++ b/api/app/lib/utils/dataRange.js @@ -14,15 +14,16 @@ module.exports = function (app, opts) { } } - async function anxinStrucIdRange (ctx) { + async function anxinStrucIdRange ({ ctx, pepProjectId }) { try { const { models } = ctx.fs.dc; const { userInfo = {} } = ctx.fs.api || {}; const { correlationProject = [] } = userInfo + // TODO 这儿也许需要判断传进来的 pepProjectId 在不在当前用户的关注范围内 const bindRes = await models.ProjectCorrelation.findAll({ where: { - id: { $in: correlationProject }, + id: { $in: pepProjectId ? [pepProjectId] : correlationProject }, del: false } })