diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js
index 197c838..1f435e3 100644
--- a/api/app/lib/schedule/alarms_push.js
+++ b/api/app/lib/schedule/alarms_push.js
@@ -1101,7 +1101,8 @@ module.exports = function (app, opts) {
alarms.AlarmGroup AS alarmGroup,
alarms.SourceId AS sourceId,
alarms.StartTime AS StartTime,
- alarms.SourceName AS SourceName
+ alarms.SourceName AS SourceName,
+ alarms.AlarmCode AS AlarmCode
FROM
alarms
WHERE
@@ -1113,9 +1114,9 @@ module.exports = function (app, opts) {
`
).toPromise() || []
- console.log('当前结构物下所有告警', alarmDatas);
- console.log('监测因素', factorData);
- console.log('结构物对应的设备', equipment);
+ // console.log('当前结构物下所有告警', alarmDatas);
+ // console.log('监测因素', factorData);
+ // console.log('结构物对应的设备', equipment);
equipment.map(f => {
f.alarmDatas = []
@@ -1156,8 +1157,8 @@ module.exports = function (app, opts) {
})
}
- console.log('数据组合', JSON.stringify(pepProject_name));
-
+ // console.log('数据组合', JSON.stringify(pepProject_name));
+
pepProject_name.forEach(h => {
let rowspan1 = 0
if (h.projects.length) {
@@ -1238,45 +1239,59 @@ module.exports = function (app, opts) {
let showOne3 = (ci == 0) ? true : false
if (c.alarmDatas && c.alarmDatas.length) {
//取设备里面告警最新的一条数据
- 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 = '
'
- for (let t of alarmTitleArr) {
- if (t.f) {
- tableData += `${t.f(alarmNewest) || ''} | `
- } else if (t.k) {
- switch (t.k) {
- case 'name':
- if (showOne1 && showOne2 && showOne3) {
- tableData += `${h[t.k] || ''} | `
- }
- break;
- case 'Structure':
- if (showOne2 && showOne3) {
- tableData += `${x['name'] || ''} | `
- }
- break;
- case 'factor':
- if (showOne3) {
- tableData += `${(f['name'] + '(' + f.rowspan + '/' + f.devicesLength + ')') || ''} | `
+ 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
+ }, {}) || {}
+
+ 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 = '
'
+ for (let t of alarmTitleArr) {
+ if (t.f) {
+ tableData += `${t.f(alarmNewest) || ''} | `
+ } else if (t.k) {
+ switch (t.k) {
+ case 'name':
+ if (showOne1 && showOne2 && showOne3) {
+ tableData += `${h[t.k] || ''} | `
+ }
+ break;
+ case 'Structure':
+ if (showOne2 && showOne3) {
+ tableData += `${x['name'] || ''} | `
+ }
+ break;
+ case 'factor':
+ if (showOne3) {
+ tableData += `${(f['name'] + '(' + f.rowspan + '/' + f.devicesLength + ')') || ''} | `
+ }
+ break;
+ case 'SourceName':
+ tableData += `${alarmNewest[t.k] || ''} | `
+ break;
+ default:
+ break;
}
- break;
- case 'SourceName':
- tableData += `${alarmNewest[t.k] || ''} | `
- break;
- default:
- break;
+ }
+ }
+ tableData += '
'
+ alarmContent += tableData
+ if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
+ newAddCount++
}
}
- }
- tableData += ''
- alarmContent += tableData
- if (alarmNewest[keyOfStartTime] && moment(alarmNewest[keyOfStartTime]).isBetween(newAddStartTime, newAddEndTime)) {
- newAddCount++
+
}
+
}
})
}
@@ -1294,8 +1309,6 @@ module.exports = function (app, opts) {
} else {
for (let [index, a] of alarmData.entries()) {
-
-
alarmContent += packageTableData({ data: a, titleArr: alarmTitleArr })