From 0d29381b6a567b28bd6cbb94040f7da108a56ebc Mon Sep 17 00:00:00 2001 From: wuqun Date: Tue, 25 Oct 2022 16:20:42 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E6=8E=A7=E5=88=B6=E5=8F=B0-BI=E5=88=86?= =?UTF-8?q?=E6=9E=90=E6=A8=A1=E5=9D=97-=E5=BA=94=E7=94=A8=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E5=9B=BE=E8=A1=A8=E6=95=B0=E6=8D=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/control/data.js | 63 +++++++++++++++++-------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/api/app/lib/controllers/control/data.js b/api/app/lib/controllers/control/data.js index d3b8511..26f1fcf 100644 --- a/api/app/lib/controllers/control/data.js +++ b/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,