Browse Source

fix 13020 数据大屏-数据不展示

dev
CODE 1 year ago
parent
commit
4f839cd984
  1. 93
      api/app/lib/controllers/project/group.js

93
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')}'

Loading…
Cancel
Save