|
|
@ -241,10 +241,19 @@ async function groupStatisticOnline (ctx) { |
|
|
|
|
|
|
|
const strucRes = strucIdArr.length ? await clickHouse.anxinyun.query( |
|
|
|
` |
|
|
|
SELECT * FROM t_structure WHERE id IN (${[...strucIdArr].join(',')}); |
|
|
|
SELECT name, id FROM t_structure WHERE id IN (${[...strucIdArr].join(',')}); |
|
|
|
` |
|
|
|
).toPromise() : [] |
|
|
|
|
|
|
|
// 查中断时间
|
|
|
|
const maxOfflineTimeRes = strucIdArr.length ? await models.StructureOff.findAll({ |
|
|
|
where: { |
|
|
|
structure: { $in: strucIdArr }, |
|
|
|
state: 0 |
|
|
|
} |
|
|
|
}) : [] |
|
|
|
|
|
|
|
// 查在线率
|
|
|
|
const strucOnlineClient = ctx.app.fs.esclient.strucOnline |
|
|
|
const onlineRes = await strucOnlineClient.search({ |
|
|
|
index: strucOnlineClient.config.index, |
|
|
@ -264,7 +273,7 @@ async function groupStatisticOnline (ctx) { |
|
|
|
{ |
|
|
|
"terms": { |
|
|
|
"structure": strucIdArr, |
|
|
|
"structure": [1, 2, 3] |
|
|
|
// "structure": [1, 2, 3]
|
|
|
|
} |
|
|
|
} |
|
|
|
] |
|
|
@ -280,8 +289,26 @@ async function groupStatisticOnline (ctx) { |
|
|
|
} |
|
|
|
}) |
|
|
|
|
|
|
|
for (let struc of strucRes) { |
|
|
|
let curOnline = |
|
|
|
onlineRes.hits.hits |
|
|
|
.filter((h) => h._source.structure == struc.id) |
|
|
|
// .sort((a, b) => {
|
|
|
|
// return a._source.collect_time - b._source.collect_time
|
|
|
|
// })
|
|
|
|
.map(s => { |
|
|
|
return { |
|
|
|
...s._source, |
|
|
|
rate: s._source.online / s._source.total * 100 |
|
|
|
} |
|
|
|
}) |
|
|
|
let curOffline = maxOfflineTimeRes.find((o) => o.structure == struc.id) |
|
|
|
struc.online = curOnline |
|
|
|
struc.offline = curOffline || {} |
|
|
|
} |
|
|
|
|
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = onlineRes.hits.hits; |
|
|
|
ctx.body = strucRes; |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |
|
|
|
ctx.status = 400; |
|
|
|