Browse Source

泵站控制

master
wenlele 1 year ago
parent
commit
0e91a0a4f1
  1. 3
      api/.vscode/launch.json
  2. 8
      api/app/lib/controllers/bigScreen/index .js
  3. 16
      api/config.js
  4. 38
      api/utils/iota-api.js
  5. 10
      web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js

3
api/.vscode/launch.json

@ -17,7 +17,8 @@
// //
"-g postgres://postgres:123456@10.8.30.166:5432/PumpStation", "-g postgres://postgres:123456@10.8.30.166:5432/PumpStation",
// "-g postgres://FashionAdmin:123456@10.8.30.166:5432/PumpStation", // "-g postgres://FashionAdmin:123456@10.8.30.166:5432/PumpStation",
"-x http://221.230.55.28:7007", // // "-x http://221.230.55.28:7007", //
"-x https://iotaproxy.anxinyun.cn", //
"--redisHost localhost", "--redisHost localhost",
"--redisPort 6379", "--redisPort 6379",
// //

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

@ -121,7 +121,7 @@ async function getDevices (ctx, next) {
try { try {
let { thingId } = ctx.query; let { thingId } = ctx.query;
const res = await ctx.app.fs.iota.get(`/metrics/things/${thingId}/devices/link_status`) || {} const res = await ctx.app.iota.request.get(`/metrics/things/${thingId}/devices/link_status`) || {}
ctx.status = 200; ctx.status = 200;
ctx.body = res.body; ctx.body = res.body;
@ -138,7 +138,7 @@ async function getInstances (ctx, next) {
try { try {
let { thingId } = ctx.query; let { thingId } = ctx.query;
const res = await ctx.app.fs.iota.get(`/things/${thingId}/deploys`) || {} const res = await ctx.app.iota.request.get(`/things/${thingId}/deploys`) || {}
ctx.status = 200; ctx.status = 200;
ctx.body = res.body; ctx.body = res.body;
@ -155,13 +155,13 @@ async function getCapabilitiesInvoke (ctx, next) {
try { try {
let data = ctx.query; let data = ctx.query;
const res = await ctx.app.fs.iota.post(`/capabilities/invoke`, data) || {} const res = await ctx.app.iota.request.post(`/capabilities/invoke`, data) || {}
ctx.status = 200; ctx.status = 200;
ctx.body = res.body; ctx.body = res.body;
} catch (err) { } catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
ctx.status = 400; ctx.status = 400;++
ctx.body = { name: 'FindError', message: '下发指令失败' }; ctx.body = { name: 'FindError', message: '下发指令失败' };
} }
} }

16
api/config.js

@ -49,6 +49,12 @@ const product = {
opts: { opts: {
maxSize: 104857600, // 100M maxSize: 104857600, // 100M
} }
},{
entry: require('./utils/iota-api').entry,
opts: {
host: ANXINCLOUD_PROXY_IOTA,
match: '/_iota_api'
}
}, { }, {
entry: require('./app').entry, entry: require('./app').entry,
opts: { opts: {
@ -66,10 +72,12 @@ const product = {
pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs
name: 'anxinyun', name: 'anxinyun',
root: API_ANXINYUN_URL root: API_ANXINYUN_URL
}, {// name 会作为一个 request 出现在 ctx.app.fs },
name: 'iota', // {// name 会作为一个 request 出现在 ctx.app.fs
root: ANXINCLOUD_PROXY_IOTA // name: 'iota',
}], // root: ANXINCLOUD_PROXY_IOTA
// }
],
} }
} }
], ],

38
api/utils/iota-api.js

@ -0,0 +1,38 @@
/**
* Created by PengLing on 2017/7/3.
*/
'use strict';
const request = require('superagent');
module.exports = {
entry: (app, router, opts) => {
const apiRoot = `${opts.host}${opts.match}`;
const req = {
get: (url) => {
return request.get(`${apiRoot}${url}`);
},
post: (url, data) => {
return request
.post(`${apiRoot}${url}`)
.set('Content-Type', 'application/json')
.send(data);
},
put: (url, data) => {
return request
.put(`${apiRoot}${url}`)
.set('Content-Type', 'application/json')
.send(data);
},
delete: (url) => {
return request.del(`${apiRoot}${url}`);
}
};
app.iota = app.iota || {};
app.iota.request = req;
}
};

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

@ -70,7 +70,7 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
useEffect(() => { useEffect(() => {
if (pumpOne?.data.length) { if (pumpOne?.data.length) {
setChecked({ setChecked({
'模式切换': pumpOne.data[0].cMotor_AUTO, '模式切换': pumpOne.data[0].sMotor_RunMode == 3 ? true : false,
'启动控制': pumpOne.data[0].cMotor_START, '启动控制': pumpOne.data[0].cMotor_START,
'停止控制': pumpOne.data[0].cMotor_STOP, '停止控制': pumpOne.data[0].cMotor_STOP,
}) })
@ -120,7 +120,7 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
dispatch(bigScreen.getDevices({ thingId: thingId })), dispatch(bigScreen.getDevices({ thingId: thingId })),
dispatch(bigScreen.getInstances({ thingId: thingId })) dispatch(bigScreen.getInstances({ thingId: thingId }))
] ]
Promise.all(promiseArr).then(resArr => { Promise.all(promiseArr).then(async 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(pumpData?.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;
@ -138,15 +138,15 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId,
break; break;
} }
} }
dispatch(bigScreen.getCapabilitiesInvoke({ await dispatch(bigScreen.getCapabilitiesInvoke({
thingId, thingId,
deviceId, deviceId,
dimCapId, dimCapId,
timeout: 15000, // timeout: 15000,
param: JSON.stringify({ param: JSON.stringify({
id: sensorId, id: sensorId,
order: label === '模式切换' ? 'mode' : label === '启动控制' ? 'run' : 'stop', order: label === '模式切换' ? 'mode' : label === '启动控制' ? 'run' : 'stop',
value: nextChecked.模式切换 ? 1 : 0 // 0:平台手动,1:启动泵/停止泵/平台液控) value: (nextChecked.模式切换 || label === '启动控制' || label === '停止控制') ? 1 : 0 // 0:平台手动,1:启动泵/停止泵/平台液控)
}) })
})).then(res => { })).then(res => {
console.log('控制res', res) console.log('控制res', res)

Loading…
Cancel
Save