From c68e972af70518aae934c209359c527ed3bd9aba Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 16 Dec 2022 09:04:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=9F=A5=E5=BE=97=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=92=8C=E6=B5=8B=E7=82=B9=E7=9A=84=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index f25e973..757202f 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( @@ -681,7 +681,9 @@ module.exports = function (app, opts) { console.log(`pomsStrucFactorId:`, pomsStrucFactorId); } + let deviceIds = new Set() for (let d of dataAlarms) { + d = { ...d, stationId: d.id } /** 按监测因素筛选 且为测点告警 */ // if (pomsStrucFactorId && d.SourceTypeId == 2) { @@ -718,6 +720,11 @@ module.exports = function (app, opts) { apMergeDeVeAnxinProjectId_.some(pid => pid == (strucMap[d.StructureId] || {}).projectId) ) ) { + // SourceTypeId 0: 'DTU' / 1: '传感器' / 2: '测点' + + if (d.SourceTypeId != 2) { + deviceIds.push(d.SourceId) + } if (apMergeDeVeAlarms[d.StructureId]) { apMergeDeVeAlarms[d.StructureId].data_exception.push(d) } else { @@ -886,6 +893,16 @@ module.exports = function (app, opts) { } if (Object.keys(apMergeDeVeAlarms).length) { + + let deviceSensorRes = [] + if (deviceIds.size) { + const device4Search = [...deviceIds] + .map(id => "'" + id + "'") + deviceSensorRes = await clickHouse.anxinyun.query(` + SELECT iota_device_id, sensor FROM t_device_sensor WHERE iota_device_id IN (${device4Search.join(',')}, '-1') + `).toPromise() + } + let alarmTitle = dataAlarmTitle.concat( videoAlarmTitle.slice(2).map(v => { return { @@ -900,9 +917,21 @@ module.exports = function (app, opts) { let alarmData = [] for (let aKey in apMergeDeVeAlarms) { let curStrucAlarm = apMergeDeVeAlarms[aKey] + if (proDebug) { + console.log(`查得数据异常、视频异常合并の告警:`); + console.log(apMergeDeVeAlarms); + console.log(`相关设备及测点信息:`); + console.log(deviceSensorRes); + } for (let de of curStrucAlarm.data_exception) { + if (!de.id) { + let corSensor = deviceSensorRes.find(ds => ds.iota_device_id == de.SourceId) + if (corSensor) { + de.id = corSensor.sensor + } + } let corVideoException = curStrucAlarm.video_exception.filter(v => { - // ! de.id 是告警的关联查出来的测点的id + // ! de.id 是告警信息关联查出来的测点的id return v.station.some(vs => vs.id == de.id) }) if (!corVideoException.length) { From 6045add003295d1e9a7d8494a787958d296cf4cf Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 16 Dec 2022 09:33:23 +0800 Subject: [PATCH 2/5] redisHost --- api/.vscode/launch.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 636e38a..e7a1783 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -21,7 +21,7 @@ "-g postgres://FashionAdmin:123456@10.8.30.156:5432/POMS", "-k 10.8.30.72:29092,10.8.30.73:29092,10.8.30.74:29092", "--iotaProxy http://10.8.30.157:17007", - "--redisHost 10.8.30.112", + "--redisHost localhost", "--redisPort 6379", "--apMergeDeVeAnxinProjectId 1,2,3", "--axyApiUrl http://127.0.0.1:4100", @@ -57,7 +57,7 @@ // 测试 "--clickHouseAnxincloud anxinyun1", "--clickHousePepEmis pepca8", - "--clickHouseProjectManage peppm", + "--clickHouseProjectManage peppm8", "--clickHouseVcmp video_access_dev", "--clickHouseDataAlarm default", "--clickHouseIot iot", From 200db1292bc779abb2e08ca84eb60ee614656dc7 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 16 Dec 2022 10:04:48 +0800 Subject: [PATCH 3/5] deviceIds.add --- api/app/lib/schedule/alarms_push.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 757202f..5a594a0 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -723,7 +723,7 @@ module.exports = function (app, opts) { // SourceTypeId 0: 'DTU' / 1: '传感器' / 2: '测点' if (d.SourceTypeId != 2) { - deviceIds.push(d.SourceId) + deviceIds.add(d.SourceId) } if (apMergeDeVeAlarms[d.StructureId]) { apMergeDeVeAlarms[d.StructureId].data_exception.push(d) From 1e580b0c635216d7ec9f611f484b838c9a285a15 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 16 Dec 2022 10:48:58 +0800 Subject: [PATCH 4/5] debug --- api/app/lib/schedule/alarms_push.js | 17 +++++++++-------- api/app/lib/utils/alarmHandle.js | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 5a594a0..b9c955b 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -893,7 +893,10 @@ module.exports = function (app, opts) { } if (Object.keys(apMergeDeVeAlarms).length) { - + if (proDebug) { + console.log(`查得数据异常、视频异常合并の告警:`); + console.log(apMergeDeVeAlarms); + } let deviceSensorRes = [] if (deviceIds.size) { const device4Search = [...deviceIds] @@ -902,7 +905,10 @@ module.exports = function (app, opts) { SELECT iota_device_id, sensor FROM t_device_sensor WHERE iota_device_id IN (${device4Search.join(',')}, '-1') `).toPromise() } - + if (proDebug) { + console.log(`相关设备及测点信息:`); + console.log(deviceSensorRes); + } let alarmTitle = dataAlarmTitle.concat( videoAlarmTitle.slice(2).map(v => { return { @@ -917,12 +923,7 @@ module.exports = function (app, opts) { let alarmData = [] for (let aKey in apMergeDeVeAlarms) { let curStrucAlarm = apMergeDeVeAlarms[aKey] - if (proDebug) { - console.log(`查得数据异常、视频异常合并の告警:`); - console.log(apMergeDeVeAlarms); - console.log(`相关设备及测点信息:`); - console.log(deviceSensorRes); - } + for (let de of curStrucAlarm.data_exception) { if (!de.id) { let corSensor = deviceSensorRes.find(ds => ds.iota_device_id == de.SourceId) diff --git a/api/app/lib/utils/alarmHandle.js b/api/app/lib/utils/alarmHandle.js index cdc0807..a9fdf5a 100644 --- a/api/app/lib/utils/alarmHandle.js +++ b/api/app/lib/utils/alarmHandle.js @@ -110,7 +110,7 @@ module.exports = function (app, opts) { } let pepProjects = pepPojectIds.size ? await clickHouse.projectManage.query(` - SELECT id, project_name FROM t_pim_project WHERE id IN (${[...pepPojectIds]}, -1)` + SELECT id, project_name FROM t_pim_project WHERE id IN (${[...pepPojectIds].join(',')}, -1)` ).toPromise() : []; return { projects, pepProjects }; From a5e2b839742708fcac5e46990c26ff8df0b1bad8 Mon Sep 17 00:00:00 2001 From: "gao.zhiyuan" Date: Fri, 16 Dec 2022 11:27:02 +0800 Subject: [PATCH 5/5] device4Search --- api/app/lib/schedule/alarms_push.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index b9c955b..6c4d851 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -902,7 +902,12 @@ module.exports = function (app, opts) { const device4Search = [...deviceIds] .map(id => "'" + id + "'") deviceSensorRes = await clickHouse.anxinyun.query(` - SELECT iota_device_id, sensor FROM t_device_sensor WHERE iota_device_id IN (${device4Search.join(',')}, '-1') + SELECT + iota_device_id, sensor + FROM t_device_sensor + WHERE iota_device_id + ${device4Search.length > 1 ? `IN (${device4Search.join(',')})` : `= ${device4Search[0]}`} + `).toPromise() } if (proDebug) {