diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 7b45a9f..53a43e2 100644 --- a/api/.vscode/launch.json +++ b/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", diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 63a12ee..bead78f 100644 --- a/api/app/lib/controllers/project/group.js +++ b/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, }; \ No newline at end of file diff --git a/web/client/src/sections/projectGroup/containers/bigscreen.jsx b/web/client/src/sections/projectGroup/containers/bigscreen.jsx index 14d5e4b..af0f43b 100644 --- a/web/client/src/sections/projectGroup/containers/bigscreen.jsx +++ b/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 (
@@ -423,7 +431,7 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
- {mockData && mockData.length > 0 ? (
@@ -443,10 +451,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
{mockData[0]?.name?.length > 5 ? {mockData[0]?.name.substring(0, 5) + '...'} : mockData[0]?.name}
-
+
0? ((mockData[0].alarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
-
+
0? ((mockData[0].dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
) : '' @@ -458,10 +466,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
{mockData[1]?.name?.length > 5 ? {mockData[1]?.name.substring(0, 5) + '...'} : mockData[0]?.name}
-
+
0? ((mockData[1].alarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
-
+
0? ((mockData[1].dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
) : '' @@ -473,10 +481,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
{mockData[2]?.name?.length > 5 ? {mockData[2]?.name.substring(0, 5) + '...'} : mockData[0]?.name}
-
+
0? ((mockData[2].alarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
-
+
0? ((mockData[2].dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
) : '' @@ -490,10 +498,10 @@ const Bigscreen = ({ dispatch, actions, user, match, history, clientHeight, grou
{item.name?.length > 5 ? {item.name.substring(0, 5) + '...'} : item.name}
-
+
0?((item.alarmCount / biggest) * 100 || '%'):0), height: '100%' }}>
-
+
0? ((item.dealAlarmCount / biggest) * 100 || '%'):0), height: '100%' }}>