Browse Source

BI分析数据中断api

dev
wenlele 2 years ago
parent
commit
b4426eead0
  1. 90
      api/app/lib/controllers/control/analysis.js
  2. 4
      api/app/lib/routes/control/index.js

90
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,
};

4
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);
};
Loading…
Cancel
Save