Browse Source

取设备里面告警最新的一条数据

dev
wenlele 2 years ago
parent
commit
9beb427bef
  1. 30
      api/app/lib/schedule/alarms_push.js

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

@ -1168,11 +1168,11 @@ module.exports = function (app, opts) {
if (f.devices.length) { if (f.devices.length) {
f.devices.forEach(c => { f.devices.forEach(c => {
if (c.alarmDatas.length) { if (c.alarmDatas.length) {
c.alarmDatas.forEach(a => {
rowspan1 += 1 rowspan1 += 1
rowspan2 += 1 rowspan2 += 1
rowspan3 += 1 rowspan3 += 1
})
} else { } else {
delete c.alarmDatas delete c.alarmDatas
} }
@ -1195,7 +1195,7 @@ module.exports = function (app, opts) {
} }
h.rowspan = rowspan1 h.rowspan = rowspan1
}) })
console.log('数据组合', JSON.stringify(pepProject_name)); // console.log('数据组合', JSON.stringify(pepProject_name));
// //
dataAlarmG1 = pepProject_name dataAlarmG1 = pepProject_name
} }
@ -1214,10 +1214,8 @@ module.exports = function (app, opts) {
let alarmContent = '' let alarmContent = ''
let alarmHtmlTitle = packageTableTitle(alarmTitleArr) let alarmHtmlTitle = packageTableTitle(alarmTitleArr)
if (type == 1) { if (type == 1) {
alarmData.map((h, hi) => { alarmData.map((h, hi) => {
if (h.projects && h.projects.length) { if (h.projects && h.projects.length) {
@ -1232,14 +1230,16 @@ module.exports = function (app, opts) {
f.devices.map((c, ci) => { f.devices.map((c, ci) => {
let showOne3 = (ci == 0) ? true : false let showOne3 = (ci == 0) ? true : false
if (c.alarmDatas && c.alarmDatas.length) { if (c.alarmDatas && c.alarmDatas.length) {
c.alarmDatas.map(a => { //取设备里面告警最新的一条数据
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>' let tableData = '<tr>'
for (let t of alarmTitleArr) { for (let t of alarmTitleArr) {
if (t.f) { if (t.f) {
tableData += `<td>${t.f(a) || ''}</td>` tableData += `<td>${t.f(alarmNewest) || ''}</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) {
@ -1247,19 +1247,17 @@ module.exports = function (app, opts) {
} }
break; break;
case 'Structure': case 'Structure':
if (showOne2 && showOne3) { if (showOne2 && showOne3) {
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) {
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>${a[t.k] || ''}</td>` tableData += `<td>${alarmNewest[t.k] || ''}</td>`
break; break;
default: default:
break; break;
@ -1268,10 +1266,10 @@ module.exports = function (app, opts) {
} }
tableData += '</tr>' tableData += '</tr>'
alarmContent += tableData alarmContent += tableData
if (a[keyOfStartTime] && moment(a[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
newAddCount++ newAddCount++
} }
})
} }
}) })
} }
@ -1382,7 +1380,7 @@ module.exports = function (app, opts) {
} }
if (proDebug) { if (proDebug) {
console.log(`相关设备及测点信息:`); console.log(`相关设备及测点信息:`);
console.log(deviceSensorRes); // console.log(deviceSensorRes);
} }
let alarmTitle = dataAlarmTitle.concat( let alarmTitle = dataAlarmTitle.concat(
videoAlarmTitle.slice(2).map(v => { videoAlarmTitle.slice(2).map(v => {

Loading…
Cancel
Save