Browse Source

获取设备在离线

dev
wenlele 1 year ago
parent
commit
0efb573261
  1. 182
      api/app/lib/controllers/analysis/network.js
  2. 2
      api/app/lib/controllers/firmwareUpgrade/index.js
  3. 4
      api/app/lib/routes/analysis/network.js
  4. 20
      web-network/client/src/sections/network/actions/network.js
  5. 1
      web-network/client/src/sections/network/components/device-tree/zuwang-main.js
  6. 18
      web-network/client/src/sections/network/containers/device-monitor.js
  7. 1
      web/client/src/sections/analysis/containers/network.jsx

182
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 error = { name: 'FindError', message: '告警信息获取失败' };
let rslt = null; let rslt = null;
const { deviceId } = ctx.params; const { deviceId } = ctx.params;
if (deviceId) { if (deviceId) {
try { try {
const { limit } = ctx.query; const { limit } = ctx.query;
const client = ctx.app.fs.esclient[ALARM];//准备查询 const client = ctx.app.fs.esclient[ALARM];//准备查询
let params = { let params = {
index: client.config.index, index: client.config.index,
type: client.config.type, type: client.config.type,
size: limit || 5, size: limit || 5,
body: { body: {
"query": { "query": {
"bool": { "bool": {
"must": [ "must": [
{ {
"match": { "match": {
"source_id": deviceId "source_id": deviceId
}
},
{
"terms": {
"state": []
}
}
]
}
},
"sort": [
{
"start_time": {
"order": "desc"
} }
} },
] {
} "terms": {
} "state": []
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; "sort": [
let historyAlarm = await client.search(params); {
const timer = ctx.app.fs.timer; "start_time": {
function filterAlarmMsg(oriMsg) { "order": "desc"
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), let newState = [AlarmState.Creation, AlarmState.CountUpgrade, AlarmState.LevelUpgrade];
endTime: timer.toCSTString(s._source.end_time), let historyState = [AlarmState.AutoElimination, AlarmState.ManElimination];
}) params.body.query.bool.must[1].terms.state = newState;
} let newAlarms = await client.search(params);//查询
return msg; params.body.query.bool.must[1].terms.state = historyState;
} params.size = 9999;
rslt = { new: filterAlarmMsg(newAlarms.hits.hits), history: filterAlarmMsg(historyAlarm.hits.hits) } let historyAlarm = await client.search(params);
error = null; const timer = ctx.app.fs.timer;
} catch (err) { function filterAlarmMsg (oriMsg) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); 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) { if (error) {
ctx.status = 400; ctx.status = 400;
ctx.body = error; ctx.body = error;
} else { } else {
ctx.status = 200; ctx.status = 200;
ctx.body = rslt; ctx.body = rslt;
} }
} }
//查询智能 //查询智能
@ -428,32 +428,49 @@ async function createInvoke (ctx, next) {
const data = ctx.request.body const data = ctx.request.body
let rslt = null, code = null, issuccess = false, text = null; let rslt = null, code = null, issuccess = false, text = null;
if (data) { if (data) {
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
let iotaThingId = data.thingId; let iotaThingId = data.thingId;
let structure = await models.Structure.findOne({ where: { iotaThingId } }); let structure = await models.Structure.findOne({ where: { iotaThingId } });
if (structure) { if (structure) {
const dataToIota = data; const dataToIota = data;
let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota) let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota)
rslt = JSON.parse(iotaResponse) rslt = JSON.parse(iotaResponse)
error = null; error = null;
} else { } else {
error = { name: 'NotFound', message: `不存在{iotaThingId=${iotaThingId}}的结构物` }; error = { name: 'NotFound', message: `不存在{iotaThingId=${iotaThingId}}的结构物` };
} }
} catch (err) { } catch (err) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${err}`);
} }
} }
if (error) { if (error) {
ctx.status = 400; ctx.status = 400;
ctx.body = error; ctx.body = error;
} else { } else {
ctx.status = 200; ctx.status = 200;
ctx.body = rslt; 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 = { module.exports = {
getOrganizationsStruc, getOrganizationsStruc,
@ -466,5 +483,6 @@ module.exports = {
findDevicesCardStatus, findDevicesCardStatus,
getDevicesLlinkStatus, getDevicesLlinkStatus,
findAlarmsDevice, findAlarmsDevice,
createInvoke createInvoke,
getThingStatus,
} }

2
api/app/lib/controllers/firmwareUpgrade/index.js

@ -264,7 +264,7 @@ async function deleteFirmware(ctx){
try{ try{
await ctx.app.fs.craw.delete(ApiTable.firmwareUpgrade,{query:{version,device_meta_id,token:tokenup}}) await ctx.app.fs.craw.delete(ApiTable.firmwareUpgrade,{query:{version,device_meta_id,token:tokenup}})
ctx.status=204 ctx.status=204
}catch(eror){ }catch(error){
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`) ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`)
ctx.status = 400 ctx.status = 400
ctx.body = { ctx.body = {

4
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 }; app.fs.api.logAttr['GET/device/:deviceId/alarms'] = { content: '获取设备告警信息', visible: true };
router.get('/device/:deviceId/alarms', network.findAlarmsDevice); router.get('/device/:deviceId/alarms', network.findAlarmsDevice);
app.fs.api.logAttr['GET/thing/status'] = { content: '获取设备在离线', visible: true };
router.get('/thing/status', network.getThingStatus);
} }

20
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 { export default {
getOrganizationsStruc, getOrganizationsStruc,
getThingsDeploy, getThingsDeploy,
@ -148,6 +166,6 @@ export default {
findDevicesCardStatus, findDevicesCardStatus,
getDevicesLlinkStatus, getDevicesLlinkStatus,
findAlarmsDevice, findAlarmsDevice,
getThingStatus
} }

1
web-network/client/src/sections/network/components/device-tree/zuwang-main.js

@ -8,6 +8,7 @@ import {
} from 'antd'; } from 'antd';
import Ps from 'perfect-scrollbar'; import Ps from 'perfect-scrollbar';
import createG6 from './edit-map'; import createG6 from './edit-map';
import moment from 'moment'
// import { useThingsLinkStatus } from '../../actions/hooks'; // import { useThingsLinkStatus } from '../../actions/hooks';

18
web-network/client/src/sections/network/containers/device-monitor.js

@ -36,15 +36,17 @@ function DeviceMonitor ({ ...props }) {
useEffect(() => { useEffect(() => {
if (strucParam?.thingId) { if (strucParam?.thingId) {
dispatch(analysis.getThingsDeploy(strucParam?.thingId, token)).then(res => { dispatch(analysis.getThingsDeploy(strucParam?.thingId, token)).then(res => {
if (res.success) { // if (res.success) {
const instances = res?.payload?.data?.instances; // const instances = res?.payload?.data?.instances;
if (instances) { // if (instances) {
const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d'); // const deviceIds = Object.keys(instances).filter((k) => instances[k]?.type == 's.d');
dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }, token)); // dispatch(analysis.getDevicesAlarms(deviceIds, { limit: 5 }, token));
} // }
} // }
}) })
dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId, token)) dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId, token))
dispatch(analysis.getThingStatus({ thingId: strucParam?.thingId }, token));
} }
}, []); }, []);
@ -132,7 +134,7 @@ function DeviceMonitor ({ ...props }) {
clientHeight={clientHeight} clientHeight={clientHeight}
clientWidth={clientWidth} clientWidth={clientWidth}
token={token} token={token}
/> />
) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} /> ) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
: ( : (

1
web/client/src/sections/analysis/containers/network.jsx

@ -24,6 +24,7 @@ const Network = ({
useEffect(() => { useEffect(() => {
setSpinning(true)
let projectData = [] let projectData = []
let project = projectPoms.filter(v => v.pepProjectIsDelete != 1) let project = projectPoms.filter(v => v.pepProjectIsDelete != 1)
if (projectPoms?.length) { if (projectPoms?.length) {

Loading…
Cancel
Save