|
|
@ -1,6 +1,7 @@ |
|
|
|
'use strict'; |
|
|
|
const moment = require('moment'); |
|
|
|
const { alarmList } = require('../alarm/video'); |
|
|
|
const { inspectionList } = require('../alarm/app'); |
|
|
|
//工作台
|
|
|
|
async function getWorkbench(ctx) { |
|
|
|
try { |
|
|
@ -67,7 +68,97 @@ async function getProjectsInfo(ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//BI分析
|
|
|
|
//BI分析-数据
|
|
|
|
async function getDataAlarmsAggDay(ctx) { |
|
|
|
try { |
|
|
|
const { utils: { anxinStrucIdRange } } = ctx.app.fs |
|
|
|
const { pepProjectId } = ctx.query |
|
|
|
|
|
|
|
let dataAbnormal = [], dataInterrupt = [], policyHit = [], deviceAbnormal = []; |
|
|
|
let anxinStruc = await anxinStrucIdRange({ |
|
|
|
ctx, pepProjectId |
|
|
|
}) |
|
|
|
let whereOption = [] |
|
|
|
// ! 1 开发临时增加
|
|
|
|
if (anxinStruc.length) { |
|
|
|
const anxinStrucIds = anxinStruc.map(a => a.strucId) |
|
|
|
// ! 开发临时注释
|
|
|
|
whereOption.push(`alarms.StructureId IN (${anxinStrucIds.join(",")})`) |
|
|
|
|
|
|
|
let start = moment().add(-1, 'year').format('YYYY-MM-DD HH:mm:ss');//最近一年
|
|
|
|
whereOption.push(`alarms.StartTime >= '${start}'`) |
|
|
|
|
|
|
|
let alarmQueryOptionStr = ` |
|
|
|
FROM alarms |
|
|
|
${whereOption.length ? 'WHERE ' + whereOption.join(' AND ') : ''} |
|
|
|
` |
|
|
|
dataAbnormal = await queryAlarm(ctx, alarmQueryOptionStr, [2]);//数据异常
|
|
|
|
dataInterrupt = await queryAlarm(ctx, alarmQueryOptionStr, [1]);//数据中断
|
|
|
|
policyHit = await queryAlarm(ctx, alarmQueryOptionStr, [3]);//策略命中
|
|
|
|
deviceAbnormal = await queryAlarm(ctx, alarmQueryOptionStr, [4, 5]);//设备异常
|
|
|
|
} |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { dataAbnormal, dataInterrupt, policyHit, deviceAbnormal }; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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 formatDateTime(StartTime,'%F') days, count(AlarmId) count, 0 done from |
|
|
|
(SELECT |
|
|
|
alarms.AlarmId AS AlarmId, |
|
|
|
alarms.State AS State, |
|
|
|
StartTime, |
|
|
|
AlarmGroup |
|
|
|
${alarmQueryOptionStr} and alarms.AlarmGroup in [${type}]) group by days |
|
|
|
|
|
|
|
union all (SELECT formatDateTime(StartTime,'%F') days, 0 count, count(AlarmId) done from |
|
|
|
(SELECT |
|
|
|
alarms.AlarmId AS AlarmId, |
|
|
|
alarms.State AS State, |
|
|
|
StartTime, |
|
|
|
AlarmGroup |
|
|
|
${alarmQueryOptionStr} and alarms.AlarmGroup in [${type}] and alarms.State > 3) group by days) |
|
|
|
|
|
|
|
) group by days ORDER BY days |
|
|
|
`).toPromise();
|
|
|
|
return alarmRes; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//BI分析-应用异常
|
|
|
|
async function getAppAlarmsAggDay(ctx) { |
|
|
|
try { |
|
|
|
let appAlarms = await inspectionList(ctx, 'day'); |
|
|
|
let aggDayMap = []; |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = aggDayMap; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
message: typeof error == 'string' ? error : undefined |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//BI分析-视频异常
|
|
|
|
async function getVideoAlarmsAggDay(ctx) { |
|
|
|
try { |
|
|
|
let videoAlarms = await alarmList(ctx, 'day'); |
|
|
@ -190,6 +281,9 @@ async function getLatestDynamic(ctx) { |
|
|
|
module.exports = { |
|
|
|
getWorkbench, |
|
|
|
getProjectsInfo, |
|
|
|
|
|
|
|
getDataAlarmsAggDay, |
|
|
|
getAppAlarmsAggDay, |
|
|
|
getVideoAlarmsAggDay, |
|
|
|
getLatestDynamic |
|
|
|
}; |