From 0efb57326170a7784a7ada9d4d859e795534b5a9 Mon Sep 17 00:00:00 2001 From: wenlele Date: Wed, 6 Dec 2023 17:35:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=AE=BE=E5=A4=87=E5=9C=A8?= =?UTF-8?q?=E7=A6=BB=E7=BA=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/analysis/network.js | 182 ++++++++++-------- .../lib/controllers/firmwareUpgrade/index.js | 2 +- api/app/lib/routes/analysis/network.js | 4 +- .../src/sections/network/actions/network.js | 20 +- .../components/device-tree/zuwang-main.js | 1 + .../network/containers/device-monitor.js | 18 +- .../sections/analysis/containers/network.jsx | 1 + 7 files changed, 135 insertions(+), 93 deletions(-) diff --git a/api/app/lib/controllers/analysis/network.js b/api/app/lib/controllers/analysis/network.js index 14fe404..ac78f06 100644 --- a/api/app/lib/controllers/analysis/network.js +++ b/api/app/lib/controllers/analysis/network.js @@ -350,76 +350,76 @@ async function getDevicesLlinkStatus (ctx, next) { } }; -async function findAlarmsDevice(ctx, next) { +async function findAlarmsDevice (ctx, next) { let error = { name: 'FindError', message: '告警信息获取失败' }; let rslt = null; const { deviceId } = ctx.params; if (deviceId) { - try { - const { limit } = ctx.query; - const client = ctx.app.fs.esclient[ALARM];//准备查询 - let params = { - index: client.config.index, - type: client.config.type, - size: limit || 5, - body: { - "query": { - "bool": { - "must": [ - { - "match": { - "source_id": deviceId - } - }, - { - "terms": { - "state": [] - } - } - ] - } - }, - "sort": [ - { - "start_time": { - "order": "desc" + try { + const { limit } = ctx.query; + const client = ctx.app.fs.esclient[ALARM];//准备查询 + let params = { + index: client.config.index, + type: client.config.type, + size: limit || 5, + body: { + "query": { + "bool": { + "must": [ + { + "match": { + "source_id": deviceId } - } - ] - } - } - let newState = [AlarmState.Creation, AlarmState.CountUpgrade, AlarmState.LevelUpgrade]; - let historyState = [AlarmState.AutoElimination, AlarmState.ManElimination]; - params.body.query.bool.must[1].terms.state = newState; - let newAlarms = await client.search(params);//查询 - params.body.query.bool.must[1].terms.state = historyState; - params.size = 9999; - let historyAlarm = await client.search(params); - const timer = ctx.app.fs.timer; - function filterAlarmMsg(oriMsg) { - let msg = []; - for (let s of oriMsg) { - msg.push({ - alarmContent: s._source.alarm_content, - alarmCount: s._source.alarm_count, - startTime: timer.toCSTString(s._source.start_time), - endTime: timer.toCSTString(s._source.end_time), - }) - } - return msg; - } - rslt = { new: filterAlarmMsg(newAlarms.hits.hits), history: filterAlarmMsg(historyAlarm.hits.hits) } - error = null; - } catch (err) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); - } + }, + { + "terms": { + "state": [] + } + } + ] + } + }, + "sort": [ + { + "start_time": { + "order": "desc" + } + } + ] + } + } + let newState = [AlarmState.Creation, AlarmState.CountUpgrade, AlarmState.LevelUpgrade]; + let historyState = [AlarmState.AutoElimination, AlarmState.ManElimination]; + params.body.query.bool.must[1].terms.state = newState; + let newAlarms = await client.search(params);//查询 + params.body.query.bool.must[1].terms.state = historyState; + params.size = 9999; + let historyAlarm = await client.search(params); + const timer = ctx.app.fs.timer; + function filterAlarmMsg (oriMsg) { + let msg = []; + for (let s of oriMsg) { + msg.push({ + alarmContent: s._source.alarm_content, + alarmCount: s._source.alarm_count, + startTime: timer.toCSTString(s._source.start_time), + endTime: timer.toCSTString(s._source.end_time), + }) + } + return msg; + } + rslt = { new: filterAlarmMsg(newAlarms.hits.hits), history: filterAlarmMsg(historyAlarm.hits.hits) } + error = null; + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); + } } if (error) { - ctx.status = 400; - ctx.body = error; + ctx.status = 400; + ctx.body = error; } else { - ctx.status = 200; - ctx.body = rslt; + ctx.status = 200; + ctx.body = rslt; } } //查询智能 @@ -428,32 +428,49 @@ async function createInvoke (ctx, next) { const data = ctx.request.body let rslt = null, code = null, issuccess = false, text = null; if (data) { - try { - const models = ctx.fs.dc.models; - let iotaThingId = data.thingId; - let structure = await models.Structure.findOne({ where: { iotaThingId } }); - if (structure) { - const dataToIota = data; - let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota) - rslt = JSON.parse(iotaResponse) - error = null; - } else { - error = { name: 'NotFound', message: `不存在{iotaThingId=${iotaThingId}}的结构物` }; - } - } catch (err) { - ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); - } + try { + const models = ctx.fs.dc.models; + let iotaThingId = data.thingId; + let structure = await models.Structure.findOne({ where: { iotaThingId } }); + if (structure) { + const dataToIota = data; + let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota) + rslt = JSON.parse(iotaResponse) + error = null; + } else { + error = { name: 'NotFound', message: `不存在{iotaThingId=${iotaThingId}}的结构物` }; + } + } catch (err) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); + } } if (error) { - ctx.status = 400; - ctx.body = error; + ctx.status = 400; + ctx.body = error; } else { - ctx.status = 200; - ctx.body = rslt; + ctx.status = 200; + ctx.body = rslt; } }; +async function getThingStatus (ctx) { + let res = [] + try { + const { thingId } = ctx.query + let res = await ctx.app.fs.craw.get('thing/status', { query: { thingId } }) + ctx.status = 200 + if (res) { + ctx.body = JSON.parse(res) + } + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) + ctx.status = 200 + ctx.body = [] + } +} + + module.exports = { getOrganizationsStruc, @@ -466,5 +483,6 @@ module.exports = { findDevicesCardStatus, getDevicesLlinkStatus, findAlarmsDevice, - createInvoke + createInvoke, + getThingStatus, } \ No newline at end of file diff --git a/api/app/lib/controllers/firmwareUpgrade/index.js b/api/app/lib/controllers/firmwareUpgrade/index.js index 57be0ba..8f7de9b 100644 --- a/api/app/lib/controllers/firmwareUpgrade/index.js +++ b/api/app/lib/controllers/firmwareUpgrade/index.js @@ -264,7 +264,7 @@ async function deleteFirmware(ctx){ try{ await ctx.app.fs.craw.delete(ApiTable.firmwareUpgrade,{query:{version,device_meta_id,token:tokenup}}) ctx.status=204 - }catch(eror){ + }catch(error){ ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) ctx.status = 400 ctx.body = { diff --git a/api/app/lib/routes/analysis/network.js b/api/app/lib/routes/analysis/network.js index ed3b21f..4e32ef6 100644 --- a/api/app/lib/routes/analysis/network.js +++ b/api/app/lib/routes/analysis/network.js @@ -31,5 +31,7 @@ module.exports = function (app, router, opts) { app.fs.api.logAttr['GET/device/:deviceId/alarms'] = { content: '获取设备告警信息', visible: true }; router.get('/device/:deviceId/alarms', network.findAlarmsDevice); - + + app.fs.api.logAttr['GET/thing/status'] = { content: '获取设备在离线', visible: true }; + router.get('/thing/status', network.getThingStatus); } \ No newline at end of file diff --git a/web-network/client/src/sections/network/actions/network.js b/web-network/client/src/sections/network/actions/network.js index 8f08ee2..557e95a 100644 --- a/web-network/client/src/sections/network/actions/network.js +++ b/web-network/client/src/sections/network/actions/network.js @@ -136,6 +136,24 @@ export function findAlarmsDevice (deviceIds, query, token) { }); } +export function getThingStatus (query, token) { + return dispatch => basicAction({ + type: 'get', + dispatch: dispatch, + query: query, + actionType: 'GET_THING_STATUS', + url: `thing/status?token=${token}`, + msg: { + error: '获取设备在离线失败' + }, + reducer: { + name: 'thingStatus' + } + }); +} + + + export default { getOrganizationsStruc, getThingsDeploy, @@ -148,6 +166,6 @@ export default { findDevicesCardStatus, getDevicesLlinkStatus, findAlarmsDevice, - + getThingStatus } diff --git a/web-network/client/src/sections/network/components/device-tree/zuwang-main.js b/web-network/client/src/sections/network/components/device-tree/zuwang-main.js index 956889a..5d7143d 100644 --- a/web-network/client/src/sections/network/components/device-tree/zuwang-main.js +++ b/web-network/client/src/sections/network/components/device-tree/zuwang-main.js @@ -8,6 +8,7 @@ import { } from 'antd'; import Ps from 'perfect-scrollbar'; import createG6 from './edit-map'; +import moment from 'moment' // import { useThingsLinkStatus } from '../../actions/hooks'; diff --git a/web-network/client/src/sections/network/containers/device-monitor.js b/web-network/client/src/sections/network/containers/device-monitor.js index c2cdc12..8289e52 100644 --- a/web-network/client/src/sections/network/containers/device-monitor.js +++ b/web-network/client/src/sections/network/containers/device-monitor.js @@ -36,15 +36,17 @@ function DeviceMonitor ({ ...props }) { useEffect(() => { if (strucParam?.thingId) { dispatch(analysis.getThingsDeploy(strucParam?.thingId, token)).then(res => { - if (res.success) { - const instances = res?.payload?.data?.instances; - if (instances) { - const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d'); - dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }, token)); - } - } + // if (res.success) { + // const instances = res?.payload?.data?.instances; + // if (instances) { + // const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d'); + // dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }, token)); + // } + // } }) dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId, token)) + dispatch(analysis.getThingStatus({ thingId: strucParam?.thingId }, token)); + } }, []); @@ -132,7 +134,7 @@ function DeviceMonitor ({ ...props }) { clientHeight={clientHeight} clientWidth={clientWidth} token={token} - + /> ) : : ( diff --git a/web/client/src/sections/analysis/containers/network.jsx b/web/client/src/sections/analysis/containers/network.jsx index 95c059b..45a38b7 100644 --- a/web/client/src/sections/analysis/containers/network.jsx +++ b/web/client/src/sections/analysis/containers/network.jsx @@ -24,6 +24,7 @@ const Network = ({ useEffect(() => { + setSpinning(true) let projectData = [] let project = projectPoms.filter(v => v.pepProjectIsDelete != 1) if (projectPoms?.length) {