Browse Source

(*)控制台-BI分析模块-应用异常图表数据获取

dev
wuqun 2 years ago
parent
commit
0d29381b6a
  1. 63
      api/app/lib/controllers/control/data.js

63
api/app/lib/controllers/control/data.js

@ -1,23 +1,6 @@
'use strict';
const moment = require('moment');
const { alarmList } = require('../alarm/video');
const { inspectionList } = require('../alarm/app');
//工作台
async function getWorkbench(ctx) {
try {
const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs
const { alarmId, limit, page } = ctx.query
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
}
}
}
//项目概览
async function getProjectsInfo(ctx) {
@ -112,7 +95,7 @@ async function queryAlarm(ctx, alarmQueryOptionStr, type) {
const { clickHouse } = ctx.app.fs
try {
const alarmRes = await clickHouse.dataAlarm.query(`
select days, sum(count) total, sum(done) done from (
select days day, sum(count) total, sum(done) done from (
SELECT formatDateTime(StartTime,'%F') days, count(AlarmId) count, 0 done from
(SELECT
@ -145,8 +128,49 @@ async function queryAlarm(ctx, alarmQueryOptionStr, type) {
//BI分析-应用异常
async function getAppAlarmsAggDay(ctx) {
try {
let appAlarms = await inspectionList(ctx, 'day');
const models = ctx.fs.dc.models;
const { utils: { pomsProjectRange } } = ctx.app.fs
const { pepProjectId } = ctx.query
let pomsProject = await pomsProjectRange({
ctx, pepProjectId
})
const pomsProjectIds = pomsProject.map(p => p.id)
let findOption = {
where: {
createTime: { $gte: moment().add(-1, 'year').format() },//最近一年
},
attributes: ['id', 'createTime', 'confirmTime'],
include: [{
model: models.App,
attributes: {
exclude: ['projectId']
},
include: [{
model: models.ProjectCorrelation,
attributes: {
exclude: ['id']
},
}]
}]
}
findOption.where['$app->projectCorrelations.id$'] = {
$in: pomsProjectIds
}
const listRes = await models.AppAlarm.findAll(findOption)
let aggDayMap = [];
for (let a of listRes) {
let exist = aggDayMap.find(ad => ad.day == moment(a.createTime).format('YYYY-MM-DD'));
if (exist) {
exist.total++;//总数
if (a.confirmTime) {
exist.done++;//已恢复
}
} else {
aggDayMap.push({ day: moment(a.createTime).format('YYYY-MM-DD'), total: 1, done: a.confirmTime ? 1 : 0 });
}
}
aggDayMap.sort((a, b) => moment(a.day) - moment(b.day));//升序
ctx.status = 200;
ctx.body = aggDayMap;
} catch (error) {
@ -279,7 +303,6 @@ async function getLatestDynamic(ctx) {
}
module.exports = {
getWorkbench,
getProjectsInfo,
getDataAlarmsAggDay,

Loading…
Cancel
Save