Browse Source

测试44444

master
wenlele 1 year ago
parent
commit
147bfe7597
  1. 5
      api/app/lib/routes/organization/index.js
  2. 784
      api/app/lib/schedule/workorder_statistics.js
  3. 2
      web/client/src/sections/bigScreen/actions/index.js

5
api/app/lib/routes/organization/index.js

@ -7,7 +7,7 @@ module.exports = function (app, router, opts) {
try { try {
app.fs.api.logAttr['get/pump/station'] = { content: '获取所有站点信息', visible: true }; app.fs.api.logAttr['get/pump/station'] = { content: '获取所有站点信息', visible: true };
router.get('/pump/station', data.getPumpStation); router.get('/pump1/station1', data.getPumpStation);
app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true }; app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true };
@ -51,7 +51,4 @@ module.exports = function (app, router, opts) {
console.log(error.response); console.log(error.response);
} }
}; };

784
api/app/lib/schedule/workorder_statistics.js

@ -1,7 +1,7 @@
const moment = require('moment') const moment = require('moment')
let isDev = false // let isDev = false
// let isDev = true let isDev = true
@ -23,401 +23,403 @@ module.exports = function (app, opts) {
let data = await getAnxinyunToken(app) let data = await getAnxinyunToken(app)
console.log(1111,data); console.log(1111, data);
//获取所有泵站 //获取所有泵站
let structureList = await app.fs.anxinyun.get(`organizations/${data.orgId}/structures?token=${data.token}`) || [] let structureList = await app.fs.anxinyun.get(`organizations/${data.orgId}/structures?token=${data.token}`) || []
console.log('获取所有泵站',structureList);
await app.redis.set("pumpStation_structure", JSON.stringify(structureList))
if (structureList.length) {
let waterLevelData = [] //七天内每个泵站的集水池液位 console.log('获取所有泵站', structureList);
let waterLevelSix = {} //泵站最新6h的集水池液位
let waterPumpStateAll = [] //所有水泵的状态 await app.redis.set("pumpStation_structure", JSON.stringify(structureList))
let capacity = {} //能耗监测 let daty = await app.redis.get("pumpStation_structure")
let currentSix = {} //水泵六小时数据 console.log(222, JSON.parse(daty));
let cabinet = {} //进线柜 // if (structureList.length) {
let threePhase = {} //三相电流
// let waterLevelData = [] //七天内每个泵站的集水池液位
// let waterLevelSix = {} //泵站最新6h的集水池液位
for (let index = 0; index < structureList.length; index++) { // let waterPumpStateAll = [] //所有水泵的状态
const strucOne = structureList[index]; // let capacity = {} //能耗监测
//单个泵站 // let currentSix = {} //水泵六小时数据
let pumpOne = await app.fs.anxinyun.get(`structures/${strucOne.id}/factors?token=${data.token}`) || [] // let cabinet = {} //进线柜
if (pumpOne.length) { // let threePhase = {} //三相电流
let pump = [] //能耗监测--水泵
let cabinetSun = [] //能耗监测--进线柜
let sun = {}
let day1 = 0 // for (let index = 0; index < structureList.length; index++) {
let day30 = 0 // const strucOne = structureList[index];
let day365 = 0 // //单个泵站
let daySun = 0 // let pumpOne = await app.fs.anxinyun.get(`structures/${strucOne.id}/factors?token=${data.token}`) || []
// if (pumpOne.length) {
//泵站信息
let informationId = pumpOne.find(v => v.name == '泵站信息').id // let pump = [] //能耗监测--水泵
if (informationId) { // let cabinetSun = [] //能耗监测--进线柜
let pumpInformation = await app.fs.anxinyun.get(`structures/${strucOne.id}/stations?token=${data.token}`, { query: { factorId: informationId } }) || [] // let sun = {}
// let day1 = 0
if (pumpInformation.length > 0 && pumpInformation[0].groups.length && pumpInformation[0].groups[0].stations[0].id) { // let day30 = 0
//七天内该泵站最新的集水池液位 // let day365 = 0
let waterLevel = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, { // let daySun = 0
query: {
stations: pumpInformation[0].groups[0].stations[0].id, // //泵站信息
startTime: moment().startOf('week').format('YYYY-MM-DD HH:mm:ss'), // let informationId = pumpOne.find(v => v.name == '泵站信息').id
endTime: moment().endOf('week').format('YYYY-MM-DD HH:mm:ss'), // if (informationId) {
limit: 1 // let pumpInformation = await app.fs.anxinyun.get(`structures/${strucOne.id}/stations?token=${data.token}`, { query: { factorId: informationId } }) || []
}
}) || {} // if (pumpInformation.length > 0 && pumpInformation[0].groups.length && pumpInformation[0].groups[0].stations[0].id) {
// //七天内该泵站最新的集水池液位
let findOne = waterLevel.stations[0].data[0] || {} // let waterLevel = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, {
sun.sHumidity = findOne.sHumidity // query: {
sun.sTEMP = findOne.sTEMP // stations: pumpInformation[0].groups[0].stations[0].id,
sun.sGrille_level = findOne.sGrille_level // startTime: moment().startOf('week').format('YYYY-MM-DD HH:mm:ss'),
// endTime: moment().endOf('week').format('YYYY-MM-DD HH:mm:ss'),
// limit: 1
// }
waterLevelData.push({ // }) || {}
strucId: strucOne.id, name: strucOne.name, level: findOne.sLiquid_level || 0
}) // let findOne = waterLevel.stations[0].data[0] || {}
// sun.sHumidity = findOne.sHumidity
//该泵站最新6h的集水池液位 // sun.sTEMP = findOne.sTEMP
let waterLevel6 = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, { // sun.sGrille_level = findOne.sGrille_level
query: {
stations: pumpInformation[0].groups[0].stations[0].id,
startTime: moment().add(-6, 'hours').format('YYYY-MM-DD HH:mm:ss'),
endTime: moment().format('YYYY-MM-DD HH:mm:ss'), // waterLevelData.push({
limit: 1440 // strucId: strucOne.id, name: strucOne.name, level: findOne.sLiquid_level || 0
} // })
}) || {}
// //该泵站最新6h的集水池液位
waterLevelSix['struc' + strucOne.id] = waterLevel6.stations[0] && JSON.stringify(waterLevel6.stations[0].data) // let waterLevel6 = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, {
// query: {
// stations: pumpInformation[0].groups[0].stations[0].id,
} // startTime: moment().add(-6, 'hours').format('YYYY-MM-DD HH:mm:ss'),
// endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
} // limit: 1440
// }
//水泵信息 // }) || {}
let waterId = pumpOne.find(v => v.name == '泵站水泵').id
if (waterId) { // waterLevelSix['struc' + strucOne.id] = waterLevel6.stations[0] && JSON.stringify(waterLevel6.stations[0].data)
let waterpPmpInformation = await app.fs.anxinyun.get(`structures/${strucOne.id}/stations?token=${data.token}`, { query: { factorId: waterId } }) || []
let dataId = [] // }
waterpPmpInformation.forEach(v => {
v.groups.forEach(s => { // }
s.stations.forEach(f => {
dataId.push(f.id) // //水泵信息
}) // let waterId = pumpOne.find(v => v.name == '泵站水泵').id
}) // if (waterId) {
}) // let waterpPmpInformation = await app.fs.anxinyun.get(`structures/${strucOne.id}/stations?token=${data.token}`, { query: { factorId: waterId } }) || []
if (dataId.length) { // let dataId = []
// waterpPmpInformation.forEach(v => {
// v.groups.forEach(s => {
// s.stations.forEach(f => {
// 当前时间 // dataId.push(f.id)
let todayOne = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, { // })
query: { // })
stations: dataId.join(), // })
startTime: moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
endTime: moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'), // if (dataId.length) {
limit: 1
}
}) || []
// // 当前时间
waterPumpStateAll.push({ strucId: strucOne.id, name: strucOne.name, data: todayOne.stations }) // let todayOne = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, {
pump = todayOne.stations || [] // query: {
// stations: dataId.join(),
todayOne.stations && todayOne.stations.forEach(d => { // startTime: moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
daySun += d.data[0] && d.data[0].eMotor_EQ || 0 // endTime: moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
}) // limit: 1
// }
// 今天 // }) || []
let dayCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
query: { // waterPumpStateAll.push({ strucId: strucOne.id, name: strucOne.name, data: todayOne.stations })
stations: dataId.join(), // pump = todayOne.stations || []
begin: moment().startOf('day').format('x'),
end: moment().endOf('day').format('x'), // todayOne.stations && todayOne.stations.forEach(d => {
aggtype: "h", // daySun += d.data[0] && d.data[0].eMotor_EQ || 0
method: 'diff' // })
}
}) || [] // // 今天
// let dayCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
if (dayCollect.length) { // query: {
dayCollect[0].stations.forEach(f => { // stations: dataId.join(),
f.data.forEach(h => { // begin: moment().startOf('day').format('x'),
if (!h.changData) { // end: moment().endOf('day').format('x'),
day1 += h.values.eMotor_EQ // aggtype: "h",
} // method: 'diff'
}) // }
}) // }) || []
}
// if (dayCollect.length) {
// 本月 // dayCollect[0].stations.forEach(f => {
let monthCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, { // f.data.forEach(h => {
query: { // if (!h.changData) {
stations: dataId.join(), // day1 += h.values.eMotor_EQ
begin: moment().startOf('month').format('x'), // }
end: moment().endOf('month').format('x'), // })
aggtype: "d", // })
method: 'diff' // }
}
}) || [] // // 本月
if (monthCollect.length) { // let monthCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
monthCollect[0].stations.forEach(f => { // query: {
f.data.forEach(h => { // stations: dataId.join(),
if (!h.changData) { // begin: moment().startOf('month').format('x'),
day30 += h.values.eMotor_EQ // end: moment().endOf('month').format('x'),
} // aggtype: "d",
}) // method: 'diff'
}) // }
} // }) || []
// if (monthCollect.length) {
// monthCollect[0].stations.forEach(f => {
// 今年 // f.data.forEach(h => {
let yearCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, { // if (!h.changData) {
query: { // day30 += h.values.eMotor_EQ
stations: dataId.join(), // }
begin: moment().startOf('year').format('x'), // })
end: moment().endOf('year').format('x'), // })
aggtype: "d", // }
method: 'diff'
}
}) || [] // // 今年
// let yearCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
if (yearCollect.length) { // query: {
yearCollect[0].stations.map(f => { // stations: dataId.join(),
f.data.forEach(h => { // begin: moment().startOf('year').format('x'),
if (!h.changData) { // end: moment().endOf('year').format('x'),
day365 += h.values.eMotor_EQ // aggtype: "d",
} // method: 'diff'
}) // }
}) // }) || []
}
// if (yearCollect.length) {
// yearCollect[0].stations.map(f => {
// f.data.forEach(h => {
let current = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, { // if (!h.changData) {
query: { // day365 += h.values.eMotor_EQ
stations: dataId.join(), // }
startTime: moment().add(-6, 'hours').format('YYYY-MM-DD HH:mm:ss'), // })
endTime: moment().format('YYYY-MM-DD HH:mm:ss'), // })
limit: 1440 // }
}
}) || {}
currentSix['struc' + strucOne.id] = JSON.stringify(current.stations) // let current = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, {
// query: {
// stations: dataId.join(),
// let threedata = [] // startTime: moment().add(-6, 'hours').format('YYYY-MM-DD HH:mm:ss'),
// let timeSet = new Set() // endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
// if (current.stations && current.stations.length) { // limit: 1440
// current.stations.map(p => { // }
// p.data.map(s => { // }) || {}
// timeSet.add(moment(s.time).format('YYYY-MM-DD HH:mm:ss'))
// }) // currentSix['struc' + strucOne.id] = JSON.stringify(current.stations)
// })
// let time = [...timeSet].sort((a, b) => moment(a).isBefore(b) ? -1 : 1)
// // let threedata = []
// time.map(x => { // // let timeSet = new Set()
// let A = [] // // if (current.stations && current.stations.length) {
// let B = [] // // current.stations.map(p => {
// let C = [] // // p.data.map(s => {
// current.stations.map((s, index) => { // // timeSet.add(moment(s.time).format('YYYY-MM-DD HH:mm:ss'))
// let abcData = s.data.find(f => moment(f.time).format('YYYY-MM-DD HH:mm:ss') == x) || {} // // })
// let a = abcData.eMotor_A_A // // })
// let b = abcData.eMotor_B_A // // let time = [...timeSet].sort((a, b) => moment(a).isBefore(b) ? -1 : 1)
// let c = abcData.eMotor_C_A
// if (a) A.push(a) // // time.map(x => {
// if (b) B.push(b) // // let A = []
// if (c) C.push(c) // // let B = []
// }) // // let C = []
// const sum = (arr) => { // // current.stations.map((s, index) => {
// let sum = 0 // // let abcData = s.data.find(f => moment(f.time).format('YYYY-MM-DD HH:mm:ss') == x) || {}
// arr.map(h => { // // let a = abcData.eMotor_A_A
// sum += h // // let b = abcData.eMotor_B_A
// }) // // let c = abcData.eMotor_C_A
// return sum // // if (a) A.push(a)
// } // // if (b) B.push(b)
// threedata.push({ // // if (c) C.push(c)
// A: A.length && (sum(A) / A.length) || null, // // })
// B: B.length && (sum(B) / B.length) || null, // // const sum = (arr) => {
// C: C.length && (sum(C) / C.length) || null, // // let sum = 0
// time: x // // arr.map(h => {
// }) // // sum += h
// }) // // })
// } // // return sum
// // }
// // threedata.push({
// threePhase['struc' + strucOne.id] = JSON.stringify(threedata) // // A: A.length && (sum(A) / A.length) || null,
// // B: B.length && (sum(B) / B.length) || null,
} // // C: C.length && (sum(C) / C.length) || null,
// // time: x
// // })
} // // })
// // }
//进线柜
let wireCabinetId = pumpOne.find(v => v.name == '泵站进线柜').id // // threePhase['struc' + strucOne.id] = JSON.stringify(threedata)
if (wireCabinetId) {
let dataList = await app.fs.anxinyun.get(`structures/${strucOne.id}/stations?token=${data.token}`, { query: { factorId: wireCabinetId } }) || [] // }
let dataId = []
dataList.map(v => {
v.groups.map(s => { // }
s.stations.map(f => {
dataId.push(f.id)
}) // //进线柜
}) // let wireCabinetId = pumpOne.find(v => v.name == '泵站进线柜').id
}) // if (wireCabinetId) {
// let dataList = await app.fs.anxinyun.get(`structures/${strucOne.id}/stations?token=${data.token}`, { query: { factorId: wireCabinetId } }) || []
if (dataId.length) { // let dataId = []
// 当前时间 // dataList.map(v => {
let todayOne = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, { // v.groups.map(s => {
query: { // s.stations.map(f => {
stations: dataId.join(), // dataId.push(f.id)
startTime: moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'), // })
endTime: moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'), // })
limit: 1 // })
}
}) || {} // if (dataId.length) {
// // 当前时间
let cabinetOne = todayOne.stations && todayOne.stations || [] // let todayOne = await app.fs.anxinyun.get(`stations/theme/data?token=${data.token}`, {
// query: {
cabinet['struc' + strucOne.id] = JSON.stringify(cabinetOne) // stations: dataId.join(),
// startTime: moment().startOf('day').format('YYYY-MM-DD HH:mm:ss'),
cabinetOne.forEach(d => { // endTime: moment().endOf('day').format('YYYY-MM-DD HH:mm:ss'),
let todayFindOne = d.data[0] || {} // limit: 1
daySun += todayFindOne.eQF_EQ || 0 // }
cabinetSun.push({ // }) || {}
today: 0,
sameMonth: 0, // let cabinetOne = todayOne.stations && todayOne.stations || []
thisYear: 0,
eQF_EQ: todayFindOne.eQF_EQ || 0, // cabinet['struc' + strucOne.id] = JSON.stringify(cabinetOne)
id: d.id,
name: d.name, // cabinetOne.forEach(d => {
sQF_CLOSING: todayFindOne.sQF_CLOSING // let todayFindOne = d.data[0] || {}
}) // daySun += todayFindOne.eQF_EQ || 0
}) // cabinetSun.push({
// 今天 // today: 0,
let dayCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, { // sameMonth: 0,
query: { // thisYear: 0,
stations: dataId.join(), // eQF_EQ: todayFindOne.eQF_EQ || 0,
begin: moment().startOf('day').format('x'), // id: d.id,
end: moment().endOf('day').format('x'), // name: d.name,
aggtype: "h", // sQF_CLOSING: todayFindOne.sQF_CLOSING
method: 'diff' // })
} // })
}) || [] // // 今天
// let dayCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
cabinetSun.forEach(p => { // query: {
if (dayCollect.length) { // stations: dataId.join(),
dayCollect[0].stations.forEach(f => { // begin: moment().startOf('day').format('x'),
if (p.id == f.id) { // end: moment().endOf('day').format('x'),
f.data.forEach(h => { // aggtype: "h",
if (!h.changData) { // method: 'diff'
p.today = p.today + h.values.eQF_EQ // }
p.sameMonth = p.sameMonth + h.values.eQF_EQ // }) || []
p.thisYear = p.thisYear + h.values.eQF_EQ
day1 += h.values.eQF_EQ // cabinetSun.forEach(p => {
} // if (dayCollect.length) {
}) // dayCollect[0].stations.forEach(f => {
} // if (p.id == f.id) {
}) // f.data.forEach(h => {
} // if (!h.changData) {
}) // p.today = p.today + h.values.eQF_EQ
// p.sameMonth = p.sameMonth + h.values.eQF_EQ
// 本月 // p.thisYear = p.thisYear + h.values.eQF_EQ
let monthCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, { // day1 += h.values.eQF_EQ
query: { // }
stations: dataId.join(), // })
begin: moment().startOf('month').format('x'), // }
end: moment().endOf('month').format('x'), // })
aggtype: "d", // }
method: 'diff' // })
}
}) || [] // // 本月
// let monthCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
cabinetSun.forEach(p => { // query: {
if (monthCollect.length) { // stations: dataId.join(),
monthCollect[0].stations.forEach(f => { // begin: moment().startOf('month').format('x'),
if (p.id == f.id) { // end: moment().endOf('month').format('x'),
f.data.forEach(h => { // aggtype: "d",
if (!h.changData) { // method: 'diff'
p.sameMonth = p.sameMonth + h.values.eQF_EQ // }
day30 += h.values.eQF_EQ // }) || []
}
}) // cabinetSun.forEach(p => {
} // if (monthCollect.length) {
}) // monthCollect[0].stations.forEach(f => {
} // if (p.id == f.id) {
}) // f.data.forEach(h => {
// if (!h.changData) {
// 今年 // p.sameMonth = p.sameMonth + h.values.eQF_EQ
let yearCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, { // day30 += h.values.eQF_EQ
query: { // }
stations: dataId.join(), // })
begin: moment().startOf('year').format('x'), // }
end: moment().endOf('year').format('x'), // })
aggtype: "d", // }
method: 'diff' // })
}
}) || [] // // 今年
// let yearCollect = await app.fs.anxinyun.get(`stations/data/theme?token=${data.token}`, {
cabinetSun.forEach(p => { // query: {
if (yearCollect.length) { // stations: dataId.join(),
yearCollect[0].stations.forEach(f => { // begin: moment().startOf('year').format('x'),
if (p.id == f.id) { // end: moment().endOf('year').format('x'),
f.data.forEach(h => { // aggtype: "d",
if (!h.changData) { // method: 'diff'
p.thisYear = p.thisYear + h.values.eQF_EQ // }
day365 += h.values.eQF_EQ // }) || []
}
}) // cabinetSun.forEach(p => {
} // if (yearCollect.length) {
}) // yearCollect[0].stations.forEach(f => {
} // if (p.id == f.id) {
}) // f.data.forEach(h => {
// if (!h.changData) {
} // p.thisYear = p.thisYear + h.values.eQF_EQ
// day365 += h.values.eQF_EQ
// }
} // })
// }
// })
// }
// })
// }
sun.day1 = day1
sun.day30 = day30 + day1 // }
sun.day365 = day365 + day1
sun.daySun = daySun
let capacityOne = { pump, cabinetSun, sun }
capacity['struc' + strucOne.id] = JSON.stringify(capacityOne)
// sun.day1 = day1
} // sun.day30 = day30 + day1
} // sun.day365 = day365 + day1
// sun.daySun = daySun
await app.redis.set("pumpStation_waterLevelAll", JSON.stringify(waterLevelData)) // let capacityOne = { pump, cabinetSun, sun }
await app.redis.hmset("pumpStation_waterLevelSix", waterLevelSix)
await app.redis.set("pumpStation_waterPumpStateAll", JSON.stringify(waterPumpStateAll)) // capacity['struc' + strucOne.id] = JSON.stringify(capacityOne)
await app.redis.hmset("pumpStation_capacity", capacity)
await app.redis.hmset("pumpStation_currentSix", currentSix)
await app.redis.hmset("pumpStation_cabinet", cabinet) // }
// await app.redis.hmset("pumpStation_threePhase", threePhase) // }
}
// await app.redis.set("pumpStation_waterLevelAll", JSON.stringify(waterLevelData))
// await app.redis.hmset("pumpStation_waterLevelSix", waterLevelSix)
// await app.redis.set("pumpStation_waterPumpStateAll", JSON.stringify(waterPumpStateAll))
// await app.redis.hmset("pumpStation_capacity", capacity)
// await app.redis.hmset("pumpStation_currentSix", currentSix)
// await app.redis.hmset("pumpStation_cabinet", cabinet)
// // await app.redis.hmset("pumpStation_threePhase", threePhase)
// }
} catch (error) { } catch (error) {

2
web/client/src/sections/bigScreen/actions/index.js

@ -13,7 +13,7 @@ export function getPumpStation (query = {}) {
type: 'get', type: 'get',
dispatch: dispatch, dispatch: dispatch,
actionType: 'GET_PUMP_STATION', actionType: 'GET_PUMP_STATION',
url: 'pump/station', url: 'pump1/station1',
query, query,
msg: { error: '获取所有站点信息失败' } msg: { error: '获取所有站点信息失败' }
}); });

Loading…
Cancel
Save