zhaobing’ 1 year ago
parent
commit
1c39128f3f
  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 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,
}

2
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 = {

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

1
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';

18
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}
/>
) : <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
: (

1
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) {

Loading…
Cancel
Save