From b4426eead0ffae1e5f5d8e54a1a6bb9c39d1a4dc Mon Sep 17 00:00:00 2001 From: wenlele Date: Tue, 25 Oct 2022 10:11:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?BI=E5=88=86=E6=9E=90=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=B8=AD=E6=96=ADapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/control/analysis.js | 90 +++++++++++++++++++++ api/app/lib/routes/control/index.js | 4 + 2 files changed, 94 insertions(+) create mode 100644 api/app/lib/controllers/control/analysis.js diff --git a/api/app/lib/controllers/control/analysis.js b/api/app/lib/controllers/control/analysis.js new file mode 100644 index 0000000..e6e741f --- /dev/null +++ b/api/app/lib/controllers/control/analysis.js @@ -0,0 +1,90 @@ +'use strict'; +const moment = require('moment'); + +async function dataList (ctx) { + try { + const { models } = ctx.fs.dc; + const { userId, pepUserId, userInfo = {}, pepUserInfo } = ctx.fs.api + const { clickHouse } = ctx.app.fs + const { utils: { judgeSuper, anxinStrucIdRange, pomsProjectRange } } = ctx.app.fs + const { database: anxinyun } = clickHouse.anxinyun.opts.config + const { pepProjectId } = ctx.request.query + + + let anxinStruc = await anxinStrucIdRange({ + ctx, pepProjectId + }) + let pomsProject = await pomsProjectRange({ + ctx, pepProjectId, + }) + const pomsProjectIds = pomsProject.map(p => p.id) + + if (anxinStruc.length) { + + const anxinStrucIds = anxinStruc.map(a => a.strucId) || [] + + const dataAlarm = await clickHouse.dataAlarm.query(` + SELECT + formatDateTime(alarmData.StartTime,'%F %H') hours, count(AlarmId) count + FROM + ( SELECT + AlarmId,State,StartTime + FROM + alarms + WHERE + alarms.StructureId IN (${anxinStrucIds.join(",")}) + AND + AlarmGroup = 3) AS alarmData + GROUP BY hours + `).toPromise(); + + // const confirmedAlarm = dataAlarm + // // TODO: 开发临时注释 + // .filter(ar => ar.State && ar.State > 2) + // .map(ar => "'" + ar.AlarmId + "'") + + // // formatDateTime(Time,'%F %H') hours, count(AlarmId) count + + // const dataConfirme = confirmedAlarm.length ? + // await clickHouse.dataAlarm.query(` + // SELECT + // max(Time) AS Time, AlarmId + // FROM + // alarm_details + // WHERE + // AlarmId IN (${confirmedAlarm.join(',')}) + // GROUP BY AlarmId + // `).toPromise() : + // []; + + + // dataAlarm.forEach(ar => { + // ar.confirme = + // dataConfirme.find(as => as.AlarmId == ar.AlarmId) || {} + + // }) + ctx.status = 200 + ctx.body = dataAlarm + } else { + ctx.status = 200 + ctx.body = { + dataAlarm: 0, + } + } + + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + message: typeof error == 'string' ? error : undefined + } + } +} + + + + + +module.exports = { + dataList, +}; \ No newline at end of file diff --git a/api/app/lib/routes/control/index.js b/api/app/lib/routes/control/index.js index 70b54c3..eb4da40 100644 --- a/api/app/lib/routes/control/index.js +++ b/api/app/lib/routes/control/index.js @@ -1,6 +1,7 @@ 'use strict'; const toolLink = require('../../controllers/control/toolLink'); +const analysis = require('../../controllers/control/analysis'); module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/console/toollink'] = { content: '获取常用工具', visible: true }; @@ -14,4 +15,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/console/count'] = { content: '查询告警数量', visible: true }; router.get('/console/count', toolLink.count); + + app.fs.api.logAttr['GET/analysis/dataList'] = { content: '查询数据告警产生,确认数量', visible: true }; + router.get('/analysis/dataList', analysis.dataList); }; \ No newline at end of file From b5a10dbeaeaf181e59cde6ae5e96611b043458bd Mon Sep 17 00:00:00 2001 From: wenlele Date: Tue, 25 Oct 2022 10:14:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/api/package.json b/api/package.json index cffb191..4d3e893 100644 --- a/api/package.json +++ b/api/package.json @@ -34,6 +34,7 @@ "pg": "^7.9.0", "redis": "^3.1.2", "request": "^2.88.2", + "sequelize-automate-freesun": "^1.2.2", "superagent": "^3.5.2", "uuid": "^3.3.2" },