wenlele 1 year ago
parent
commit
3ad6f78f6b
  1. 6
      api/.vscode/launch.json
  2. 145
      api/app/lib/controllers/project/group.js
  3. 38
      web/client/src/sections/projectGroup/containers/bigscreen.jsx

6
api/.vscode/launch.json

@ -46,6 +46,8 @@
// click
"--clickHouseUrl http://10.8.30.95",
"--clickHousePort 30123",
// "--clickHouseUrl http://218.3.126.49",
// "--clickHousePort 18123",
// click
// "--clickHouseUrl http://10.8.30.161",
// "--clickHousePort 30123",
@ -58,8 +60,8 @@
// "--clickHousePort 8123",
//
// * 2
// "--clickHouseUser ",
// "--clickHousePassword ",
// "--clickHouseUser default",
// "--clickHousePassword Wbo@hi1I",
//
// "--clickHouseAnxincloud anxinyun",
// "--clickHousePepEmis pepca",

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

@ -116,7 +116,7 @@ async function groupStatistic (ctx) {
}
})
// 获取全部的 poms 项目id
// 获取全部的 poms 项目id 并构建关系
let pomsProjectIds = new Set()
for (let group of progectGroupList) {
for (let projectId of group.pomsProjectIds) {
@ -318,153 +318,10 @@ async function groupStatisticOnline (ctx) {
}
}
async function groupStatisticAlarm (ctx) {
try {
const { models } = ctx.fs.dc;
const { groupId } = ctx.query
const sequelize = ctx.fs.dc.orm
const { clickHouse } = ctx.app.fs
const pomsProjectRes = await sequelize.query(`
SELECT project_correlation.anxin_project_id
FROM project_group
JOIN project_correlation
ON project_correlation.id = ANY(project_group.poms_project_ids)
WHERE project_group.id = ${groupId};
`)
const anxinProjectIds = new Set()
for (let pomsProject of (pomsProjectRes[0] || [])) {
for (let pid of pomsProject.anxin_project_id)
anxinProjectIds.add(pid)
}
const strucIdRes = anxinProjectIds.size ? await clickHouse.anxinyun.query(
`
SELECT *
FROM t_project_structure
WHERE project IN (${[...anxinProjectIds].join(',')}, -1)
`
).toPromise() : []
let strucIds = new Set()
for (let struc of strucIdRes) {
strucIds.add(struc.structure)
}
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() : []
// 查一周内超阈值告警的个数
strucIdArr = [1]
const alarmRes = strucIdArr.length ? await clickHouse.dataAlarm.query(
`
SELECT StructureId,count(StructureId) AS alarmCount
FROM alarms
WHERE StructureId IN (${[...strucIdArr].join(',')})
AND AlarmGroupUnit = 8
AND StartTime >= '${moment().subtract(7, 'days').format('YYYY-MM-DD HH:mm:ss')}'
group by StructureId
`
).toPromise() : []
const alarmDealRes = strucIdArr.length ? await clickHouse.dataAlarm.query(
`
SELECT StructureId,count(StructureId) AS alarmCount
FROM alarms
WHERE StructureId IN (${[...strucIdArr].join(',')})
AND AlarmGroupUnit = 8
AND State = 4
AND StartTime >= '${moment().subtract(30, 'days').format('YYYY-MM-DD HH:mm:ss')}'
group by StructureId
`
).toPromise() : []
for (let struc of strucRes) {
let corAlarm = alarmRes.find((o) => o.StructureId == struc.id)
let corDealAlarm = alarmDealRes.find((o) => o.StructureId == struc.id)
struc.alarmCount = corAlarm ? corAlarm.alarmCount : 0
struc.dealAlarmCount = corDealAlarm ? corDealAlarm.alarmCount : 0
}
strucRes.sort((a, b) => b.alarmCount - a.alarmCount)
ctx.status = 200;
ctx.body = strucRes;
// ctx.body = [{
// id: 1,
// name: '测试结构物1',
// alarmCount: 128,
// dealAlarmCount: 23
// }];
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
async function groupProject (ctx) {
try {
const { models } = ctx.fs.dc;
const { groupId } = ctx.query
const { clickHouse } = ctx.app.fs
const findOne = await models.ProjectGroup.findOne({ where: { id: groupId } })
const proRes = await models.ProjectCorrelation.findAll({ where: { id: { $in: findOne.pomsProjectIds } } })
let pepProjectIds = new Set()
for (let p of proRes) {
if (p.pepProjectId) {
pepProjectIds.add(p.pepProjectId)
}
}
const pepProjectRes = pepProjectIds.size ?
await clickHouse.projectManage.query(
`
SELECT
t_pim_project.id AS id,
t_pim_project.project_name AS project_name,
t_pim_project.isdelete AS isdelete,
t_pim_project_construction.construction_status_id AS construction_status_id,
t_pim_project_state.construction_status AS construction_status
FROM t_pim_project
LEFT JOIN t_pim_project_construction
ON t_pim_project.id = t_pim_project_construction.project_id
LEFT JOIN t_pim_project_state
ON t_pim_project_construction.construction_status_id = t_pim_project_state.id
WHERE id IN (${[...pepProjectIds].join(',')}, -1)
`
).toPromise() :
[]
for (let p of proRes) {
const corPro = pepProjectRes.find(pp => pp.id == p.pepProjectId) || {}
p.dataValues.pepProjectName = corPro.project_name
}
ctx.status = 200;
ctx.body = proRes;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined
}
}
}
module.exports = {
groupList,
editGroup,
delGroup,
groupStatistic,
groupStatisticOnline,
groupStatisticAlarm,
groupProject,
};

38
web/client/src/sections/projectGroup/containers/bigscreen.jsx

@ -94,12 +94,17 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
return combinedMax;
}
return max;
}, -Infinity)
const bigD = Math.ceil(maxCombinedValue / 50) * 50
50, 40, 30, 20, 10, 0
setXData([bigD, (bigD - bigD / 5), (bigD - bigD * 2 / 5), (bigD - bigD * 3 / 5), (bigD - bigD * 4 / 5), 0, (bigD - bigD * 4 / 5), (bigD - bigD * 3 / 5), (bigD - bigD * 2 / 5), (bigD - bigD / 5), bigD])
setBiggest(bigD)
}, [])
}, -Infinity)
console.log('setAlarmData4',maxCombinedValue)
const bigD= Math.ceil(maxCombinedValue/50)*50
if(bigD==0){
setXData([5,4,3,2,1,0,1,2,3,4,5])//0
}else{
setXData([bigD,(bigD-bigD/5),(bigD-bigD*2/5),(bigD-bigD*3/5),(bigD-bigD*4/5),0,(bigD-bigD*4/5),(bigD-bigD*3/5),(bigD-bigD*2/5),(bigD-bigD/5),bigD])
}
setBiggest(bigD)
},[])
// const mockData=[
// {id: 1,name: '',alarmCount: 200,dealAlarmCount: 23},
// {id: 2,name: '2',alarmCount: 300,dealAlarmCount: 22},
@ -180,6 +185,7 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
function formatDate (date) {
var year = date.getFullYear();
var month = String(date.getMonth() + 1).padStart(2, '0');
@ -241,6 +247,8 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
}, [proportion]);
// console.log('setAlarmData3',alarmData)
// console.log(groupStatisticOnline);
return (
<div className='project-group'>
@ -423,7 +431,7 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
</div>
<div style={{ width: '100%', height: "calc(55% - 24px)", display: 'flex', marginTop: 24 }}>
<Card title='告警排名TOP20' style={{
<Card title='告警排名TOP20' style={{
width: "calc(50% - 8px)", height: "100%", marginRight: 16
}} >
{mockData && mockData.length > 0 ? (<div style={{ height: '100%' }}>
@ -443,10 +451,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
<div class='structDiv'>{mockData[0]?.name?.length > 5 ? <Tooltip content={mockData[0]?.name}>{mockData[0]?.name.substring(0, 5) + '...'}</Tooltip> : mockData[0]?.name}</div>
<div class='barChartDiv'>
<div style={{ width: '50%', display: 'flex', justifyContent: 'flex-end' }}>
<div class='alarms' style={{ width: (mockData[0].alarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='alarms' style={{ width:(biggest>0? ((mockData[0].alarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
<div style={{ width: '50%', display: 'flex', }}>
<div class='dealAlarms' style={{ width: (mockData[0].dealAlarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='dealAlarms' style={{ width: (biggest>0? ((mockData[0].dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
</div>
</div>) : ''
@ -458,10 +466,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
<div class='structDiv'>{mockData[1]?.name?.length > 5 ? <Tooltip content={mockData[1]?.name}>{mockData[1]?.name.substring(0, 5) + '...'}</Tooltip> : mockData[0]?.name}</div>
<div class='barChartDiv'>
<div style={{ width: '50%', display: 'flex', justifyContent: 'flex-end' }}>
<div class='alarms' style={{ width: (mockData[1].alarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='alarms' style={{ width: (biggest>0? ((mockData[1].alarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
<div style={{ width: '50%', display: 'flex', }}>
<div class='dealAlarms' style={{ width: (mockData[1].dealAlarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='dealAlarms' style={{ width: (biggest>0? ((mockData[1].dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
</div>
</div>) : ''
@ -473,10 +481,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
<div class='structDiv'>{mockData[2]?.name?.length > 5 ? <Tooltip content={mockData[2]?.name}>{mockData[2]?.name.substring(0, 5) + '...'}</Tooltip> : mockData[0]?.name}</div>
<div class='barChartDiv'>
<div style={{ width: '50%', display: 'flex', justifyContent: 'flex-end' }}>
<div class='alarms' style={{ width: (mockData[2].alarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='alarms' style={{ width: (biggest>0? ((mockData[2].alarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
<div style={{ width: '50%', display: 'flex', }}>
<div class='dealAlarms' style={{ width: (mockData[2].dealAlarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='dealAlarms' style={{ width:(biggest>0? ((mockData[2].dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
</div>
</div>) : ''
@ -490,10 +498,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
<div class='structDiv'>{item.name?.length > 5 ? <Tooltip content={item.name}>{item.name.substring(0, 5) + '...'}</Tooltip> : item.name}</div>
<div class='barChartDiv'>
<div style={{ width: '50%', display: 'flex', justifyContent: 'flex-end' }}>
<div class='alarms' style={{ width: (item.alarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='alarms' style={{ width:(biggest>0?((item.alarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
<div style={{ width: '50%', display: 'flex', }}>
<div class='dealAlarms' style={{ width: (item.dealAlarmCount / biggest) * 100 || '%', height: '100%' }}></div>
<div class='dealAlarms' style={{ width:(biggest>0? ((item.dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}></div>
</div>
</div>

Loading…
Cancel
Save