Browse Source

泵站控制修改

master
wenlele 12 months ago
parent
commit
4032edcc29
  1. 5
      api/app/lib/controllers/bigScreen/index .js
  2. 63
      web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js

5
api/app/lib/controllers/bigScreen/index .js

@ -43,7 +43,8 @@ async function axyData (ctx, next) {
url = url.replace(`{orgId}`, data.orgId) url = url.replace(`{orgId}`, data.orgId)
} }
const res = await ctx.app.fs.anxinyun[type](`${url}?token=${data.token}`, { data: params.data || {}, query: params.query || {} }) const res = await ctx.app.fs.anxinyun[type](`${url}?token=${data.token}?test=123`, { data: params.data || {}, query: params.query || {} })
ctx.status = 200; ctx.status = 200;
ctx.body = res; ctx.body = res;
} catch (err) { } catch (err) {
@ -78,7 +79,7 @@ const getPumpStation = async function (ctx) {
try { try {
console.log(ctx); console.log(ctx);
const { key, methodType, field } = ctx.query; const { key, methodType, field } = ctx.query;
let res let res
if (field) { if (field) {
res = await ctx.redis[methodType]("pumpStation_" + key, field) || [] res = await ctx.redis[methodType]("pumpStation_" + key, field) || []

63
web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js

@ -4,7 +4,7 @@ import moment from 'moment'
import { Select, Modal, Switch, Input, Button, Form, message } from 'antd'; import { Select, Modal, Switch, Input, Button, Form, message } from 'antd';
const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId, strucId, siteList,pumpOne, setPumpOne, currentSix }) => { const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId, strucId, siteList, pumpOne, setPumpOne, currentSix }) => {
const { bigScreen } = actions; const { bigScreen } = actions;
@ -13,7 +13,7 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
const [isModalOpen, setIsModalOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false);
const [pumpName, setPumpName] = useState(''); const [pumpName, setPumpName] = useState('');
// const [pumpOne, setPumpOne] = useState({ data: [] }); const [pumpData, setPumpData] = useState([]);
const [checked, setChecked] = useState({ const [checked, setChecked] = useState({
'模式切换': false, // 平台手动/平台液控 '模式切换': false, // 平台手动/平台液控
'启动控制': false, '启动控制': false,
@ -24,22 +24,47 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
setPumpName(pumpList?.length ? pumpList[0].name : '') setPumpName(pumpList?.length ? pumpList[0].name : '')
}, [pumpList]) }, [pumpList])
useEffect(async () => {
if (strucId) {
await dispatch(bigScreen.axyData({ type: 'get', url: `structures/${strucId}/factors` })).then(async r => {
if (r.success) {
//水泵信息
let waterId = r.payload.data?.find(v => v.name == '泵站水泵')?.id
if (waterId) {
await dispatch(bigScreen.axyData({
type: 'get', url: `structures/${strucId}/stations`,
params: { query: { factorId: waterId } }
})).then(async p => {
if (p.success) {
setPumpData(p.payload.data[0]?.groups[0]?.stations || [])
}
})
}
}
})
}
}, [strucId])
useEffect(() => { useEffect(() => {
dispatch(bigScreen.axyData({ if (pumpId) {
type: 'get', url: `stations/theme/data`, params: { dispatch(bigScreen.axyData({
query: { type: 'get', url: `stations/theme/data`, params: {
stations: pumpId, query: {
startTime: moment().startOf('week').format('YYYY-MM-DD HH:mm:ss'), stations: pumpId,
endTime: moment().format('YYYY-MM-DD HH:mm:ss'), startTime: moment().startOf('week').format('YYYY-MM-DD HH:mm:ss'),
limit: 1 endTime: moment().format('YYYY-MM-DD HH:mm:ss'),
limit: 1
}
} }
} })).then(d => {
})).then(d => { if (d.success) {
if (d.success) { setPumpOne(d.payload.data?.stations[0] || { data: [] })
setPumpOne(d.payload.data?.stations[0] || { data: [] }) }
} })
}) }
}, [pumpId]) }, [pumpId])
useEffect(() => { useEffect(() => {
@ -75,8 +100,10 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
const onChange = (label, isChecked) => { const onChange = (label, isChecked) => {
const nextChecked = { ...checked, [label]: isChecked }; const nextChecked = { ...checked, [label]: isChecked };
// console.log(nextChecked,label, isChecked);
setChecked(nextChecked); setChecked(nextChecked);
console.log(siteList);
const thingId = siteList?.find(s => s.value === strucId)?.iotaThingId; const thingId = siteList?.find(s => s.value === strucId)?.iotaThingId;
let deviceId = null; let deviceId = null;
let sensorId = null; let sensorId = null;
@ -93,7 +120,7 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
Promise.all(promiseArr).then(resArr => { Promise.all(promiseArr).then(resArr => {
if (resArr[0].success && resArr[1].success) { if (resArr[0].success && resArr[1].success) {
deviceId = resArr[0].payload.data?.devices[0].deviceId; deviceId = resArr[0].payload.data?.devices[0].deviceId;
sensorId = resArr[1].payload.data.instances[Object.keys(pumpList?.find(p => p.id === pumpId)?.iotaDevices)[0]].instance.properties.sensorId; sensorId = resArr[1].payload.data.instances[Object.keys(pumpData?.find(p => p.id === pumpId)?.iotaDevices)[0]].instance.properties.sensorId;
for (const instance of Object.values(resArr[1].payload.data.instances)) { for (const instance of Object.values(resArr[1].payload.data.instances)) {
if (instance.name === "泵站数据采集仪") { if (instance.name === "泵站数据采集仪") {
for (const interfaces of Object.values(instance.instance.interfaces)) { for (const interfaces of Object.values(instance.instance.interfaces)) {
@ -126,8 +153,8 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
})).then(res => { })).then(res => {
console.log('控制res', res) console.log('控制res', res)
}) })
pumpOne.data[0] = { ...pumpOne.data[0], sMotor_State: label === '启动控制' ? 2 : label === '停止控制' ? 1 : pumpOne.sMotor_State }
setPumpOne({ ...pumpOne, sMotor_State: label === '启动控制' ? 2 : label === '停止控制' ? 1 : pumpOne.sMotor_State }) setPumpOne({ ...pumpOne })
setTimeout(() => { setTimeout(() => {
dispatch(bigScreen.axyData({ dispatch(bigScreen.axyData({
type: 'get', url: `stations/theme/data`, params: { type: 'get', url: `stations/theme/data`, params: {

Loading…
Cancel
Save