diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 39d0130..5a3d2b2 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -158,12 +158,31 @@ async function groupStatistic (ctx) { // 获取所有的 安心云项目id let anxinProjectIds = new Set() + let pepmProjectIds = new Set() for (let project of groupProjectRes) { for (let projectId of project.anxinProjectId) { anxinProjectIds.add(projectId) } + if (project.pepProjectId) { + pepmProjectIds.add(project.pepProjectId) + } } let anxinProjectIdArr = Array.from(anxinProjectIds) + let pepmProjectIdArr = Array.from(pepmProjectIds) + + // 查询pepm项目的客户等级 + 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 + RIGHT JOIN t_rpm_customer + ON t_rpm_customer.id = t_pim_project.related_customers_id + RIGHT 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() : [] + + pepmCustomerLevelRes.sort((a, b) => a.id - b.id) // 统计安心云项目下的结构物 const strucRes = anxinProjectIdArr.length ? await clickHouse.anxinyun.query( @@ -260,6 +279,7 @@ async function groupStatistic (ctx) { todayAlarms, maxOffLineTime, anxinProjectCount, + level: pepmCustomerLevelRes.length ? pepmCustomerLevelRes[0] : null }) } @@ -587,39 +607,39 @@ async function groupProject (ctx) { } -async function getProjectWorkOrders(ctx){ - try{ +async function getProjectWorkOrders (ctx) { + try { // 计算一个月前的日期 const oneMonthAgo = moment().subtract(1, 'months').toDate() const { models } = ctx.fs.dc const sequelize = ctx.fs.dc.ORM const { projectIds } = ctx.query - if(projectIds&&projectIds.length){ - const projectIdsArr=projectIds.split(',').map(Number) - const res= await models.FormDataTable.findAll({ + if (projectIds && projectIds.length) { + const projectIdsArr = projectIds.split(',').map(Number) + const res = await models.FormDataTable.findAll({ attributes: [ - 'projectId', - [sequelize.fn('COUNT', sequelize.col('id')), 'count'], + 'projectId', + [sequelize.fn('COUNT', sequelize.col('id')), 'count'], ], where: { - projectId: { - $in: projectIdsArr, - }, - startTime: { - $gte: oneMonthAgo, - }, + projectId: { + $in: projectIdsArr, + }, + startTime: { + $gte: oneMonthAgo, + }, }, group: ['projectId'], - order: [[sequelize.fn('COUNT', sequelize.col('id')), 'DESC']], - }) - ctx.body=res - ctx.status=200 - }else{ - ctx.body='没有查询到数据' - ctx.status=204 + order: [[sequelize.fn('COUNT', sequelize.col('id')), 'DESC']], + }) + ctx.body = res + ctx.status = 200 + } else { + ctx.body = '没有查询到数据' + ctx.status = 204 } - }catch(error){ + } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { @@ -628,32 +648,32 @@ async function getProjectWorkOrders(ctx){ } } -async function getWorkOrdersRepairRank(ctx){ - try{ +async function getWorkOrdersRepairRank (ctx) { + try { const oneMonthAgo = moment().subtract(1, 'months').toDate() const { models } = ctx.fs.dc - const sequelize = ctx.fs.dc.ORM + const sequelize = ctx.fs.dc.ORM const { projectIds } = ctx.query - if(projectIds&&projectIds.length){ - const res= await models.FormDataTable.findAll({ + if (projectIds && projectIds.length) { + const res = await models.FormDataTable.findAll({ where: { projectId: { $in: projectIds.split(',').map(Number) - }, - startTime: { - $gte: oneMonthAgo, - } + }, + startTime: { + $gte: oneMonthAgo, + } }, order: [ [sequelize.literal('(EXTRACT(EPOCH FROM "end_time" - "start_time"))'), 'DESC'] - ] + ] }) - ctx.body=res - ctx.status=200 - }else{ - ctx.body='没有查询到信息' - ctx.status=204 + ctx.body = res + ctx.status = 200 + } else { + ctx.body = '没有查询到信息' + ctx.status = 204 } @@ -661,7 +681,7 @@ async function getWorkOrdersRepairRank(ctx){ - }catch(error){ + } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index 107f662..5abb817 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/api/app/lib/schedule/alarms_push.js @@ -1191,7 +1191,7 @@ module.exports = function (app, opts) { alarms.AlarmCode AS AlarmCode, alarms.SourceTypeId AS SourceTypeId, alarms.StructureId AS StructureId, - alarms.subStations AS subStations, + alarms.subStations AS subStations FROM alarms WHERE diff --git a/web/client/src/sections/projectGroup/containers/statistic.jsx b/web/client/src/sections/projectGroup/containers/statistic.jsx index f7a8a18..72d7aa7 100644 --- a/web/client/src/sections/projectGroup/containers/statistic.jsx +++ b/web/client/src/sections/projectGroup/containers/statistic.jsx @@ -64,7 +64,9 @@ const Statistic = (props) => { title: '项目集类型', dataIndex: "name", key: 'name', - render: (_, row) => '--' + render: (_, row) => { + return row?.level ? row?.level?.name + ' 级' : '--' + } }, { title: '项目个数', dataIndex: "pomsProjectIds",