From 4f839cd984f13c98bf63a9b1348a5809c2a7fb8f Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Thu, 7 Sep 2023 09:30:15 +0800 Subject: [PATCH] =?UTF-8?q?fix=2013020=20=E6=95=B0=E6=8D=AE=E5=A4=A7?= =?UTF-8?q?=E5=B1=8F-=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/group.js | 93 +++++++++++++----------- 1 file changed, 50 insertions(+), 43 deletions(-) diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 747320b..24bda85 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -195,7 +195,7 @@ async function groupStatistic (ctx) { ` SELECT StructureId,count(StructureId) AS alarmCount FROM alarms - WHERE StructureId IN (${[...strucIdArr].join(',')}) + WHERE StructureId IN (${strucIdArr.join(',')}, -1) AND AlarmGroupUnit = 8 AND StartTime >= '${moment().subtract(1, 'days').format('YYYY-MM-DD HH:mm:ss')}' group by StructureId @@ -278,9 +278,9 @@ async function groupStatisticOnline (ctx) { const strucRes = anxinProjectIds.size ? await clickHouse.anxinyun.query( ` SELECT - DISTINCT t_structure.id AS strucId, + DISTINCT t_structure.id AS id, t_project.id AS projectId, - t_structure.name AS strucName, + t_structure.name AS name, project_state FROM t_project @@ -318,51 +318,58 @@ async function groupStatisticOnline (ctx) { let strucIdArr = Array.from(strucIds) // 查中断时间 - const maxOfflineTimeRes = strucIdArr.length ? await models.StructureOff.findAll({ - where: { - structure: { $in: strucIdArr }, - state: 0, - offline: { $gt: 720 } - } - }) : [] + const maxOfflineTimeRes = strucIdArr.length ? + await models.StructureOff.findAll({ + where: { + structure: { $in: strucIdArr }, + state: 0, + offline: { $gt: 720 } + } + }) : [] // 查在线率 const strucOnlineClient = ctx.app.fs.esclient.strucOnline - const onlineRes = await strucOnlineClient.search({ - index: strucOnlineClient.config.index, - type: strucOnlineClient.config.type, - body: { - "query": { - "bool": { - "filter": [ - { - "range": { - "collect_time": { - "gte": `${moment().subtract(32, 'hours').format('YYYY-MM-DDTHH:mm:ss.SSS')}Z`, - // "gte": "2023-08-24T08:00:00.000Z", + const onlineRes = strucIdArr.length ? + await strucOnlineClient.search({ + index: strucOnlineClient.config.index, + type: strucOnlineClient.config.type, + body: { + "query": { + "bool": { + "filter": [ + { + "range": { + "collect_time": { + "gte": `${moment().subtract(32, 'hours').format('YYYY-MM-DDTHH:mm:ss.SSS')}Z`, + // "gte": "2023-08-24T08:00:00.000Z", + } + } + }, + { + "terms": { + "structure": strucIdArr, + // "structure": [1, 2, 3] } } - }, - { - "terms": { - "structure": strucIdArr, - // "structure": [1, 2, 3] - } + ] + } + }, + "sort": [ + { + "collect_time": { + "order": "asc" } - ] - } - }, - "sort": [ - { - "collect_time": { - "order": "asc" } - } - ], - "size": 10000 + ], + "size": 10000 + } + }) + : { + hits: { + hits: [] + } } - }) for (let struc of strucRes) { let curOnline = @@ -419,9 +426,9 @@ async function groupStatisticAlarm (ctx) { const strucRes = anxinProjectIds.size ? await clickHouse.anxinyun.query( ` SELECT - DISTINCT t_structure.id AS strucId, + DISTINCT t_structure.id AS id, t_project.id AS projectId, - t_structure.name AS strucName, + t_structure.name AS name, project_state FROM t_project @@ -463,7 +470,7 @@ async function groupStatisticAlarm (ctx) { ` SELECT StructureId,count(StructureId) AS alarmCount FROM alarms - WHERE StructureId IN (${[...strucIdArr].join(',')}) + WHERE StructureId IN (${strucIdArr.join(',')}, -1) AND AlarmGroupUnit = 8 AND StartTime >= '${moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm:ss')}' group by StructureId @@ -474,7 +481,7 @@ async function groupStatisticAlarm (ctx) { ` SELECT StructureId,count(StructureId) AS alarmCount FROM alarms - WHERE StructureId IN (${[...strucIdArr].join(',')}) + WHERE StructureId IN (${strucIdArr.join(',')}, -1) AND AlarmGroupUnit = 8 AND State = 4 AND StartTime >= '${moment().subtract(30, 'days').format('YYYY-MM-DD HH:mm:ss')}'