Browse Source

feat:fix bugs

dev
zhaobing’ 1 year ago
parent
commit
feee2904e1
  1. 147
      api/app/lib/controllers/monitor/index.js
  2. 10
      web/client/src/sections/data/containers/dataDetail.jsx
  3. 55
      web/client/src/sections/data/containers/dataTableComponent.jsx

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

@ -1,17 +1,17 @@
const moment = require('moment'); const moment = require('moment');
async function getStructures (ctx) { async function getStructures(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { pomsProjectId } = ctx.query const { pomsProjectId } = ctx.query
let bindRes=[] let bindRes = []
//选择全局就是查询所有项目下的结构物,有选择项目就只查询对应项目的结构物 //选择全局就是查询所有项目下的结构物,有选择项目就只查询对应项目的结构物
if(pomsProjectId){ if (pomsProjectId) {
bindRes = await models.ProjectCorrelation.findAll({where:{id:{ $in: pomsProjectId.split(',') }}}) bindRes = await models.ProjectCorrelation.findAll({ where: { id: { $in: pomsProjectId.split(',') } } })
}else{ } else {
bindRes = await models.ProjectCorrelation.findAll() bindRes = await models.ProjectCorrelation.findAll()
} }
let anxinProjectIds = new Set() let anxinProjectIds = new Set()
for (let b of bindRes) { for (let b of bindRes) {
@ -21,7 +21,7 @@ async function getStructures (ctx) {
} }
} }
} }
let undelStrucRes=[] let undelStrucRes = []
if (bindRes) { if (bindRes) {
undelStrucRes = anxinProjectIds.size ? undelStrucRes = anxinProjectIds.size ?
await clickHouse.anxinyun.query( await clickHouse.anxinyun.query(
@ -51,7 +51,7 @@ async function getStructures (ctx) {
ON t_structure.id = t_project_structure.structure ON t_structure.id = t_project_structure.structure
OR t_structure.id = t_structuregroup_structure.structure OR t_structure.id = t_structuregroup_structure.structure
OR t_structure.id = t_structure_site.structid OR t_structure.id = t_structure_site.structid
WHERE WHERE
project_state != -1 project_state != -1
AND AND
@ -62,8 +62,8 @@ async function getStructures (ctx) {
).toPromise() : ).toPromise() :
[] []
} }
// undelStrucRes.push({strucId:4036,strucName:'象山港大桥'}) // undelStrucRes.push({ strucId: 4036, strucName: '象山港大桥' })
// undelStrucRes.push({strucId:1,strucName:'象山港大'}) // undelStrucRes.push({ strucId: 1, strucName: '象山港大' })
ctx.status = 200; ctx.status = 200;
ctx.body = undelStrucRes ctx.body = undelStrucRes
} catch (error) { } catch (error) {
@ -75,22 +75,22 @@ async function getStructures (ctx) {
} }
} }
async function getFactors (ctx) { async function getFactors(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { structId,cacl } = ctx.query const { structId, cacl } = ctx.query
let list=[] let list = []
if(cacl){ if (cacl) {
const factorList=await clickHouse.alarmLocal.query(`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`).toPromise() const factorList = await clickHouse.alarmLocal.query(`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`).toPromise()
let fList=factorList.map(m=>m.SafetyFactorTypeId) let fList = factorList.map(m => m.SafetyFactorTypeId)
list=await clickHouse.alarmLocal.query(`select distinct FactorID, Name,Items,ItemNames from factors where FactorID in (${[...fList,-1].join(',')})`).toPromise() list = await clickHouse.alarmLocal.query(`select distinct FactorID, Name,Items,ItemNames from factors where FactorID in (${[...fList, -1].join(',')})`).toPromise()
}else{ } else {
list=await clickHouse.alarmLocal.query(`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`).toPromise() list = await clickHouse.alarmLocal.query(`select distinct SafetyFactorTypeId, SafetyFactorTypeName from sensors where PlatformStructureId =${structId}`).toPromise()
} }
ctx.body=list ctx.body = list
ctx.status=200 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;
ctx.body = { ctx.body = {
@ -99,18 +99,18 @@ async function getFactors (ctx) {
} }
} }
//查询设备 //查询设备
async function getSensors (ctx) { async function getSensors(ctx) {
try { try {
const { models } = ctx.fs.dc; const { models } = ctx.fs.dc;
const { clickHouse } = ctx.app.fs const { clickHouse } = ctx.app.fs
const { structId,SafetyFactorTypeId } = ctx.query const { structId, SafetyFactorTypeId } = ctx.query
const list=await clickHouse.alarmLocal.query(` const list = await clickHouse.alarmLocal.query(`
select distinct SensorId,SensorLocationDescription,Project select distinct SensorId,SensorLocationDescription,Project
from sensors where PlatformStructureId =${structId} from sensors where PlatformStructureId =${structId}
and SafetyFactorTypeId=${SafetyFactorTypeId}`).toPromise() and SafetyFactorTypeId=${SafetyFactorTypeId}`).toPromise()
ctx.body=list ctx.body = list
ctx.status=200 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;
ctx.body = { ctx.body = {
@ -119,61 +119,62 @@ async function getSensors (ctx) {
} }
} }
//根据设备id和监测因素id查询监测数据 //根据设备id和监测因素id查询监测数据
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 monitorData=await clickHouse.alarmLocal.query(`SELECT SensorId,CollectTime,Values FROM themes const transformedArray = dataArray.map(item => {
WHERE SensorId in ('${id}') return item.replace('-',':')+''
})
const id=`(${transformedArray.map(id => `'${id}'`).join(',')})`
const monitorData = await clickHouse.alarmLocal.query(`SELECT SensorId,CollectTime,Values FROM themes
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()||[] const sensor = await clickHouse.alarmLocal.query(`SELECT distinct ID, SensorId,SensorLocationDescription FROM sensors WHERE ID in ${id}`).toPromise()
console.log('vmonitorDatamonitorDatamonitorData',monitorData) //监测项
const sensor=await clickHouse.alarmLocal.query(`SELECT distinct SensorId,SensorLocationDescription FROM sensors WHERE ID='${id}'`).toPromise() let items = {}
//监测项 if (factorsList && factorsList.length > 0) {
let items={}
if(factorsList&&factorsList.length>0){
//因素解释 //因素解释
let factors=[] let factors = []
//因素名词 //因素名词
let factorNames=[] let factorNames = []
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=>{ factors.map(child => {
factorNames.map(p=>{ factorNames.map(p => {
items[p]={name:child,unit:item.ItemUnits} items[p] = { name: child, unit: item.ItemUnits }
}) })
}) })
}) })
} }
//设备数据+数据 //设备数据+数据
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=>{
Object.keys(items).forEach(key => { const filterData=monitorData.filter(p=>p.SensorId==item.ID)
const index = Object.keys(items).indexOf(key); filterData.map(data=>{
values[key] = data.Values[index]; const values = {}
}); Object.keys(items).forEach(key => {
sensors.push({ values, time: moment(data.CollectTime).format('YYYY-MM-DD HH:mm:ss') }); 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') })
if(sensor&&sensor.length){ })
ctx.body={items,sensors:[{data:sensors,id:sensor[0].SensorId,name:sensor[0].SensorLocationDescription}]} data.push({id:item.ID,name:item.SensorLocationDescription,data:sensors})
ctx.status=200 })
}else{ }
ctx.body={items,sensors:[]} ctx.body = { items, sensors: data }
ctx.status=200 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;
ctx.body = { ctx.body = {
@ -188,5 +189,5 @@ async function getMonitorData (ctx) {
module.exports = { module.exports = {
getStructures,getFactors,getSensors,getMonitorData getStructures, getFactors, getSensors, getMonitorData
} }

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)
}) })

55
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,35 +48,40 @@ 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 cdataT={} let themeStations = dataList.sensors
let startT = ""; for (let i = 0; i < themeStations.length; i++) {
let endT = ""; for (let k = 0; k < themeStations[i].data.length; k++) {
let dataTS = dataList[i].data[k]; let cdataT={}
cdataT.key = `station-${dataList[i].id}-${k}`; let startT = "";
cdataT.position = dataList[i].name; let endT = "";
cdataT.acqTime = moment(dataTS.time).format('YYYY-MM-DD HH:mm:ss'); let dataTS = themeStations[i].data[k];
cdataT.realTime = moment(dataTS.time).valueOf(); cdataT.key = `station-${themeStations[i].id}-${k}`;
if (startT == "") { cdataT.position = themeStations[i].name;
startT = dataTS.time; cdataT.acqTime = moment(dataTS.time).format('YYYY-MM-DD HH:mm:ss');
endT = dataTS.time; cdataT.realTime = moment(dataTS.time).valueOf();
} else { if (startT == "") {
if (moment(startT) >= moment(dataTS.time))
startT = dataTS.time; startT = dataTS.time;
if (moment(endT) <= moment(dataTS.time))
endT = dataTS.time; endT = dataTS.time;
} else {
if (moment(startT) >= moment(dataTS.time))
startT = dataTS.time;
if (moment(endT) <= moment(dataTS.time))
endT = dataTS.time;
}
//
for (let themeItem in arr) {
cdataT[themeItem] = dataTS.values[themeItem];
}
data1.push(cdataT)
} }
//
for (let themeItem in arr) {
cdataT[themeItem] = dataTS.values[themeItem];
}
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