|
|
@ -127,48 +127,80 @@ async function count (ctx) { |
|
|
|
|
|
|
|
const anxinStrucIds = anxinStruc.map(a => a.strucId) || [] |
|
|
|
|
|
|
|
//剩余数据,设备告警
|
|
|
|
const dataAlarm = await clickHouse.dataAlarm.query(` |
|
|
|
SELECT |
|
|
|
AlarmId,State,StartTime,AlarmGroup |
|
|
|
AlarmGroup,COUNT(AlarmId) AS count |
|
|
|
FROM |
|
|
|
alarms |
|
|
|
WHERE |
|
|
|
alarms.StructureId IN (${anxinStrucIds.join(",")}) |
|
|
|
AND |
|
|
|
State < 3 |
|
|
|
GROUP BY AlarmGroup |
|
|
|
`).toPromise();
|
|
|
|
|
|
|
|
const confirmedAlarm = dataAlarm |
|
|
|
// TODO: 开发临时注释
|
|
|
|
.filter(ar => ar.State && ar.State > 2) |
|
|
|
.map(ar => "'" + ar.AlarmId + "'") |
|
|
|
|
|
|
|
//剩余数据告警
|
|
|
|
const dataSurplus = dataAlarm.filter(ar => ar.State && ar.State < 3 && ar.AlarmGroup < 4).length || 0 |
|
|
|
let dataSurplus = 0 |
|
|
|
//剩余设备告警
|
|
|
|
const toolSurplus = dataAlarm.filter(ar => ar.State && ar.State < 3 && ar.AlarmGroup > 3).length || 0 |
|
|
|
let toolSurplus = 0 |
|
|
|
|
|
|
|
for (let p of dataAlarm) { |
|
|
|
if (p.AlarmGroup < 4) { |
|
|
|
dataSurplus = dataSurplus + p.count |
|
|
|
} |
|
|
|
if (p.AlarmGroup > 3) { |
|
|
|
toolSurplus = toolSurplus + p.count |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const dataAlarmToday = await clickHouse.dataAlarm.query(` |
|
|
|
SELECT |
|
|
|
AlarmGroup,COUNT(StartTime) AS count |
|
|
|
FROM |
|
|
|
alarms |
|
|
|
WHERE |
|
|
|
alarms.StructureId IN (${anxinStrucIds.join(",")}) |
|
|
|
AND |
|
|
|
StartTime BETWEEN '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' AND '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND |
|
|
|
State < 3 |
|
|
|
GROUP BY AlarmGroup |
|
|
|
`).toPromise()
|
|
|
|
//今日新增数据告警
|
|
|
|
const dataNewAdd = dataAlarm.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.StartTime) && moment(r.createTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')) && r.AlarmGroup < 4).length || 0 |
|
|
|
const toolNewAdd = dataAlarm.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.StartTime) && moment(r.createTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')) && r.AlarmGroup > 3).length || 0 |
|
|
|
let dataNewAdd = 0 |
|
|
|
//今日新增设备告警
|
|
|
|
let toolNewAdd = 0 |
|
|
|
for (let p of dataAlarmToday) { |
|
|
|
if (p.AlarmGroup < 4) dataNewAdd = dataNewAdd + p.count |
|
|
|
if (p.AlarmGroup > 3) toolNewAdd = toolNewAdd + p.count |
|
|
|
} |
|
|
|
|
|
|
|
//今日确认数据告警
|
|
|
|
const dataConfirme = confirmedAlarm.length ? |
|
|
|
await clickHouse.dataAlarm.query(` |
|
|
|
const dataConfirme = await clickHouse.dataAlarm.query(` |
|
|
|
SELECT |
|
|
|
max(Time) AS Time, AlarmId , max(Content) AS Content, |
|
|
|
alarms.AlarmGroup AS AlarmGroup |
|
|
|
AlarmGroup,COUNT(EndTime) AS count |
|
|
|
FROM |
|
|
|
alarm_details |
|
|
|
LEFT JOIN alarms |
|
|
|
ON alarm_details.AlarmId=alarms.AlarmId |
|
|
|
alarms |
|
|
|
WHERE |
|
|
|
AlarmId IN (${confirmedAlarm.join(',')}) |
|
|
|
AND |
|
|
|
alarm_details.Time >= '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND |
|
|
|
alarm_details.Time <= '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
GROUP BY AlarmId,AlarmGroup |
|
|
|
`).toPromise() :
|
|
|
|
[]; |
|
|
|
alarms.StructureId IN (${anxinStrucIds.join(",")}) |
|
|
|
AND |
|
|
|
EndTime BETWEEN '${moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')}' AND '${moment().endOf('day').format('YYYY-MM-DD HH:mm:ss')}' |
|
|
|
AND |
|
|
|
State > 2 |
|
|
|
GROUP BY AlarmGroup |
|
|
|
`).toPromise()
|
|
|
|
|
|
|
|
|
|
|
|
//今日确认数据告警
|
|
|
|
let dataConfirmeToday = 0 |
|
|
|
//今日确认设备告警
|
|
|
|
let toolConfirmeToday = 0 |
|
|
|
for (let p of dataConfirme) { |
|
|
|
if (p.AlarmGroup < 4) dataConfirmeToday = dataConfirmeToday + p.count |
|
|
|
if (p.AlarmGroup > 3) toolConfirmeToday = toolConfirmeToday + p.count |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let findOption = { |
|
|
@ -195,13 +227,20 @@ async function count (ctx) { |
|
|
|
} |
|
|
|
|
|
|
|
//应用总告警
|
|
|
|
const listRes = await models.AppAlarm.findAndCountAll(findOption) |
|
|
|
let listRes = await models.AppAlarm.findAndCountAll(findOption) |
|
|
|
|
|
|
|
//剩余应用告警
|
|
|
|
const appSurplus = listRes.rows.filter(r => !r.confirmTime).length || 0 |
|
|
|
let appSurplus = 0 |
|
|
|
//今日新增应用告警
|
|
|
|
const appNewAdd = listRes.rows.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.createTime) && moment(r.createTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))).length || 0 |
|
|
|
let appNewAdd = 0 |
|
|
|
//今日确认应用告警
|
|
|
|
const appConfirme = listRes.rows.filter(r => moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(r.confirmTime) && moment(r.confirmTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))).length || 0 |
|
|
|
let appConfirme = 0 |
|
|
|
|
|
|
|
for (let p of listRes.rows) { |
|
|
|
if (!p.dataValues.confirmTime) appSurplus++ |
|
|
|
if (p.dataValues.createTime && moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(p.dataValues.createTime) && moment(p.dataValues.createTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))) appNewAdd++ |
|
|
|
if (p.dataValues.confirmTime && moment(moment().startOf('day').format('YYYY-MM-DD HH:mm:ss')).isBefore(p.dataValues.confirmTime) && moment(p.dataValues.confirmTime).isBefore(moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'))) appConfirme++ |
|
|
|
} |
|
|
|
|
|
|
|
const alarmRes = anxinStrucIds.length ? await clickHouse.vcmp.query( |
|
|
|
` |
|
|
@ -307,33 +346,59 @@ async function count (ctx) { |
|
|
|
|
|
|
|
let findOptions = { |
|
|
|
where: { |
|
|
|
del: false |
|
|
|
del: false, |
|
|
|
|
|
|
|
}, |
|
|
|
attributes: [] |
|
|
|
attributes: ['pepProjectId'] |
|
|
|
} |
|
|
|
if (!userInfo.role.includes('SuperAdmin') && !userInfo.role.includes('admin')) { |
|
|
|
findOptions.where.id = { $in: userInfo.correlationProject } |
|
|
|
} |
|
|
|
const projects = await models.ProjectCorrelation.findAndCountAll(findOptions) |
|
|
|
let pepProjectIds = new Set() |
|
|
|
|
|
|
|
for (let p of projects.rows) { |
|
|
|
if (p.pepProjectId) { |
|
|
|
pepProjectIds.add(p.pepProjectId) |
|
|
|
} |
|
|
|
} |
|
|
|
const pepProjectRes = pepProjectIds.size ? |
|
|
|
await clickHouse.projectManage.query( |
|
|
|
` |
|
|
|
SELECT |
|
|
|
t_pim_project.id AS id, |
|
|
|
t_pim_project.isdelete AS isdelete |
|
|
|
FROM t_pim_project |
|
|
|
WHERE id IN (${[...pepProjectIds].join(',')}, -1) |
|
|
|
` |
|
|
|
).toPromise() : |
|
|
|
[] |
|
|
|
|
|
|
|
|
|
|
|
for (let p of projects.rows) { |
|
|
|
const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId) || {} |
|
|
|
p.dataValues.pepProjectIsDelete = corPro.isdelete |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { |
|
|
|
|
|
|
|
dataSurplus: dataSurplus + videoSurplus, |
|
|
|
dataNewAdd: dataNewAdd + videoNewAdd, |
|
|
|
dataConfirme: appConfirme + dataConfirme.filter(r => r.AlarmGroup < 4).length, |
|
|
|
dataConfirme: videoConfirme + dataConfirmeToday, |
|
|
|
|
|
|
|
|
|
|
|
toolSurplus: toolSurplus, |
|
|
|
toolNewAdd: toolNewAdd, |
|
|
|
toolConfirme: dataConfirme.filter(r => r.AlarmGroup > 3).length, |
|
|
|
toolConfirme: toolConfirmeToday, |
|
|
|
|
|
|
|
|
|
|
|
appSurplus: appSurplus, |
|
|
|
appNewAdd: appNewAdd, |
|
|
|
appConfirme: appConfirme, |
|
|
|
|
|
|
|
projects: projects.count, |
|
|
|
projects: projects.rows.filter(v => v.dataValues.pepProjectIsDelete !== 1).length, |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|