Browse Source

feat:fix bugs

dev
zhaobing’ 1 year ago
parent
commit
7bf0f4e38a
  1. 47
      api/app/lib/controllers/monitor/index.js
  2. 13
      web/client/src/sections/data/components/lineTimeChartTemplate.jsx
  3. 4
      web/client/src/sections/data/containers/dataComponent.jsx
  4. 2
      web/client/src/sections/problem/components/tableData.jsx

47
api/app/lib/controllers/monitor/index.js

@ -123,15 +123,16 @@ async function getMonitorData(ctx) {
try { try {
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { factorId, sensorId, startTime, endTime } = ctx.query 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 const factorsList = await clickHouse.alarmLocal.query(`SELECT FactorID,Items,ItemNames,ItemUnits FROM factors
WHERE FactorID=${factorId} WHERE FactorID=${factorId} AND Project='${projectId}'
`).toPromise() || [] `).toPromise() || []
const dataArray = sensorId.split(',') const dataArray = sensorId.split(',')
const transformedArray = dataArray.map(item => { const transformedArray = dataArray.map(item => {
return item.replace('-',':')+'' return item.replace('-',':')+''
}) })
const id=`(${transformedArray.map(id => `'${id}'`).join(',')})` 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} WHERE SensorId in ${id}
AND CollectTime >= toDate('${startTime}') AND CollectTime >= toDate('${startTime}')
AND CollectTime <= toDate('${endTime}') AND CollectTime <= toDate('${endTime}')
@ -144,11 +145,14 @@ async function getMonitorData(ctx) {
let factors = [] let factors = []
//因素名词 //因素名词
let factorNames = [] let factorNames = []
//单位
let c=[]
factorsList.map(item => { factorsList.map(item => {
factors = item.ItemNames.split(',') factors = item.ItemNames.split(',')
factorNames = item.Items.split(',') factorNames = item.Items.split(',')
factors.map((child,index)=> { c = item.ItemUnits.split(',')
items[factorNames[index]] = { name: child, unit:factorNames[index] } factorNames.map((child,index)=> {
items[factorNames[index]] = { name:factors[index] , unit:c[index] }
}) })
}) })
} }
@ -156,18 +160,29 @@ async function getMonitorData(ctx) {
let sensors = [] let sensors = []
let data=[] let data=[]
if(sensor&&monitorData&&sensor.length && monitorData.length){ if(sensor&&monitorData&&sensor.length && monitorData.length){
sensor.map(item=>{ sensor.forEach((item) => {
const filterData=monitorData.filter(p=>p.SensorId==item.ID) // 过滤与当前传感器相关的数据
filterData.map(data=>{ const sensorDataArray = monitorData.filter((d) => d.SensorId == item.ID)
const values = {} // 构建最终的传感器数据结构
Object.keys(items).forEach(key => { const sensorDataItem = {
const index = Object.keys(items).indexOf(key) id: item.ID,
values[key] = data.Values[index] name: item.SensorLocationDescription,
}) data: sensorDataArray.map((d) => {
sensors.push({ values, time: moment(data.CollectTime).format('YYYY-MM-DD HH:mm:ss') }) // 根据 item 对象进行映射
}) const values = {};
data.push({id:item.ID,name:item.SensorLocationDescription,data:sensors}) 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.body = { items, sensors: data }
ctx.status = 200 ctx.status = 200

13
web/client/src/sections/data/components/lineTimeChartTemplate.jsx

@ -179,11 +179,14 @@ class LineTimeChart extends Component {
// }); // });
// dataset.unshift(x); // dataset.unshift(x);
//data //data
let data = this.props.data; let data = this.props.data
let dataArray = [], types = {}; let dataArray = [], types = {}
let xAxisValue = props.xAxis || 'time'; let xAxisValue = props.xAxis || 'time'
let yAxisValue = props.yAxis || 'value'; let yAxisValue = props.yAxis || 'value'
data.map(dd => { 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]) { if (!types[dd.name]) {
types[dd.name] = Object.assign({ types[dd.name] = Object.assign({
name: dd.name, data: [] name: dd.name, data: []

4
web/client/src/sections/data/containers/dataComponent.jsx

@ -65,8 +65,8 @@ const DataComponent =(props)=>{
const optionsD = { const optionsD = {
"xArray": [], "xArray": [],
"yAlias": deviceItems[deviceItem].name + '(' + deviceItems[deviceItem].unit + ')', "yAlias": deviceItems[deviceItem].name + '(' + deviceItems[deviceItem].unit + ')',
"sliderStart": moment(startD).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'),// // "sliderEnd": moment(endD).format('YYYY-MM-DD HH:mm:ss'),//
"mask": "yyyy-mm-dd HH:MM:ss",// "mask": "yyyy-mm-dd HH:MM:ss",//
} }
chartContent.push( chartContent.push(

2
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)} onSubmit={(values) => console.log(values)}
getFormApi={(formApi) => (api.current = formApi)} getFormApi={(formApi) => (api.current = formApi)}
layout="horizontal" layout="horizontal"
style={{ position: "relative", width: "100%", flex: 1 }} style={{ position: "relative", width: "100%", flex: 1,display:'flex' }}
> >
{(() => { {(() => {
let frame = [] let frame = []

Loading…
Cancel
Save