From f973bbc0aa7b2e52aee3c0c04113241d66c4a1d4 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Tue, 26 Sep 2023 10:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E8=A7=A3=20subStations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 119 ++++++++++++++++------------ 1 file changed, 68 insertions(+), 51 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index c72c2da..107f662 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -4,7 +4,7 @@ let isDev = false // isDev = true let proDebug = false -// proDebug = true +proDebug = true module.exports = function (app, opts) { const alarmsPush = app.fs.scheduleInit( @@ -1179,7 +1179,7 @@ module.exports = function (app, opts) { ).toPromise() || [] - const alarmDatas = await clickHouse.dataAlarm.query( + const alarmDataRes = await clickHouse.dataAlarm.query( ` SELECT alarms.AlarmId AS alarmId, @@ -1190,7 +1190,8 @@ module.exports = function (app, opts) { alarms.SourceName AS SourceName, alarms.AlarmCode AS AlarmCode, alarms.SourceTypeId AS SourceTypeId, - alarms.StructureId AS StructureId + alarms.StructureId AS StructureId, + alarms.subStations AS subStations, FROM alarms WHERE @@ -1202,6 +1203,21 @@ module.exports = function (app, opts) { ` ).toPromise() || [] + let alarmDatas = [] + for (let alarms of alarmDataRes) { + if (alarms.subStations && alarms.subStations.length) { + pLog('拆解 subStations' + alarms.alarmId + ' ' + alarms.subStations.length + '个') + for (let subStation of alarms.subStations) { + alarmDatas.push({ + ...alarms, + alarmId: subStation + }) + } + } else { + alarmDatas.push(alarms) + } + } + // 为设备分配自己产生的告警数据 let matchedAlarmIds = [] // 这一步能被分配的告警应该也能最终体现在邮件中 @@ -1256,54 +1272,55 @@ module.exports = function (app, opts) { // 上面的代码自内而外构建数据 // 下面的逻辑自外向内!!! - // // 处理那些没有被匹配到的告警信息 - // // 将设备没有绑定到测点的告警也推出去 - // for (let a of alarmDatas) { - // if (!matchedAlarmIds.includes(a.alarmId)) { - // let curStruc = strucMap[a.StructureId] - // if (curStruc) { - // // curStruc 可以推出 告警属于哪个 project -> pomsProject - // let curProject = pepProject_name.filter(p => p.anxinProjectId && p.anxinProjectId.includes(curStruc.projectId)); - // for (let cp of curProject) { - // // cp.projects 是结构物信息 - // let curStruc = cp.projects.find(cpp => cpp.id == a.StructureId) - // if (!curStruc) { - // console.error(`没有查到结构物信息:${a.StructureId}?!不应该不应该!`); - // } else { - // // let emptyFactor = { id: -1 } - // let emptyFactor = curStruc.factor.find(f => f.id == -1) - // if (!emptyFactor) { - // curStruc.factor.push({ - // id: -1, - // devices: [{ - // alarmDatas: [ - // { ...a } - // ], - // iotaDeviceId: a.sourceId, - // name: a.SourceName, - // structureId: a.StructureId, - // }] - // }) - // } else { - // let curDevice = emptyFactor.devices.find(d => d.iotaDeviceId == a.sourceId) - // if (!curDevice) { - // emptyFactor.devices.push({ - // alarmDatas: [ - // { ...a } - // ], - // iotaDeviceId: a.sourceId, - // name: a.SourceName, - // structureId: a.StructureId, - // }) - // } else { - // curDevice.alarmDatas.push({ ...a }) - // } - // } - // } - // } - // } - // } - // } + // 处理那些没有被匹配到的告警信息 + // 将设备没有绑定到测点的告警也推出去 + for (let a of alarmDatas) { + if (!matchedAlarmIds.includes(a.alarmId)) { + pLog('未匹配到的告警 ' + a.alarmId) + // let curStruc = strucMap[a.StructureId] + // if (curStruc) { + // // curStruc 可以推出 告警属于哪个 project -> pomsProject + // let curProject = pepProject_name.filter(p => p.anxinProjectId && p.anxinProjectId.includes(curStruc.projectId)); + // for (let cp of curProject) { + // // cp.projects 是结构物信息 + // let curStruc = cp.projects.find(cpp => cpp.id == a.StructureId) + // if (!curStruc) { + // console.error(`没有查到结构物信息:${a.StructureId}?!不应该不应该!`); + // } else { + // // let emptyFactor = { id: -1 } + // let emptyFactor = curStruc.factor.find(f => f.id == -1) + // if (!emptyFactor) { + // curStruc.factor.push({ + // id: -1, + // devices: [{ + // alarmDatas: [ + // { ...a } + // ], + // iotaDeviceId: a.sourceId, + // name: a.SourceName, + // structureId: a.StructureId, + // }] + // }) + // } else { + // let curDevice = emptyFactor.devices.find(d => d.iotaDeviceId == a.sourceId) + // if (!curDevice) { + // emptyFactor.devices.push({ + // alarmDatas: [ + // { ...a } + // ], + // iotaDeviceId: a.sourceId, + // name: a.SourceName, + // structureId: a.StructureId, + // }) + // } else { + // curDevice.alarmDatas.push({ ...a }) + // } + // } + // } + // } + // } + } + } pepProject_name.forEach(h => { let rowspan1 = 0