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 ac4aeb6..162f7f6 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'); const csData = require('../../controllers/control/data'); module.exports = function (app, router, opts) { @@ -16,6 +17,8 @@ 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);