Browse Source

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

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

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

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

Loading…
Cancel
Save