From 31da6d9c01a5fa5147b5c12d5d479a861847c257 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Tue, 17 Oct 2023 13:56:56 +0800 Subject: [PATCH] SubDevices --- api/app/lib/schedule/alarms_push.js | 74 ++++++++++++++--------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index ac1b873..6bebb25 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -27,9 +27,9 @@ module.exports = function (app, opts) { const { pushBySms, pushByEmail, sendNoticeToWeb } = app.fs.utils const curMinOfYear = moment().diff(moment().startOf('year'), 'minutes') - const pLog = (msg1,msg2) => { + const pLog = (msg1, msg2) => { if (proDebug) { - console.log(msg1,msg2) + console.log(msg1, msg2) } } @@ -407,7 +407,7 @@ module.exports = function (app, opts) { ON anxinStation.id = anxinIpcStation.station ORDER BY cameraAlarm.createTime DESC ` - ).toPromise() : [] + ).toPromise() : [] let returnD = [] let positionD = {} // 每个设备一个告警 @@ -540,9 +540,9 @@ module.exports = function (app, opts) { ${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} ORDER BY StartTime DESC `).toPromise() : [] - //本地化 - const dataAlarmsLocal=!c.alarmSubType || dataAlarmSubType_.length ? - await clickHouse.dataAlarm.query(` + //本地化 + const dataAlarmsLocal = !c.alarmSubType || dataAlarmSubType_.length ? + await clickHouse.dataAlarm.query(` SELECT * FROM alarms LEFT JOIN sensors AS anxinStation @@ -554,13 +554,13 @@ module.exports = function (app, opts) { ${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} ORDER BY StartTime DESC `).toPromise() : [] - //合并本地化和安心云的告警 - dataAlarms=[...dataAlarms,...dataAlarmsLocal] - pLog('合并的告警列表(安心云+本地)',dataAlarms.length) - pLog('合并的告警列表(安心云+本地)',dataAlarmsLocal.length) + //合并本地化和安心云的告警 + dataAlarms = [...dataAlarms, ...dataAlarmsLocal] + pLog('合并的告警列表(安心云+本地)', dataAlarms.length) + pLog('合并的告警列表(安心云+本地)', dataAlarmsLocal.length) } - + let dataAlarmTitle2 = [{ n: '项目', @@ -1152,21 +1152,21 @@ module.exports = function (app, opts) { ` let dataAlarmG1Data = dataAlarms.filter(a => a.AlarmGroup == 1) - pLog('数据中断',dataAlarmG1Data.length) + pLog('数据中断', dataAlarmG1Data.length) if (dataAlarmG1Data.length) { //安心云项目是structureId数组 let dataAlarmG1StructureId = new Set() //本地化项目structureId数组 let dataAlarmStructureId = new Set() dataAlarmG1Data.map(c => { - if(c.project){ + if (c.project) { dataAlarmStructureId.add(c.StructureId) - }else{ + } else { dataAlarmG1StructureId.add(c.StructureId) } }) - pLog('安心云项目结构物id',dataAlarmG1StructureId) - pLog('本地化项目结构物id',dataAlarmStructureId) + pLog('安心云项目结构物id', dataAlarmG1StructureId) + pLog('本地化项目结构物id', dataAlarmStructureId) //查询结构物的监测因素(安心云) let factorData = await clickHouse.anxinyun.query( ` @@ -1184,19 +1184,19 @@ module.exports = function (app, opts) { ).toPromise() || [] //查询结构物的监测因素(本地化项目) let factorDataLocal = await clickHouse.dataAlarm.query( - ` SELECT + ` SELECT StructId AS structureId,SafetyFactorTypeName AS name,SafetyFactorTypeId AS id FROM sensors WHERE sensors.StructId in (${[...dataAlarmStructureId].join(',')},-1)` ).toPromise() || [] - pLog('安心云项目监测因素',factorData.length) - pLog('本地化项目监测因素',factorDataLocal) - //合并(安心云+本地化项目) - factorData=[...factorDataLocal,...factorData] - pLog('安心云+本地监测因素',factorData.length) + pLog('安心云项目监测因素', factorData.length) + pLog('本地化项目监测因素', factorDataLocal) + //合并(安心云+本地化项目) + factorData = [...factorDataLocal, ...factorData] + pLog('安心云+本地监测因素', factorData.length) let factorId = factorData.map(f => f.id) - let factorIdLocal=factorIdLocal.map(f => f.id) + let factorIdLocal = factorIdLocal.map(f => f.id) //查询结构物对应的测点(安心云) let equipment = await clickHouse.dataAlarm.query( ` @@ -1225,13 +1225,13 @@ module.exports = function (app, opts) { FROM sensors WHERE sensors.StructId IN (${[...dataAlarmStructureId].join(',')},-1) AND sensors.SafetyFactorTypeId IN (${factorIdLocal.join(',')},-1) - ` + ` ).toPromise() || [] - pLog('安心云项目测点',equipment.length) - pLog('本地化项目测点',equipmentLocal) + pLog('安心云项目测点', equipment.length) + pLog('本地化项目测点', equipmentLocal) //合并本地化数据+安心云数据 - equipment=[...equipment,...equipmentLocal] - pLog('本地化+安心云测点',equipment.length) + equipment = [...equipment, ...equipmentLocal] + pLog('本地化+安心云测点', equipment.length) const alarmDataRes = await clickHouse.dataAlarm.query( ` SELECT @@ -1243,27 +1243,27 @@ 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.SubDevices AS SubDevices FROM alarms WHERE - alarms.StructureId In (${[...dataAlarmG1StructureId,...dataAlarmStructureId].join(',')},-1) + alarms.StructureId In (${[...dataAlarmG1StructureId, ...dataAlarmStructureId].join(',')},-1) AND alarms.AlarmGroup = 1 AND alarms.State < 3 ` - // , - // alarms.subStations AS subStations + ).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) { + if (alarms.SubDevices && alarms.SubDevices.length) { + pLog('拆解 SubDevices' + alarms.alarmId + ' ' + alarms.SubDevices.length + '个') + for (let SubDevice of alarms.SubDevices) { alarmDatas.push({ ...alarms, - alarmId: subStation + alarmId: SubDevice }) } } else { @@ -1666,7 +1666,7 @@ module.exports = function (app, opts) { `).toPromise() : [] let receiverId = [] - console.log('接收邮件的人',receiverRes) + console.log('接收邮件的人', receiverRes) let emails = receiverRes.reduce((arr, r) => { if (r.email) { arr.push(r.email)