From 7bf0f4e38ae78c8d72287626cdb74aefac4a65e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?zhaobing=E2=80=99?= Date: Thu, 16 Nov 2023 09:53:50 +0800 Subject: [PATCH] feat:fix bugs --- api/app/lib/controllers/monitor/index.js | 47 ++++++++++++------- .../data/components/lineTimeChartTemplate.jsx | 13 +++-- .../data/containers/dataComponent.jsx | 4 +- .../sections/problem/components/tableData.jsx | 2 +- 4 files changed, 42 insertions(+), 24 deletions(-) diff --git a/api/app/lib/controllers/monitor/index.js b/api/app/lib/controllers/monitor/index.js index 8425426..59e451c 100644 --- a/api/app/lib/controllers/monitor/index.js +++ b/api/app/lib/controllers/monitor/index.js @@ -123,15 +123,16 @@ async function getMonitorData(ctx) { try { const { clickHouse } = ctx.app.fs const { factorId, sensorId, startTime, endTime } = ctx.query + const projectId=sensorId.split('-')[0] const factorsList = await clickHouse.alarmLocal.query(`SELECT FactorID,Items,ItemNames,ItemUnits FROM factors - WHERE FactorID=${factorId} + WHERE FactorID=${factorId} AND Project='${projectId}' `).toPromise() || [] const dataArray = sensorId.split(',') const transformedArray = dataArray.map(item => { return item.replace('-',':')+'' }) const id=`(${transformedArray.map(id => `'${id}'`).join(',')})` - const monitorData = await clickHouse.alarmLocal.query(`SELECT SensorId,CollectTime,Values FROM themes + const monitorData = await clickHouse.alarmLocal.query(`SELECT distinct SensorId,CollectTime,Values FROM themes WHERE SensorId in ${id} AND CollectTime >= toDate('${startTime}') AND CollectTime <= toDate('${endTime}') @@ -144,11 +145,14 @@ async function getMonitorData(ctx) { let factors = [] //因素名词 let factorNames = [] + //单位 + let c=[] factorsList.map(item => { factors = item.ItemNames.split(',') factorNames = item.Items.split(',') - factors.map((child,index)=> { - items[factorNames[index]] = { name: child, unit:factorNames[index] } + c = item.ItemUnits.split(',') + factorNames.map((child,index)=> { + items[factorNames[index]] = { name:factors[index] , unit:c[index] } }) }) } @@ -156,18 +160,29 @@ async function getMonitorData(ctx) { let sensors = [] let data=[] if(sensor&&monitorData&&sensor.length && monitorData.length){ - sensor.map(item=>{ - const filterData=monitorData.filter(p=>p.SensorId==item.ID) - filterData.map(data=>{ - const values = {} - Object.keys(items).forEach(key => { - const index = Object.keys(items).indexOf(key) - values[key] = data.Values[index] - }) - sensors.push({ values, time: moment(data.CollectTime).format('YYYY-MM-DD HH:mm:ss') }) - }) - data.push({id:item.ID,name:item.SensorLocationDescription,data:sensors}) - }) + sensor.forEach((item) => { + // 过滤与当前传感器相关的数据 + const sensorDataArray = monitorData.filter((d) => d.SensorId == item.ID) + // 构建最终的传感器数据结构 + const sensorDataItem = { + id: item.ID, + name: item.SensorLocationDescription, + data: sensorDataArray.map((d) => { + // 根据 item 对象进行映射 + const values = {}; + itemKeys = Object.keys(items) + itemKeys.forEach((key, index) => { + values[key] = d.Values[index]; + }); + + return { + time: d.CollectTime, + values: values + }; + }) + }; + data.push(sensorDataItem) + }) } ctx.body = { items, sensors: data } ctx.status = 200 diff --git a/web/client/src/sections/data/components/lineTimeChartTemplate.jsx b/web/client/src/sections/data/components/lineTimeChartTemplate.jsx index e5c52ae..dea22b9 100644 --- a/web/client/src/sections/data/components/lineTimeChartTemplate.jsx +++ b/web/client/src/sections/data/components/lineTimeChartTemplate.jsx @@ -179,11 +179,14 @@ class LineTimeChart extends Component { // }); // dataset.unshift(x); //组织后端数据组织data - let data = this.props.data; - let dataArray = [], types = {}; - let xAxisValue = props.xAxis || 'time'; - let yAxisValue = props.yAxis || 'value'; - data.map(dd => { + let data = this.props.data + let dataArray = [], types = {} + let xAxisValue = props.xAxis || 'time' + let yAxisValue = props.yAxis || 'value' + const data1=[] + data.forEach(item=>data1.push(item)) + data1.sort((a, b) => new Date(a.time) - new Date(b.time)) + data1.map(dd => { if (!types[dd.name]) { types[dd.name] = Object.assign({ name: dd.name, data: [] diff --git a/web/client/src/sections/data/containers/dataComponent.jsx b/web/client/src/sections/data/containers/dataComponent.jsx index d469122..4e21990 100644 --- a/web/client/src/sections/data/containers/dataComponent.jsx +++ b/web/client/src/sections/data/containers/dataComponent.jsx @@ -65,8 +65,8 @@ const DataComponent =(props)=>{ const optionsD = { "xArray": [], "yAlias": deviceItems[deviceItem].name + '(' + deviceItems[deviceItem].unit + ')', - "sliderStart": moment(startD).format('YYYY-MM-DD HH:mm:ss'),//默认数据源第一个,时间毫秒数 - "sliderEnd": moment(endD).format('YYYY-MM-DD HH:mm:ss'),//默认数据源最后一个,时间毫秒数 + // "sliderStart": moment(startD).format('YYYY-MM-DD HH:mm:ss'),//默认数据源第一个,时间毫秒数 + // "sliderEnd": moment(endD).format('YYYY-MM-DD HH:mm:ss'),//默认数据源最后一个,时间毫秒数 "mask": "yyyy-mm-dd HH:MM:ss",//时间格式 } chartContent.push( diff --git a/web/client/src/sections/problem/components/tableData.jsx b/web/client/src/sections/problem/components/tableData.jsx index d498b77..035ee20 100644 --- a/web/client/src/sections/problem/components/tableData.jsx +++ b/web/client/src/sections/problem/components/tableData.jsx @@ -251,7 +251,7 @@ const TableData = ({ route, dispatch, actions, collectData, setSetup, exhibition onSubmit={(values) => console.log(values)} getFormApi={(formApi) => (api.current = formApi)} layout="horizontal" - style={{ position: "relative", width: "100%", flex: 1 }} + style={{ position: "relative", width: "100%", flex: 1,display:'flex' }} > {(() => { let frame = []