From 84e27fb6b391ceeec54c70e23a05f5566e3ca564 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Tue, 17 Oct 2023 16:47:54 +0800 Subject: [PATCH 1/3] fix : Cannot read property 'length' of undefined --- api/app/lib/schedule/alarms_push.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 35d6a71..a3d4955 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -1,7 +1,7 @@ const moment = require('moment') let isDev = false -// isDev = true +isDev = true let proDebug = false proDebug = true @@ -1179,7 +1179,7 @@ module.exports = function (app, opts) { LEFT JOIN t_factor ON t_factor.id = t_structure_factor.factor WHERE - t_structure_factor.structure IN (${[...dataAlarmG1StructureId,-1].join(',')}) + t_structure_factor.structure IN (${[...dataAlarmG1StructureId, -1].join(',')}) ` ).toPromise() || [] : [] //查询结构物的监测因素(本地化项目) @@ -1188,14 +1188,14 @@ module.exports = function (app, opts) { StructId AS structureId,SafetyFactorTypeName AS name,SafetyFactorTypeId AS id FROM sensors - WHERE sensors.StructId in (${[...dataAlarmStructureId,-1].join(',')})` + WHERE sensors.StructId in (${[...dataAlarmStructureId, -1].join(',')})` ).toPromise() || [] pLog('安心云项目监测因素', factorData.length) pLog('本地化项目监测因素', factorDataLocal) //安心云的factorId let factorId = factorData.map(f => f.id) //本地化的factorId - let factorIdLocal=factorDataLocal.map(f => f.id) + let factorIdLocal = factorDataLocal.map(f => f.id) pLog('安心云+本地监测因素', factorData.length) //查询结构物对应的测点(安心云) let equipment = await clickHouse.anxinyun.query( @@ -1210,9 +1210,9 @@ module.exports = function (app, opts) { LEFT JOIN t_device_sensor ON t_device_sensor.sensor = t_sensor.id WHERE - t_sensor.structure IN (${[...dataAlarmG1StructureId,-1].join(',')}) + t_sensor.structure IN (${[...dataAlarmG1StructureId, -1].join(',')}) AND - t_sensor.factor IN (${[...factorId,-1].join(',')}) + t_sensor.factor IN (${[...factorId, -1].join(',')}) ` ).toPromise() || [] //查询结构物对应的测点(本地化) @@ -1223,8 +1223,8 @@ module.exports = function (app, opts) { SafetyFactorTypeId AS factorId, SensorId AS iotaDeviceId FROM sensors - WHERE sensors.StructId IN (${[...dataAlarmStructureId,-1].join(',')}) - AND sensors.SafetyFactorTypeId IN (${[...factorIdLocal,-1].join(',')}) + WHERE sensors.StructId IN (${[...dataAlarmStructureId, -1].join(',')}) + AND sensors.SafetyFactorTypeId IN (${[...factorIdLocal, -1].join(',')}) ` ).toPromise() || [] pLog('安心云项目测点', equipment.length) @@ -1248,7 +1248,7 @@ module.exports = function (app, opts) { FROM alarms WHERE - alarms.StructureId In (${[...dataAlarmG1StructureId, ...dataAlarmStructureId,-1].join(',')}) + alarms.StructureId In (${[...dataAlarmG1StructureId, ...dataAlarmStructureId, -1].join(',')}) AND alarms.AlarmGroup = 1 AND @@ -1307,7 +1307,7 @@ module.exports = function (app, opts) { } } - if (projectList.length) { + if (true || projectList.length) { pepProject_name.map(s => { s.projects = [] projectList.map(f => { From 9750566ce8794847a3b759bc635946ace45d2f2b Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Tue, 17 Oct 2023 17:20:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=8E=A8=E9=80=81++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index a3d4955..b5054f1 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -654,8 +654,6 @@ module.exports = function (app, opts) { }, { n: '告警信息', k: 'AlarmContent' - }, { - }, { n: '告警等级(当前)', k: '', @@ -1045,12 +1043,9 @@ module.exports = function (app, opts) { * 以测点关联 */ if ( - isDev || - ( - apMergeDeVeAnxinProjectId_.length && - d.SourceName && d.SourceName.includes('扬尘') && - apMergeDeVeAnxinProjectId_.some(pid => pid == (strucMap[d.StructureId] || {}).projectId) - ) + apMergeDeVeAnxinProjectId_.length && + d.SourceName && d.SourceName.includes('扬尘') && + apMergeDeVeAnxinProjectId_.some(pid => pid == (strucMap[d.StructureId] || {}).projectId) ) { // SourceTypeId 0: 'DTU' / 1: '传感器' / 2: '测点' @@ -1121,9 +1116,9 @@ module.exports = function (app, opts) { .replace('**', abnormalDeviceCount.toFixed(0)) } // 注1 - if (apMergeDeVeAnxinProjectId_.length || isDev) { + if (apMergeDeVeAnxinProjectId_.length) { for (let a of videoAlarms) { - let existStruc = a.struc.find(asc => apMergeDeVeAlarms[asc.id] || isDev) + let existStruc = a.struc.find(asc => apMergeDeVeAlarms[asc.id]) if (existStruc) { apMergeDeVeAlarms[existStruc.id].video_exception.push(a) } @@ -1631,10 +1626,11 @@ module.exports = function (app, opts) { de.id = corSensor.sensor } } - let corVideoException = curStrucAlarm.video_exception.filter(v => { - // ! de.id 是告警信息关联查出来的测点的id - return v.station.some(vs => vs.id == de.id) - }) + let corVideoException = + curStrucAlarm.video_exception ? curStrucAlarm.video_exception.filter(v => { + // ! de.id 是告警信息关联查出来的测点的id + return v.station.some(vs => vs.id == de.id) + }) : [] if (!corVideoException.length) { // 构造一个长度 以便在for循环里把 data_exception 放进去 corVideoException.push({}) From 410e2ff47b12618e89c281d35208740006d36fe0 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Tue, 17 Oct 2023 17:32:44 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=8E=A8=E9=80=81++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index b5054f1..4a844cf 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -1,7 +1,7 @@ const moment = require('moment') let isDev = false -isDev = true +// isDev = true let proDebug = false proDebug = true @@ -130,6 +130,7 @@ module.exports = function (app, opts) { pepProject_name.push({ id: poms.id, anxinProjectId: poms.anxinProjectId, name: corPepProject.project_name }) } else { // 不符合当前项目的时间节点 + pLog(`不符合当前项目的时间节点`) continue } } else { @@ -220,6 +221,7 @@ module.exports = function (app, opts) { searchStrucIds.unshift(-1) } else { // 没有结构物可查 + pLog(`没有结构物可查`) continue } let pepProjectName = @@ -1108,6 +1110,7 @@ module.exports = function (app, opts) { pLog(`异常比率 ${rate} 设定值 ${deviceProportion}`) if (rate < parseFloat(deviceProportion)) { // 设备异常率低于设定值 + pLog(`异常设备率低于设定值`) continue } @@ -1687,7 +1690,7 @@ module.exports = function (app, opts) { html: html }) - //存日志 存动态 socket到前端 + // //存日志 存动态 socket到前端 let dataToSave = { time: moment().format(), pushConfigId: c.id,