Browse Source

feat:fix bugs

dev
zhaobing’ 1 year ago
parent
commit
7bf0f4e38a
  1. 43
      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

43
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,17 +160,28 @@ 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') })
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({id:item.ID,name:item.SensorLocationDescription,data:sensors})
};
data.push(sensorDataItem)
})
}
ctx.body = { items, sensors: data }

13
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: []

4
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(

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)}
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 = []

Loading…
Cancel
Save