|
|
@ -1,7 +1,7 @@ |
|
|
|
const moment = require('moment') |
|
|
|
|
|
|
|
let isDev = false |
|
|
|
// let isDev = true
|
|
|
|
// let isDev = false
|
|
|
|
let isDev = true |
|
|
|
|
|
|
|
let proDebug = false |
|
|
|
proDebug = true |
|
|
@ -9,8 +9,8 @@ proDebug = true |
|
|
|
module.exports = function (app, opts) { |
|
|
|
const alarmsPush = app.fs.scheduleInit( |
|
|
|
{ |
|
|
|
interval: '12 */1 * * * *', |
|
|
|
// interval: '12 0 0 0 */1 *',
|
|
|
|
// interval: '12 */1 * * * *',
|
|
|
|
interval: '12 0 0 0 */1 *', |
|
|
|
immediate: isDev, |
|
|
|
proRun: !isDev, |
|
|
|
}, |
|
|
@ -1158,7 +1158,7 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
|
|
|
|
// console.log('数据组合', JSON.stringify(pepProject_name));
|
|
|
|
|
|
|
|
|
|
|
|
pepProject_name.forEach(h => { |
|
|
|
let rowspan1 = 0 |
|
|
|
if (h.projects.length) { |
|
|
@ -1174,15 +1174,27 @@ module.exports = function (app, opts) { |
|
|
|
f.devices.forEach(c => { |
|
|
|
if (c.alarmDatas.length) { |
|
|
|
|
|
|
|
rowspan1 += 1 |
|
|
|
rowspan2 += 1 |
|
|
|
rowspan3 += 1 |
|
|
|
|
|
|
|
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 |
|
|
|
rowspan2 += 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 { |
|
|
|
delete c.alarmDatas |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
f.devices = f.devices.filter(b => b.alarmDatas && b.alarmDatas.length > 0) |
|
|
|
} else { |
|
|
|
delete f.devices |
|
|
|
} |
|
|
@ -1240,42 +1252,33 @@ module.exports = function (app, opts) { |
|
|
|
if (c.alarmDatas && c.alarmDatas.length) { |
|
|
|
//取设备里面告警最新的一条数据
|
|
|
|
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 |
|
|
|
}, {}) || {} |
|
|
|
c.alarmDatas.map((d, di) => { |
|
|
|
let showOne4 = (di == 0) ? true : false |
|
|
|
|
|
|
|
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>` |
|
|
|
tableData += `<td>${t.f(d) || ''}</td>` |
|
|
|
} else if (t.k) { |
|
|
|
switch (t.k) { |
|
|
|
case 'name': |
|
|
|
if (showOne1 && showOne2 && showOne3) { |
|
|
|
if (showOne1 && showOne2 && showOne3 && showOne4) { |
|
|
|
tableData += `<th rowspan=${h.rowspan}>${h[t.k] || ''}</th>` |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'Structure': |
|
|
|
if (showOne2 && showOne3) { |
|
|
|
if (showOne2 && showOne3 && showOne4) { |
|
|
|
tableData += `<th rowspan=${x.rowspan}>${x['name'] || ''}</th>` |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'factor': |
|
|
|
if (showOne3) { |
|
|
|
if (showOne3 && showOne4) { |
|
|
|
tableData += `<th rowspan=${f.rowspan}>${(f['name'] + '(' + f.rowspan + '/' + f.devicesLength + ')') || ''}</th>` |
|
|
|
} |
|
|
|
break; |
|
|
|
case 'SourceName': |
|
|
|
tableData += `<td>${alarmNewest[t.k] || ''}</td>` |
|
|
|
tableData += `<td>${d[t.k] || ''}</td>` |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
@ -1284,11 +1287,10 @@ module.exports = function (app, opts) { |
|
|
|
} |
|
|
|
tableData += '</tr>' |
|
|
|
alarmContent += tableData |
|
|
|
if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { |
|
|
|
if (d[keyOfStartTime] && moment(d[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) { |
|
|
|
newAddCount++ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|