Browse Source

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

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

88
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,46 +1230,46 @@ 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 => { //取设备里面告警最新的一条数据
let tableData = '<tr>' if (c.alarmDatas.length > 1) {
c.alarmDatas.sort((a, b) => new Date(b.StartTime) - new Date(a.StartTime))
for (let t of alarmTitleArr) { }
if (t.f) { let alarmNewest = c.alarmDatas[0] || {}
tableData += `<td>${t.f(a) || ''}</td>` let tableData = '<tr>'
} else if (t.k) { for (let t of alarmTitleArr) {
if (t.f) {
switch (t.k) { tableData += `<td>${t.f(alarmNewest) || ''}</td>`
case 'name': } else if (t.k) {
if (showOne1 && showOne2 && showOne3) { switch (t.k) {
tableData += `<th rowspan=${h.rowspan}>${h[t.k] || ''}</th>` case 'name':
} if (showOne1 && showOne2 && showOne3) {
break; tableData += `<th rowspan=${h.rowspan}>${h[t.k] || ''}</th>`
case 'Structure': }
break;
if (showOne2 && showOne3) { case 'Structure':
tableData += `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>` if (showOne2 && showOne3) {
} tableData += `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>`
break; }
case 'factor': break;
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;
}
} }
} }
tableData += '</tr>' }
alarmContent += tableData tableData += '</tr>'
if (a[keyOfStartTime] && moment(a[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { alarmContent += tableData
newAddCount++ if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
} 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