From 416cd57660a7609756a5e65834bb5e564b8793de Mon Sep 17 00:00:00 2001 From: wenlele Date: Wed, 10 May 2023 19:56:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E4=B8=AA=E8=AE=BE=E5=A4=87=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E4=B8=8D=E5=90=8C=E7=B1=BB=E5=9E=8B=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 97 ++++++++++++++++------------- 1 file changed, 55 insertions(+), 42 deletions(-) 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 })