Browse Source

项目集类型

dev
CODE 1 year ago
parent
commit
8e35db39d5
  1. 94
      api/app/lib/controllers/project/group.js
  2. 2
      api/app/lib/schedule/alarms_push.js
  3. 4
      web/client/src/sections/projectGroup/containers/statistic.jsx

94
api/app/lib/controllers/project/group.js

@ -158,12 +158,31 @@ async function groupStatistic (ctx) {
// 获取所有的 安心云项目id // 获取所有的 安心云项目id
let anxinProjectIds = new Set() let anxinProjectIds = new Set()
let pepmProjectIds = new Set()
for (let project of groupProjectRes) { for (let project of groupProjectRes) {
for (let projectId of project.anxinProjectId) { for (let projectId of project.anxinProjectId) {
anxinProjectIds.add(projectId) anxinProjectIds.add(projectId)
} }
if (project.pepProjectId) {
pepmProjectIds.add(project.pepProjectId)
}
} }
let anxinProjectIdArr = Array.from(anxinProjectIds) 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( const strucRes = anxinProjectIdArr.length ? await clickHouse.anxinyun.query(
@ -260,6 +279,7 @@ async function groupStatistic (ctx) {
todayAlarms, todayAlarms,
maxOffLineTime, maxOffLineTime,
anxinProjectCount, anxinProjectCount,
level: pepmCustomerLevelRes.length ? pepmCustomerLevelRes[0] : null
}) })
} }
@ -587,39 +607,39 @@ async function groupProject (ctx) {
} }
async function getProjectWorkOrders(ctx){ async function getProjectWorkOrders (ctx) {
try{ try {
// 计算一个月前的日期 // 计算一个月前的日期
const oneMonthAgo = moment().subtract(1, 'months').toDate() const oneMonthAgo = moment().subtract(1, 'months').toDate()
const { models } = ctx.fs.dc const { models } = ctx.fs.dc
const sequelize = ctx.fs.dc.ORM const sequelize = ctx.fs.dc.ORM
const { projectIds } = ctx.query const { projectIds } = ctx.query
if(projectIds&&projectIds.length){ if (projectIds && projectIds.length) {
const projectIdsArr=projectIds.split(',').map(Number) const projectIdsArr = projectIds.split(',').map(Number)
const res= await models.FormDataTable.findAll({ const res = await models.FormDataTable.findAll({
attributes: [ attributes: [
'projectId', 'projectId',
[sequelize.fn('COUNT', sequelize.col('id')), 'count'], [sequelize.fn('COUNT', sequelize.col('id')), 'count'],
], ],
where: { where: {
projectId: { projectId: {
$in: projectIdsArr, $in: projectIdsArr,
}, },
startTime: { startTime: {
$gte: oneMonthAgo, $gte: oneMonthAgo,
}, },
}, },
group: ['projectId'], group: ['projectId'],
order: [[sequelize.fn('COUNT', sequelize.col('id')), 'DESC']], order: [[sequelize.fn('COUNT', sequelize.col('id')), 'DESC']],
}) })
ctx.body=res ctx.body = res
ctx.status=200 ctx.status = 200
}else{ } else {
ctx.body='没有查询到数据' ctx.body = '没有查询到数据'
ctx.status=204 ctx.status = 204
} }
}catch(error){ } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {
@ -628,32 +648,32 @@ async function getProjectWorkOrders(ctx){
} }
} }
async function getWorkOrdersRepairRank(ctx){ async function getWorkOrdersRepairRank (ctx) {
try{ try {
const oneMonthAgo = moment().subtract(1, 'months').toDate() const oneMonthAgo = moment().subtract(1, 'months').toDate()
const { models } = ctx.fs.dc const { models } = ctx.fs.dc
const sequelize = ctx.fs.dc.ORM const sequelize = ctx.fs.dc.ORM
const { projectIds } = ctx.query const { projectIds } = ctx.query
if(projectIds&&projectIds.length){ if (projectIds && projectIds.length) {
const res= await models.FormDataTable.findAll({ const res = await models.FormDataTable.findAll({
where: { where: {
projectId: { projectId: {
$in: projectIds.split(',').map(Number) $in: projectIds.split(',').map(Number)
}, },
startTime: { startTime: {
$gte: oneMonthAgo, $gte: oneMonthAgo,
} }
}, },
order: [ order: [
[sequelize.literal('(EXTRACT(EPOCH FROM "end_time" - "start_time"))'), 'DESC'] [sequelize.literal('(EXTRACT(EPOCH FROM "end_time" - "start_time"))'), 'DESC']
] ]
}) })
ctx.body=res ctx.body = res
ctx.status=200 ctx.status = 200
}else{ } else {
ctx.body='没有查询到信息' ctx.body = '没有查询到信息'
ctx.status=204 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.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { ctx.body = {

2
api/app/lib/schedule/alarms_push.js

@ -1191,7 +1191,7 @@ module.exports = function (app, opts) {
alarms.AlarmCode AS AlarmCode, alarms.AlarmCode AS AlarmCode,
alarms.SourceTypeId AS SourceTypeId, alarms.SourceTypeId AS SourceTypeId,
alarms.StructureId AS StructureId, alarms.StructureId AS StructureId,
alarms.subStations AS subStations, alarms.subStations AS subStations
FROM FROM
alarms alarms
WHERE WHERE

4
web/client/src/sections/projectGroup/containers/statistic.jsx

@ -64,7 +64,9 @@ const Statistic = (props) => {
title: '项目集类型', title: '项目集类型',
dataIndex: "name", dataIndex: "name",
key: 'name', key: 'name',
render: (_, row) => '--' render: (_, row) => {
return row?.level ? row?.level?.name + ' 级' : '--'
}
}, { }, {
title: '项目个数', title: '项目个数',
dataIndex: "pomsProjectIds", dataIndex: "pomsProjectIds",

Loading…
Cancel
Save