diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 4a9b857..eeacd6b 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -174,16 +174,17 @@ async function groupStatistic (ctx) { console.log(`查询pepm项目`, pepmProjectIdArr.join(',')); let pepmCustomerLevelRes = pepmProjectIdArr.length ? await clickHouse.projectManage.query( ` - SELECT DISTINCT t_rpm_customer_level.id AS id, t_rpm_customer_level.name AS name FROM t_pim_project - LEFT JOIN t_rpm_customer - ON t_rpm_customer.id = t_pim_project.related_customers_id - LEFT JOIN t_rpm_customer_level - ON t_rpm_customer_level.id = t_rpm_customer.level + SELECT t_rpm_customer_level.id AS id, t_rpm_customer_level.name AS name, t_pim_project.id AS projectId + FROM t_pim_project + LEFT JOIN t_rpm_customer + ON t_rpm_customer.id = t_pim_project.related_customers_id + LEFT JOIN t_rpm_customer_level + ON t_rpm_customer_level.id = t_rpm_customer.level WHERE t_pim_project.id IN (${pepmProjectIdArr.join(',')},-1) ` ).toPromise() : [] console.log(pepmCustomerLevelRes); - pepmCustomerLevelRes.sort((a, b) => a.id - b.id) + // pepmCustomerLevelRes = pepmCustomerLevelRes.filter(item => item && item.id > 0) // 统计安心云项目下的结构物 const strucRes = anxinProjectIdArr.length ? await clickHouse.anxinyun.query( @@ -245,10 +246,14 @@ async function groupStatistic (ctx) { ).toPromise() : [] let rslt = [] + // progectGroupList 是自定义分组信息 for (let pg of progectGroupList) { let strucCount = 0 let maxOffLineTime = 0 let todayAlarms = 0 + let pepmCustomerLevels = [] + + // groupProjectRes 是poms项目信息 let anxinProjectCount = groupProjectRes.reduce((count, gp) => { if (pg.pomsProjectIds.some(id => gp.id == id)) { // 如果 pg 分组信息 存储的 pomsProjectIds 运维项目id 和 真正的 groupProjectRes 运维项目id 相等 @@ -264,6 +269,13 @@ async function groupStatistic (ctx) { return p + c.alarmCount }, 0) // + if (gp.pepProjectId) { + let corLevel = pepmCustomerLevelRes.find(p => p.projectId == gp.pepProjectId) + if (corLevel) { + pepmCustomerLevels.push(corLevel) + } + } + // for (let { dataValues: off } of deviceOffTimeRes) { if (strucIdArr_.some((s) => s.strucId == off.structure)) { if (off.offline > maxOffLineTime) { @@ -274,13 +286,15 @@ async function groupStatistic (ctx) { } return count }, 0) + console.log(pg.id, pepmCustomerLevels); + pepmCustomerLevels.sort((a, b) => a.id - b.id) rslt.unshift({ ...pg.dataValues, strucCount, todayAlarms, maxOffLineTime, anxinProjectCount, - level: pepmCustomerLevelRes.length ? pepmCustomerLevelRes[0] : null + level: pepmCustomerLevels.length ? pepmCustomerLevels[0] : null }) }