|
|
@ -108,6 +108,7 @@ async function groupStatistic (ctx) { |
|
|
|
const { models } = ctx.fs.dc; |
|
|
|
const { userId } = ctx.fs.api |
|
|
|
const { clickHouse } = ctx.app.fs |
|
|
|
const { utils: { judgeSuper, anxinStrucIdRange } } = ctx.app.fs |
|
|
|
const sequelize = ctx.fs.dc.orm |
|
|
|
|
|
|
|
const progectGroupList = await models.ProjectGroup.findAll({ |
|
|
@ -140,18 +141,46 @@ async function groupStatistic (ctx) { |
|
|
|
} |
|
|
|
let anxinProjectIdArr = Array.from(anxinProjectIds) |
|
|
|
|
|
|
|
// 统计安心云项目下的结构物id
|
|
|
|
const strucIdRes = await clickHouse.anxinyun.query( |
|
|
|
` |
|
|
|
SELECT * |
|
|
|
FROM t_project_structure |
|
|
|
WHERE project IN (${[...anxinProjectIdArr].join(',')}, -1) |
|
|
|
// 统计安心云项目下的结构物
|
|
|
|
const strucRes = anxinProjectIdArr.length ? await clickHouse.anxinyun.query( |
|
|
|
` |
|
|
|
).toPromise() |
|
|
|
SELECT |
|
|
|
t_project.id AS projectId, |
|
|
|
t_structure.id AS strucId, |
|
|
|
t_structure.name AS strucName, |
|
|
|
project_state |
|
|
|
FROM |
|
|
|
t_project |
|
|
|
LEFT JOIN |
|
|
|
t_project_structure |
|
|
|
ON t_project_structure.project = t_project.id |
|
|
|
LEFT JOIN |
|
|
|
t_project_structuregroup |
|
|
|
ON t_project_structuregroup.project = t_project.id |
|
|
|
LEFT JOIN |
|
|
|
t_structuregroup_structure |
|
|
|
ON t_structuregroup_structure.structuregroup = t_project_structuregroup.structuregroup |
|
|
|
LEFT JOIN |
|
|
|
t_project_construction |
|
|
|
ON t_project_construction.project = t_project.id |
|
|
|
LEFT JOIN |
|
|
|
t_structure_site |
|
|
|
ON t_structure_site.siteid = t_project_construction.construction |
|
|
|
RIGHT JOIN |
|
|
|
t_structure |
|
|
|
ON t_structure.id = t_project_structure.structure |
|
|
|
OR t_structure.id = t_structuregroup_structure.structure |
|
|
|
OR t_structure.id = t_structure_site.structid |
|
|
|
WHERE |
|
|
|
project_state != -1 |
|
|
|
AND |
|
|
|
t_project.id IN (${anxinProjectIdArr.join(',')},-1) |
|
|
|
` |
|
|
|
).toPromise() : [] |
|
|
|
|
|
|
|
let strucIds = new Set() |
|
|
|
for (let struc of strucIdRes) { |
|
|
|
strucIds.add(struc.structure) |
|
|
|
for (let struc of strucRes) { |
|
|
|
strucIds.add(struc.strucId) |
|
|
|
} |
|
|
|
|
|
|
|
let strucIdArr = Array.from(strucIds) |
|
|
@ -172,11 +201,11 @@ async function groupStatistic (ctx) { |
|
|
|
count += gp.anxinProjectId.length |
|
|
|
//
|
|
|
|
let strucIdArr_ = |
|
|
|
strucIdRes.filter(s => gp.anxinProjectId.includes(s.project)) |
|
|
|
strucRes.filter(s => gp.anxinProjectId.includes(s.projectId)) |
|
|
|
strucCount += strucIdArr_.length |
|
|
|
//
|
|
|
|
for (let { dataValues: off } of deviceOffTimeRes) { |
|
|
|
if (strucIdArr_.some((s) => s.structure == off.structure)) { |
|
|
|
if (strucIdArr_.some((s) => s.strucId == off.structure)) { |
|
|
|
if (off.offline > maxOffLineTime) { |
|
|
|
maxOffLineTime = off.offline |
|
|
|
} |
|
|
@ -233,17 +262,54 @@ async function groupStatisticOnline (ctx) { |
|
|
|
WHERE project IN (${[...anxinProjectIds].join(',')}, -1) |
|
|
|
` |
|
|
|
).toPromise() |
|
|
|
// 统计安心云项目下的结构物
|
|
|
|
const strucRes = anxinProjectIds.length ? await clickHouse.anxinyun.query( |
|
|
|
` |
|
|
|
SELECT |
|
|
|
t_project.id AS projectId, |
|
|
|
t_structure.id AS strucId, |
|
|
|
t_structure.name AS strucName, |
|
|
|
project_state |
|
|
|
FROM |
|
|
|
t_project |
|
|
|
LEFT JOIN |
|
|
|
t_project_structure |
|
|
|
ON t_project_structure.project = t_project.id |
|
|
|
LEFT JOIN |
|
|
|
t_project_structuregroup |
|
|
|
ON t_project_structuregroup.project = t_project.id |
|
|
|
LEFT JOIN |
|
|
|
t_structuregroup_structure |
|
|
|
ON t_structuregroup_structure.structuregroup = t_project_structuregroup.structuregroup |
|
|
|
LEFT JOIN |
|
|
|
t_project_construction |
|
|
|
ON t_project_construction.project = t_project.id |
|
|
|
LEFT JOIN |
|
|
|
t_structure_site |
|
|
|
ON t_structure_site.siteid = t_project_construction.construction |
|
|
|
RIGHT JOIN |
|
|
|
t_structure |
|
|
|
ON t_structure.id = t_project_structure.structure |
|
|
|
OR t_structure.id = t_structuregroup_structure.structure |
|
|
|
OR t_structure.id = t_structure_site.structid |
|
|
|
WHERE |
|
|
|
project_state != -1 |
|
|
|
AND |
|
|
|
t_project.id IN (${anxinProjectIds.join(',')},-1) |
|
|
|
` |
|
|
|
).toPromise() : [] |
|
|
|
|
|
|
|
let strucIds = new Set() |
|
|
|
for (let struc of strucIdRes) { |
|
|
|
strucIds.add(struc.structure) |
|
|
|
for (let struc of strucRes) { |
|
|
|
strucIds.add(struc.strucId) |
|
|
|
} |
|
|
|
let strucIdArr = Array.from(strucIds) |
|
|
|
|
|
|
|
const strucRes = strucIdArr.length ? await clickHouse.anxinyun.query( |
|
|
|
` |
|
|
|
SELECT name, id FROM t_structure WHERE id IN (${[...strucIdArr].join(',')}); |
|
|
|
` |
|
|
|
).toPromise() : [] |
|
|
|
// const strucRes = strucIdArr.length ? await clickHouse.anxinyun.query(
|
|
|
|
// `
|
|
|
|
// SELECT name, id FROM t_structure WHERE id IN (${[...strucIdArr].join(',')});
|
|
|
|
// `
|
|
|
|
// ).toPromise() : []
|
|
|
|
|
|
|
|
// 查中断时间
|
|
|
|
const maxOfflineTimeRes = strucIdArr.length ? await models.StructureOff.findAll({ |
|
|
@ -255,8 +321,6 @@ async function groupStatisticOnline (ctx) { |
|
|
|
|
|
|
|
// 查在线率
|
|
|
|
const strucOnlineClient = ctx.app.fs.esclient.strucOnline |
|
|
|
console.log('es参数,', strucOnlineClient.config) |
|
|
|
console.log('strucIdArr', strucIdArr) |
|
|
|
|
|
|
|
const onlineRes = await strucOnlineClient.search({ |
|
|
|
index: strucOnlineClient.config.index, |
|
|
|