From 28b2cd43bdb16869957561bdd8b23b17d032f8f1 Mon Sep 17 00:00:00 2001 From: wenlele Date: Mon, 13 Nov 2023 16:22:50 +0800 Subject: [PATCH] iota --- api/.vscode/launch.json | 1 + api/app/lib/controllers/bigScreen/index .js | 59 ++++++++++++++++++- api/app/lib/routes/organization/index.js | 54 +++++++++-------- api/config.js | 8 ++- .../sections/bigScreen/actions/bigScreen.js | 37 ++++++++++++ .../components/electrity/realTimeStatus.js | 40 ++++++------- web/config.js | 8 +-- 7 files changed, 156 insertions(+), 51 deletions(-) diff --git a/api/.vscode/launch.json b/api/.vscode/launch.json index 004411d..dc15310 100644 --- a/api/.vscode/launch.json +++ b/api/.vscode/launch.json @@ -17,6 +17,7 @@ // 研发 "-g postgres://postgres:123456@10.8.30.166:5432/PumpStation", // "-g postgres://FashionAdmin:123456@10.8.30.166:5432/PumpStation", + "-x http://221.230.55.28:7007", //商用代理 "--redisHost localhost", "--redisPort 6379", // 测试 diff --git a/api/app/lib/controllers/bigScreen/index .js b/api/app/lib/controllers/bigScreen/index .js index 8bf204b..57be29d 100644 --- a/api/app/lib/controllers/bigScreen/index .js +++ b/api/app/lib/controllers/bigScreen/index .js @@ -116,10 +116,65 @@ const getVideoUrl = async function (ctx) { } +async function getDevices (ctx, next) { + + try { + let { thingId } = ctx.query; + + const res = await ctx.app.fs.iota.get(`/metrics/things/${thingId}/devices/link_status`) || {} + + ctx.status = 200; + ctx.body = res.body; + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); + ctx.status = 400; + ctx.body = { name: 'FindError', message: '获取iota数据失败' }; + } +} + + +async function getInstances (ctx, next) { + + try { + let { thingId } = ctx.query; + + const res = await ctx.app.fs.iota.get(`/things/${thingId}/deploys`) || {} + + ctx.status = 200; + ctx.body = res.body; + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); + ctx.status = 400; + ctx.body = { name: 'FindError', message: '获取iota数据失败' }; + } +} + + +async function getCapabilitiesInvoke (ctx, next) { + + try { + let data = ctx.query; + + const res = await ctx.app.fs.iota.post(`/capabilities/invoke`, data) || {} + + ctx.status = 200; + ctx.body = res.body; + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); + ctx.status = 400; + ctx.body = { name: 'FindError', message: '下发指令失败' }; + } +} + + + + module.exports = { axyData, pumpInformation, getPumpStation, - getVideoUrl - + getVideoUrl, + getDevices, + getInstances, + getCapabilitiesInvoke } \ No newline at end of file diff --git a/api/app/lib/routes/organization/index.js b/api/app/lib/routes/organization/index.js index 171c128..53cfab3 100644 --- a/api/app/lib/routes/organization/index.js +++ b/api/app/lib/routes/organization/index.js @@ -6,39 +6,47 @@ module.exports = function (app, router, opts) { - app.fs.api.logAttr['GET/pump/station'] = { content: '获取所有站点信息', visible: true }; - router.get('/pump/station', data.getPumpStation); + app.fs.api.logAttr['GET/pump/station'] = { content: '获取所有站点信息', visible: true }; + router.get('/pump/station', data.getPumpStation); - app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true }; - router.post('/axyData', data.axyData); + app.fs.api.logAttr['POST/axyData'] = { content: '获取安心云数据', visible: true }; + router.post('/axyData', data.axyData); - app.fs.api.logAttr['GET/pumpInformation'] = { content: '获取泵站信息', visible: true }; - router.get('/pumpInformation', data.pumpInformation); + app.fs.api.logAttr['GET/pumpInformation'] = { content: '获取泵站信息', visible: true }; + router.get('/pumpInformation', data.pumpInformation); - app.fs.api.logAttr['GET/videoUrl'] = { content: '获取视频监控url', visible: true }; - router.get('/videoUrl', data.getVideoUrl); + app.fs.api.logAttr['GET/videoUrl'] = { content: '获取视频监控url', visible: true }; + router.get('/videoUrl', data.getVideoUrl); - app.fs.api.logAttr['GET/water/level/all'] = { content: '获取所有泵站七天内最新集水池液位', visible: true }; - router.get('/water/level/all', data.getPumpStation); + app.fs.api.logAttr['GET/water/level/all'] = { content: '获取所有泵站七天内最新集水池液位', visible: true }; + router.get('/water/level/all', data.getPumpStation); - app.fs.api.logAttr['GET/water/level/six'] = { content: '获取泵站6h最新集水池液位', visible: true }; - router.get('/water/level/six', data.getPumpStation); + app.fs.api.logAttr['GET/water/level/six'] = { content: '获取泵站6h最新集水池液位', visible: true }; + router.get('/water/level/six', data.getPumpStation); - app.fs.api.logAttr['GET/water/pump/state/all'] = { content: '获取水泵状态', visible: true }; - router.get('/water/pump/state/all', data.getPumpStation); + app.fs.api.logAttr['GET/water/pump/state/all'] = { content: '获取水泵状态', visible: true }; + router.get('/water/pump/state/all', data.getPumpStation); - app.fs.api.logAttr['GET/capacity'] = { content: '获取能耗监测数据', visible: true }; - router.get('/capacity', data.getPumpStation); + app.fs.api.logAttr['GET/capacity'] = { content: '获取能耗监测数据', visible: true }; + router.get('/capacity', data.getPumpStation); - app.fs.api.logAttr['GET/currentSix'] = { content: '获取水泵数据', visible: true }; - router.get('/currentSix', data.getPumpStation); + app.fs.api.logAttr['GET/currentSix'] = { content: '获取水泵数据', visible: true }; + router.get('/currentSix', data.getPumpStation); - app.fs.api.logAttr['GET/cabinet'] = { content: '获取进线柜数据', visible: true }; - router.get('/cabinet', data.getPumpStation); + app.fs.api.logAttr['GET/cabinet'] = { content: '获取进线柜数据', visible: true }; + router.get('/cabinet', data.getPumpStation); - app.fs.api.logAttr['GET/threePhase'] = { content: '获取三相电流数据', visible: true }; - router.get('/threePhase', data.getPumpStation); - + app.fs.api.logAttr['GET/threePhase'] = { content: '获取三相电流数据', visible: true }; + router.get('/threePhase', data.getPumpStation); + + app.fs.api.logAttr['GET/devices'] = { content: '获取水泵deviceId', visible: true }; + router.get('/devices', data.getDevices); + + app.fs.api.logAttr['GET/instances'] = { content: '获取水泵sensorId', visible: true }; + router.get('/instances', data.getInstances); + + app.fs.api.logAttr['GET/capabilities/invoke'] = { content: '下发指令', visible: true }; + router.get('/capabilities/invoke', data.getCapabilitiesInvoke); }; \ No newline at end of file diff --git a/api/config.js b/api/config.js index f14bb66..2312314 100644 --- a/api/config.js +++ b/api/config.js @@ -17,6 +17,8 @@ args.option('redisPswd', 'redisPassword'); args.option('apiAnxinyunUrl', "安心云api"); args.option('axyProject', '安心云泵站项目信息'); +args.option(['x', 'iota-proxy'], 'iota代理URL'); + const flags = args.parse(process.argv); @@ -28,10 +30,11 @@ const AXY_BZ_PROJECT = process.env.AXY_BZ_PROJECT || flags.axyProject const IOTA_REDIS_SERVER_HOST = process.env.IOTA_REDIS_SERVER_HOST || flags.redisHost || "localhost";//redis IP const IOTA_REDIS_SERVER_PORT = process.env.IOTA_REDIS_SERVER_PORT || flags.redisPort || "6379";//redis 端口 const IOTA_REDIS_SERVER_PWD = process.env.IOTA_REDIS_SERVER_PWD || flags.redisPswd || "";//redis 密码 +const ANXINCLOUD_PROXY_IOTA = process.env.ANXINCLOUD_PROXY_IOTA || flags.iotaProxy; -if (!BENGZHAN_DB || !API_ANXINYUN_URL || !AXY_BZ_PROJECT || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT) { +if (!BENGZHAN_DB || !API_ANXINYUN_URL || !AXY_BZ_PROJECT || !IOTA_REDIS_SERVER_HOST || !IOTA_REDIS_SERVER_PORT || !ANXINCLOUD_PROXY_IOTA) { console.log('缺少启动参数,异常退出'); args.showHelp(); process.exit(-1); @@ -63,6 +66,9 @@ const product = { pssaRequest: [{// name 会作为一个 request 出现在 ctx.app.fs name: 'anxinyun', root: API_ANXINYUN_URL + }, {// name 会作为一个 request 出现在 ctx.app.fs + name: 'iota', + root: ANXINCLOUD_PROXY_IOTA }], } } diff --git a/web/client/src/sections/bigScreen/actions/bigScreen.js b/web/client/src/sections/bigScreen/actions/bigScreen.js index c14e4eb..525b0ae 100644 --- a/web/client/src/sections/bigScreen/actions/bigScreen.js +++ b/web/client/src/sections/bigScreen/actions/bigScreen.js @@ -111,4 +111,41 @@ export function getThreePhase (query = {}) { }); } +export function getDevices (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + actionType: 'GET_DEVICES', + url: 'devices', + query: query, + msg: { error: '获取水泵deviceId失败' }, + reducer: { name: '' } + }); +} + +export function getInstances (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + actionType: 'GET_INSTANCES', + url: 'instances', + query: query, + msg: { error: '获取水泵sensorId失败' }, + reducer: { name: '' } + }); +} + + +export function getCapabilitiesInvoke (query = {}) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + actionType: 'GET_CAPABILITIES_INVOKE', + url: 'capabilities/invoke', + query: query, + msg: { error: '下发指令失败' }, + reducer: { name: '' } + }); +} + diff --git a/web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js b/web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js index d6c9ee4..39abc8c 100644 --- a/web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js +++ b/web/client/src/sections/bigScreen/components/electrity/realTimeStatus.js @@ -110,12 +110,15 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId, let dimCapId = null; const promiseArr = [ - dispatch(bigScreen.axyData({ - type: 'get', url: `/metrics/things/${thingId}/devices/link_status` - })), - dispatch(bigScreen.axyData({ - type: 'get', url: `/things/${thingId}/devices/deploy` - })) + // dispatch(bigScreen.axyData({ + // type: 'get', url: `/metrics/things/${thingId}/devices/link_status` + // })), + // dispatch(bigScreen.axyData({ + // type: 'get', url: `/things/${thingId}/devices/deploy` + // })) + + dispatch(bigScreen.getDevices({ thingId: thingId })), + dispatch(bigScreen.getInstances({ thingId: thingId })) ] Promise.all(promiseArr).then(resArr => { if (resArr[0].success && resArr[1].success) { @@ -135,21 +138,16 @@ const RealTimeStatus = ({ dispatch, actions, user, pumpId, pumpList, setPumpId, break; } } - dispatch(bigScreen.axyData({ - type: 'post', url: `/capabilities/invoke`, - params: { - data: { - thingId, - deviceId, - dimCapId, - timeout: 15000, - param: JSON.stringify({ - id: sensorId, - order: label === '模式切换' ? 'mode' : label === '启动控制' ? 'run' : 'stop', - value: nextChecked.模式切换 ? 1 : 0 // 0:平台手动,1:启动泵/停止泵/平台液控) - }) - } - } + dispatch(bigScreen.getCapabilitiesInvoke({ + thingId, + deviceId, + dimCapId, + timeout: 15000, + param: JSON.stringify({ + id: sensorId, + order: label === '模式切换' ? 'mode' : label === '启动控制' ? 'run' : 'stop', + value: nextChecked.模式切换 ? 1 : 0 // 0:平台手动,1:启动泵/停止泵/平台液控) + }) })).then(res => { console.log('控制res', res) }) diff --git a/web/config.js b/web/config.js index 8268c7c..4b3491f 100644 --- a/web/config.js +++ b/web/config.js @@ -18,13 +18,13 @@ args.option(['u', 'api-url'], 'webapi的URL'); -const flags = args.parse(process.argv); +const flags = args.parse(process.argv); const FS_UNIAPP_API = process.env.FS_UNIAPP_API || flags.apiUrl; const weatherUrl = process.env.ANXINCLOUD_WEATHERAPP_API || "https://weatherssj.anxinyun.cn/weatherApp/weather/getImmeData" if ( - !FS_UNIAPP_API + !FS_UNIAPP_API ) { console.log('缺少启动参数,异常退出'); args.showHelp(); @@ -43,7 +43,7 @@ const product = { }, { entry: require('./middlewares/proxy').entry, opts: { - + } }, { entry: require('./middlewares/attachment').entry, @@ -59,7 +59,7 @@ const product = { }, { entry: require('./client').entry,// 静态信息 opts: { - + } }], logger: {