Browse Source

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

dev
wenlele 2 years ago
parent
commit
a66a3a2958
  1. 52
      api/app/lib/schedule/alarms_push.js

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

@ -1,7 +1,7 @@
const moment = require('moment') const moment = require('moment')
let isDev = false // let isDev = false
// let isDev = true let isDev = true
let proDebug = false let proDebug = false
proDebug = true proDebug = true
@ -9,8 +9,8 @@ proDebug = true
module.exports = function (app, opts) { module.exports = function (app, opts) {
const alarmsPush = app.fs.scheduleInit( const alarmsPush = app.fs.scheduleInit(
{ {
interval: '12 */1 * * * *', // interval: '12 */1 * * * *',
// interval: '12 0 0 0 */1 *', interval: '12 0 0 0 */1 *',
immediate: isDev, immediate: isDev,
proRun: !isDev, proRun: !isDev,
}, },
@ -1174,15 +1174,27 @@ module.exports = function (app, opts) {
f.devices.forEach(c => { f.devices.forEach(c => {
if (c.alarmDatas.length) { if (c.alarmDatas.length) {
let grouped = c.alarmDatas.reduce((acc, cur) => {
if (!acc[cur.AlarmCode]) {
acc[cur.AlarmCode] = []
}
acc[cur.AlarmCode].push(cur)
return acc
}, {}) || {}
let alarmData = []
for (let key in grouped) {
rowspan1 += 1 rowspan1 += 1
rowspan2 += 1 rowspan2 += 1
rowspan3 += 1 rowspan3 += 1
grouped[key].sort((a, b) => new Date(b.StartTime) - new Date(a.StartTime))
alarmData.push(grouped[key][0])
}
c.alarmDatas = alarmData
} else { } else {
delete c.alarmDatas delete c.alarmDatas
} }
}) })
f.devices = f.devices.filter(b => b.alarmDatas && b.alarmDatas.length > 0)
} else { } else {
delete f.devices delete f.devices
} }
@ -1241,41 +1253,32 @@ module.exports = function (app, opts) {
//取设备里面告警最新的一条数据 //取设备里面告警最新的一条数据
if (c.alarmDatas.length > 0) { if (c.alarmDatas.length > 0) {
c.alarmDatas.map((d, di) => {
let showOne4 = (di == 0) ? true : false
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>' let tableData = '<tr>'
for (let t of alarmTitleArr) { for (let t of alarmTitleArr) {
if (t.f) { if (t.f) {
tableData += `<td>${t.f(alarmNewest) || ''}</td>` tableData += `<td>${t.f(d) || ''}</td>`
} else if (t.k) { } else if (t.k) {
switch (t.k) { switch (t.k) {
case 'name': case 'name':
if (showOne1 && showOne2 && showOne3) { if (showOne1 && showOne2 && showOne3 && showOne4) {
tableData += `<th rowspan=${h.rowspan}>${h[t.k] || ''}</th>` tableData += `<th rowspan=${h.rowspan}>${h[t.k] || ''}</th>`
} }
break; break;
case 'Structure': case 'Structure':
if (showOne2 && showOne3) { if (showOne2 && showOne3 && showOne4) {
tableData += `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>` tableData += `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>`
} }
break; break;
case 'factor': case 'factor':
if (showOne3) { if (showOne3 && showOne4) {
tableData += `<th rowspan=${f.rowspan}>${(f['name'] + '(' + f.rowspan + '/' + f.devicesLength + ')') || ''}</th>` tableData += `<th rowspan=${f.rowspan}>${(f['name'] + '(' + f.rowspan + '/' + f.devicesLength + ')') || ''}</th>`
} }
break; break;
case 'SourceName': case 'SourceName':
tableData += `<td>${alarmNewest[t.k] || ''}</td>` tableData += `<td>${d[t.k] || ''}</td>`
break; break;
default: default:
break; break;
@ -1284,11 +1287,10 @@ module.exports = function (app, opts) {
} }
tableData += '</tr>' tableData += '</tr>'
alarmContent += tableData alarmContent += tableData
if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { if (d[keyOfStartTime] && moment(d[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
newAddCount++ newAddCount++
} }
} })
} }

Loading…
Cancel
Save