Browse Source

一个设备区分不同类型告警

dev
wenlele 2 years ago
parent
commit
416cd57660
  1. 33
      api/app/lib/schedule/alarms_push.js

33
api/app/lib/schedule/alarms_push.js

@ -1101,7 +1101,8 @@ module.exports = function (app, opts) {
alarms.AlarmGroup AS alarmGroup, alarms.AlarmGroup AS alarmGroup,
alarms.SourceId AS sourceId, alarms.SourceId AS sourceId,
alarms.StartTime AS StartTime, alarms.StartTime AS StartTime,
alarms.SourceName AS SourceName alarms.SourceName AS SourceName,
alarms.AlarmCode AS AlarmCode
FROM FROM
alarms alarms
WHERE WHERE
@ -1113,9 +1114,9 @@ module.exports = function (app, opts) {
` `
).toPromise() || [] ).toPromise() || []
console.log('当前结构物下所有告警', alarmDatas); // console.log('当前结构物下所有告警', alarmDatas);
console.log('监测因素', factorData); // console.log('监测因素', factorData);
console.log('结构物对应的设备', equipment); // console.log('结构物对应的设备', equipment);
equipment.map(f => { equipment.map(f => {
f.alarmDatas = [] f.alarmDatas = []
@ -1156,7 +1157,7 @@ module.exports = function (app, opts) {
}) })
} }
console.log('数据组合', JSON.stringify(pepProject_name)); // console.log('数据组合', JSON.stringify(pepProject_name));
pepProject_name.forEach(h => { pepProject_name.forEach(h => {
let rowspan1 = 0 let rowspan1 = 0
@ -1238,10 +1239,20 @@ module.exports = function (app, opts) {
let showOne3 = (ci == 0) ? true : false let showOne3 = (ci == 0) ? true : false
if (c.alarmDatas && c.alarmDatas.length) { if (c.alarmDatas && c.alarmDatas.length) {
//取设备里面告警最新的一条数据 //取设备里面告警最新的一条数据
if (c.alarmDatas.length > 1) { if (c.alarmDatas.length > 0) {
c.alarmDatas.sort((a, b) => new Date(b.StartTime) - new Date(a.StartTime))
let grouped = c.alarmDatas.reduce((acc, cur) => {
if (!acc[cur.AlarmCode]) {
acc[cur.AlarmCode] = []
} }
let alarmNewest = c.alarmDatas[0] || {} acc[cur.AlarmCode].push(cur)
return acc
}, {}) || {}
for (let key in grouped) {
grouped[key].sort((a, b) => new Date(b.StartTime) - new Date(a.StartTime))
let alarmNewest = grouped[key][0] || {}
let tableData = '<tr>' let tableData = '<tr>'
for (let t of alarmTitleArr) { for (let t of alarmTitleArr) {
if (t.f) { if (t.f) {
@ -1276,6 +1287,10 @@ module.exports = function (app, opts) {
if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
newAddCount++ newAddCount++
} }
}
}
} }
}) })
@ -1294,8 +1309,6 @@ module.exports = function (app, opts) {
} else { } else {
for (let [index, a] of alarmData.entries()) { for (let [index, a] of alarmData.entries()) {
alarmContent += packageTableData({ data: a, titleArr: alarmTitleArr }) alarmContent += packageTableData({ data: a, titleArr: alarmTitleArr })

Loading…
Cancel
Save