lucas2 1 year ago
parent
commit
9a45b5b5da
  1. 45
      api/app/lib/controllers/monitor/index.js
  2. 2
      api/app/lib/index.js
  3. 10
      web/client/src/sections/data/containers/dataDetail.jsx
  4. 23
      web/client/src/sections/data/containers/dataTableComponent.jsx

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

@ -122,20 +122,21 @@ async function getSensors (ctx) {
async function getMonitorData(ctx) { async function getMonitorData(ctx) {
try { try {
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { factorId,sensorId,startTime, endTime,limit,page } = ctx.query const { factorId, sensorId, startTime, endTime } = ctx.query
const offset=page*limit
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}
`).toPromise() || [] `).toPromise() || []
const id=sensorId&&sensorId.replace('-',':') 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 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}')
LIMIT ${limit} OFFSET ${offset}
`).toPromise() || [] `).toPromise() || []
console.log('vmonitorDatamonitorDatamonitorData',monitorData) const sensor = await clickHouse.alarmLocal.query(`SELECT distinct ID, SensorId,SensorLocationDescription FROM sensors WHERE ID in ${id}`).toPromise()
const sensor=await clickHouse.alarmLocal.query(`SELECT distinct SensorId,SensorLocationDescription FROM sensors WHERE ID='${id}'`).toPromise()
//监测项 //监测项
let items = {} let items = {}
if (factorsList && factorsList.length > 0) { if (factorsList && factorsList.length > 0) {
@ -155,24 +156,24 @@ async function getMonitorData (ctx) {
} }
//设备数据+数据 //设备数据+数据
let sensors = [] let sensors = []
if(monitorData&&monitorData.length>0){ let data=[]
monitorData.map(data => { if(sensor&&monitorData&&sensor.length && monitorData.length){
const values = {}; sensor.map(item=>{
const filterData=monitorData.filter(p=>p.SensorId==item.ID)
filterData.map(data=>{
const values = {}
Object.keys(items).forEach(key => { Object.keys(items).forEach(key => {
const index = Object.keys(items).indexOf(key); const index = Object.keys(items).indexOf(key)
values[key] = data.Values[index]; values[key] = data.Values[index]
}); })
sensors.push({ values, time: moment(data.CollectTime).format('YYYY-MM-DD HH:mm:ss') }); sensors.push({ values, time: moment(data.CollectTime).format('YYYY-MM-DD HH:mm:ss') })
}); })
data.push({id:item.ID,name:item.SensorLocationDescription,data:sensors})
})
} }
if(sensor&&sensor.length){ ctx.body = { items, sensors: data }
ctx.body={items,sensors:[{data:sensors,id:sensor[0].SensorId,name:sensor[0].SensorLocationDescription}]}
ctx.status = 200 ctx.status = 200
}else{
ctx.body={items,sensors:[]}
ctx.status=200
}
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.fs.logger.error(`path: ${ctx.path}, error: error`);
ctx.status = 400; ctx.status = 400;

2
api/app/lib/index.js

@ -35,7 +35,7 @@ module.exports.entry = function (app, router, opts) {
es(app, opts) es(app, opts)
// kafka(app, opts) kafka(app, opts)
// clickHouse 数据库 client // clickHouse 数据库 client
clickHouseClient(app, opts) clickHouseClient(app, opts)

10
web/client/src/sections/data/containers/dataDetail.jsx

@ -30,17 +30,15 @@ const DataDetail = (props) => {
const form = useRef() const form = useRef()
// //
useEffect(() => { useEffect(() => {
if(factorId&&project){ // if(factorId&&project){
let query={ let query={
factorId, factorId:factorId?factorId:-1,
sensorId:sensorId&&sensorId.length>0?sensorId.map(item=>`${project}-${item}`).join(','):[-11], sensorId:sensorId&&sensorId.length>0?sensorId.map(item=>`${project}-${item}`).join(','):[-11],
startTime:moment(dateRange[0]).format('YYYY-MM-DD HH:mm:ss'), startTime:moment(dateRange[0]).format('YYYY-MM-DD HH:mm:ss'),
endTime:moment(dateRange[1]).format('YYYY-MM-DD HH:mm:ss'), endTime:moment(dateRange[1]).format('YYYY-MM-DD HH:mm:ss'),
limit:queryPage.limit,
page:queryPage.page
} }
queryData(query) queryData(query)
} // }
// dispatch(sectionData.getContinuityType()) // dispatch(sectionData.getContinuityType())
// form.current.setValue('createTimes',[moment().subtract(24, 'hours').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')]) // form.current.setValue('createTimes',[moment().subtract(24, 'hours').format('YYYY-MM-DD HH:mm:ss'), moment().format('YYYY-MM-DD HH:mm:ss')])
@ -165,8 +163,6 @@ const DataDetail = (props) => {
sensorId:sensorId&&sensorId.length>0?sensorId.map(item=>`${project}-${item}`).join(','):[-11], sensorId:sensorId&&sensorId.length>0?sensorId.map(item=>`${project}-${item}`).join(','):[-11],
startTime:moment(rs.createTimes[0]).format('YYYY-MM-DD HH:mm:ss'), startTime:moment(rs.createTimes[0]).format('YYYY-MM-DD HH:mm:ss'),
endTime:moment(rs.createTimes[1]).format('YYYY-MM-DD HH:mm:ss'), endTime:moment(rs.createTimes[1]).format('YYYY-MM-DD HH:mm:ss'),
limit:queryPage.limit,
page:queryPage.page
} }
queryData(query) queryData(query)
}) })

23
web/client/src/sections/data/containers/dataTableComponent.jsx

@ -16,9 +16,12 @@ const DataTableComponent = (props) => {
const [isRequesting, setIsRequesting] = useState(false); const [isRequesting, setIsRequesting] = useState(false);
const [arr,setArr]=useState(dataList.items) const [arr,setArr]=useState(dataList.items)
const [data,setData]=useState([]) const [data,setData]=useState([])
// const [list,setList]=useState(dataList.sensors)
const [columns,setColumns]=useState([]) const [columns,setColumns]=useState([])
// //
useEffect(()=>{
setArr(dataList.items)
},[dataList])
useEffect(()=>{ useEffect(()=>{
// let arr=[{readingNumber:{name: '', unit: 'kWh'}}] // let arr=[{readingNumber:{name: '', unit: 'kWh'}}]
@ -45,14 +48,17 @@ const DataTableComponent = (props) => {
}); });
// //
const data1=[] const data1=[]
for (let i = 0; i < dataList.length; i++) { if (JSON.stringify(dataList) != "{}") {
for (let k = 0; k < dataList[i].data.length; k++) { let themeItems = dataList.items
let themeStations = dataList.sensors
for (let i = 0; i < themeStations.length; i++) {
for (let k = 0; k < themeStations[i].data.length; k++) {
let cdataT={} let cdataT={}
let startT = ""; let startT = "";
let endT = ""; let endT = "";
let dataTS = dataList[i].data[k]; let dataTS = themeStations[i].data[k];
cdataT.key = `station-${dataList[i].id}-${k}`; cdataT.key = `station-${themeStations[i].id}-${k}`;
cdataT.position = dataList[i].name; cdataT.position = themeStations[i].name;
cdataT.acqTime = moment(dataTS.time).format('YYYY-MM-DD HH:mm:ss'); cdataT.acqTime = moment(dataTS.time).format('YYYY-MM-DD HH:mm:ss');
cdataT.realTime = moment(dataTS.time).valueOf(); cdataT.realTime = moment(dataTS.time).valueOf();
if (startT == "") { if (startT == "") {
@ -71,9 +77,11 @@ const DataTableComponent = (props) => {
data1.push(cdataT) data1.push(cdataT)
} }
} }
}
setData(data1) setData(data1)
setColumns(columns) setColumns(columns)
},[]) },[dataList])
@ -106,7 +114,6 @@ const DataTableComponent = (props) => {
return ( return (
<div> <div>
<Spin spinning={isRequesting}> <Spin spinning={isRequesting}>

Loading…
Cancel
Save