wenlele 1 year ago
parent
commit
9e7537c6d8
  1. 146
      api/app/lib/controllers/project/group.js
  2. 11
      script/3.1/schema/3.updata_struc_off .sql
  3. 219
      web/client/src/sections/projectGroup/containers/bigscreen.jsx

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

@ -255,6 +255,8 @@ async function groupStatisticOnline (ctx) {
// 查在线率 // 查在线率
const strucOnlineClient = ctx.app.fs.esclient.strucOnline const strucOnlineClient = ctx.app.fs.esclient.strucOnline
console.log('es数据,', strucOnlineClient)
const onlineRes = await strucOnlineClient.search({ const onlineRes = await strucOnlineClient.search({
index: strucOnlineClient.config.index, index: strucOnlineClient.config.index,
type: strucOnlineClient.config.type, type: strucOnlineClient.config.type,
@ -288,6 +290,7 @@ async function groupStatisticOnline (ctx) {
] ]
} }
}) })
console.log('es数据,', onlineRes.hits.hits.length,onlineRes)
for (let struc of strucRes) { for (let struc of strucRes) {
let curOnline = let curOnline =
@ -318,10 +321,153 @@ 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 = { module.exports = {
groupList, groupList,
editGroup, editGroup,
delGroup, delGroup,
groupStatistic, groupStatistic,
groupStatisticOnline, groupStatisticOnline,
groupStatisticAlarm,
groupProject
}; };

11
script/3.1/schema/3.updata_struc_off .sql

@ -0,0 +1,11 @@
alter table t_structure_off
add totnum integer;
comment on column t_structure_off.totnum is '测点总数';
alter table t_structure_off
add offnum integer;
comment on column t_structure_off.offnum is '离线个数';

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

@ -28,7 +28,6 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
const [biggest, setBiggest] = useState()// const [biggest, setBiggest] = useState()//
const [mockData, setMockData] = useState()// const [mockData, setMockData] = useState()//
const [xData, setXData] = useState([])// const [xData, setXData] = useState([])//
const self = useRef({ myChart: null }); const self = useRef({ myChart: null });
@ -64,7 +63,188 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
} }
}, []) }, [])
// const mockData=[
// {
// "name": "西",
// "id": 2957,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "-绿",
// "id": 2966,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "-绿",
// "id": 2967,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 2973,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 2975,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 2977,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 2988,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3004,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "驿",
// "id": 3007,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3008,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3010,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3023,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3024,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3025,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3033,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3034,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3035,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3036,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3037,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3038,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3039,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3040,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3041,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3042,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3043,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3044,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3045,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3047,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3048,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// {
// "name": "",
// "id": 3049,
// "alarmCount": 0,
// "dealAlarmCount": 0
// },
// ]
useEffect(() => { useEffect(() => {
const overview = document.getElementById("alarmRank"); const overview = document.getElementById("alarmRank");
if (overview) { if (overview) {
@ -87,6 +267,7 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
interrupt.update(); interrupt.update();
} }
}) })
useEffect(() => { useEffect(() => {
const maxCombinedValue = mockData?.reduce((max, item) => { const maxCombinedValue = mockData?.reduce((max, item) => {
const combinedMax = Math.max(item.alarmCount, item.dealAlarmCount); const combinedMax = Math.max(item.alarmCount, item.dealAlarmCount);
@ -95,7 +276,6 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
} }
return max; return max;
}, -Infinity) }, -Infinity)
console.log('setAlarmData4',maxCombinedValue)
const bigD= Math.ceil(maxCombinedValue/50)*50 const bigD= Math.ceil(maxCombinedValue/50)*50
if(bigD==0){ if(bigD==0){
setXData([5,4,3,2,1,0,1,2,3,4,5])//0 setXData([5,4,3,2,1,0,1,2,3,4,5])//0
@ -103,7 +283,16 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
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]) 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) setBiggest(bigD)
},[]) if (mockData && mockData.length > 3 && mockData.length < 21) {
const newArray = mockData.slice(3)
setAlarmData(newArray)
}
if (mockData && mockData.length > 21) {
//2020
const newArray = mockData.slice(3, 20)
setAlarmData(newArray)
}
},[mockData])
// const mockData=[ // const mockData=[
// {id: 1,name: '',alarmCount: 200,dealAlarmCount: 23}, // {id: 1,name: '',alarmCount: 200,dealAlarmCount: 23},
@ -130,21 +319,6 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
// {id: 22,name: '22',alarmCount: 27,dealAlarmCount: 22}, // {id: 22,name: '22',alarmCount: 27,dealAlarmCount: 22},
// {id: 23,name: '23',alarmCount: 26,dealAlarmCount: 21}, // {id: 23,name: '23',alarmCount: 26,dealAlarmCount: 21},
// ] // ]
useEffect(() => {
if (mockData && mockData.length > 3 && mockData.length < 21) {
const newArray = mockData.slice(3)
setAlarmData(newArray)
}
if (mockData && mockData.length > 21) {
//2020
const newArray = mockData.slice(3, 20)
setAlarmData(newArray)
}
}, [])
let statisticOnline = (groupId) => { let statisticOnline = (groupId) => {
dispatch(actions.projectGroup.groupStatisticOnline({ groupId })).then(res => { dispatch(actions.projectGroup.groupStatisticOnline({ groupId })).then(res => {
if (res.success) { if (res.success) {
@ -179,13 +353,11 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
// }) // })
// } // }
// }) // })
// } // }
function formatDate (date) { function formatDate (date) {
var year = date.getFullYear(); var year = date.getFullYear();
var month = String(date.getMonth() + 1).padStart(2, '0'); var month = String(date.getMonth() + 1).padStart(2, '0');
@ -246,10 +418,6 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
}; };
}, [proportion]); }, [proportion]);
// console.log('setAlarmData3',alarmData)
// console.log(groupStatisticOnline);
return ( return (
<div className='project-group'> <div className='project-group'>
<Header match={match} history={history} /> <Header match={match} history={history} />
@ -444,6 +612,7 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
</div> </div>
</div> </div>
<div id='alarmRank' style={{ height: clientHeight * 0.55 - 150, position: 'relative' }}> <div id='alarmRank' style={{ height: clientHeight * 0.55 - 150, position: 'relative' }}>
{mockData && mockData[0] ? (<div style={{ display: 'flex', marginTop: 15, alignItems: 'center' }}> {mockData && mockData[0] ? (<div style={{ display: 'flex', marginTop: 15, alignItems: 'center' }}>
<div class='rankDiv'> <div class='rankDiv'>
<img src='/assets/images/projectGroup/first.png'></img> <img src='/assets/images/projectGroup/first.png'></img>

Loading…
Cancel
Save