Browse Source

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

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

95
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,45 +1239,59 @@ 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 alarmNewest = c.alarmDatas[0] || {} let grouped = c.alarmDatas.reduce((acc, cur) => {
let tableData = '<tr>' if (!acc[cur.AlarmCode]) {
for (let t of alarmTitleArr) { acc[cur.AlarmCode] = []
if (t.f) { }
tableData += `<td>${t.f(alarmNewest) || ''}</td>` acc[cur.AlarmCode].push(cur)
} else if (t.k) { return acc
switch (t.k) { }, {}) || {}
case 'name':
if (showOne1 && showOne2 && showOne3) { for (let key in grouped) {
tableData += `<th rowspan=${h.rowspan}>${h[t.k] || ''}</th>` grouped[key].sort((a, b) => new Date(b.StartTime) - new Date(a.StartTime))
} let alarmNewest = grouped[key][0] || {}
break; let tableData = '<tr>'
case 'Structure': for (let t of alarmTitleArr) {
if (showOne2 && showOne3) { if (t.f) {
tableData += `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>` tableData += `<td>${t.f(alarmNewest) || ''}</td>`
} } else if (t.k) {
break; switch (t.k) {
case 'factor': case 'name':
if (showOne3) { if (showOne1 && showOne2 && showOne3) {
tableData += `<th rowspan=${f.rowspan}>${(f['name'] + '(' + f.rowspan + '/' + f.devicesLength + ')') || ''}</th>` 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>` tableData += '</tr>'
break; alarmContent += tableData
default: if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
break; 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 { } 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