diff --git a/api/app/lib/controllers/analysis/network.js b/api/app/lib/controllers/analysis/network.js
index a038292..081b8dc 100644
--- a/api/app/lib/controllers/analysis/network.js
+++ b/api/app/lib/controllers/analysis/network.js
@@ -349,6 +349,80 @@ async function getDevicesLlinkStatus (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"
+ }
+ }
+ ]
+ }
+ }
+ 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;
+ } else {
+ ctx.status = 200;
+ ctx.body = rslt;
+ }
+}
+
+
module.exports = {
@@ -361,4 +435,5 @@ module.exports = {
findAlarmsDevices,
findDevicesCardStatus,
getDevicesLlinkStatus,
+ findAlarmsDevice
}
\ No newline at end of file
diff --git a/api/app/lib/routes/analysis/network.js b/api/app/lib/routes/analysis/network.js
index 6b30683..ed3b21f 100644
--- a/api/app/lib/routes/analysis/network.js
+++ b/api/app/lib/routes/analysis/network.js
@@ -13,7 +13,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/metrics/things/:iotaThingId/devices/link_status'] = { content: '获取设备在线状态/以结构物id集体获取', visible: true };
router.get('/metrics/things/:iotaThingId/devices/link_status', network.iotaLinkStatus)
-
+
app.fs.api.logAttr['GET/meta/things/:iotaThingId/devices'] = { content: '原始数据查询失败', visible: false };
router.get('/meta/things/:iotaThingId/devices', network.findDeviceMetaDeployed)
@@ -27,13 +27,9 @@ module.exports = function (app, router, opts) {
router.post('/devices/cardStatus', network.findDevicesCardStatus);
app.fs.api.logAttr['GET/metrics/devices/:deviceId/link_status'] = { content: '获取设备在线状态/以设备id单个获取', visible: false };
- router.get('/metrics/devices/:deviceId/link_status', network.getDevicesLlinkStatus);
- // app.fs.api.logAttr['GET/systemAvailability'] = { content: '获取系统可用性', visible: true };
- // router.get('/systemAvailability', operationData.getSystemAvailability)
+ router.get('/metrics/devices/:deviceId/link_status', network.getDevicesLlinkStatus);
- // app.fs.api.logAttr['GET/problemType'] = { content: '获取故障类型', visible: true };
- // router.get('/problemType', operationData.getProblemType)
+ app.fs.api.logAttr['GET/device/:deviceId/alarms'] = { content: '获取设备告警信息', visible: true };
+ router.get('/device/:deviceId/alarms', network.findAlarmsDevice);
- // app.fs.api.logAttr['GET/operationsPersonnel'] = { content: '获取运维人员', visible: true };
- // router.get('/operationsPersonnel', operationData.getOperationsPersonnel)
}
\ 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 955496f..fb0e1fd 100644
--- a/web-network/client/src/sections/network/actions/network.js
+++ b/web-network/client/src/sections/network/actions/network.js
@@ -119,18 +119,23 @@ export function getDevicesLlinkStatus (id) {
})
}
-export function findAlarmsDevice (id) {
+
+export function findAlarmsDevice (deviceIds, query) {
return dispatch => basicAction({
type: 'get',
dispatch: dispatch,
- actionType: 'GET_FIND_ALARMS_DEVICE',
- url: `${ApiTable.getDevicesLlinkStatus.replace('{deviceId}', id)}`,
- msg: { error: '获取设备告警信息失败' },
- reducer: { name: '' }
- })
+ query: query,
+ actionType: 'GET_FIND_ALARM_DEVICES',
+ url: `device/${deviceIds}/alarms`,
+ msg: {
+ error: '获取设备告警信息失败'
+ },
+ reducer: {
+ name: ''
+ }
+ });
}
-
export default {
getOrganizationsStruc,
getThingsDeploy,
diff --git a/web-network/client/src/sections/network/components/device-tree/equipment-option.js b/web-network/client/src/sections/network/components/device-tree/equipment-option.js
index c85a874..25def35 100644
--- a/web-network/client/src/sections/network/components/device-tree/equipment-option.js
+++ b/web-network/client/src/sections/network/components/device-tree/equipment-option.js
@@ -12,85 +12,82 @@ import { Request } from '@peace/utils'
const TabPane = Tabs.TabPane;
-export default ({...props}) => {
- const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch } = props;
- const [linkState, setLinkState] = useSafeState(null);
- const [alarmMsg, setAlarmMsg] = useSafeState({ new: [],history: [] });
- const [currentDeviceId, setCurrentDeviceId] = useSafeState(null);
- const [activeKey, setActiveKey] = useSafeState('1');
- const callback = (key) => {
- setActiveKey(key)
- }
- useEffect(() => {
- if(info){
- if(info?.linkState){
- setLinkState(info.linkState)
- }
- if(info?.device?.id && info.device.id != currentDeviceId){
- setCurrentDeviceId(info.device.id);
- setActiveKey('1');
- let url = ApiTable.getDevicesLlinkStatus.replace('{deviceId}', info.device.id);
+export default ({ ...props }) => {
+ const { isEdit, devices, info, parentNode, dimensions, height, deviceMetas, dispatch, actions } = props;
+ const { analysis } = actions
+
+ const [linkState, setLinkState] = useSafeState(null);
+ const [alarmMsg, setAlarmMsg] = useSafeState({ new: [], history: [] });
+ const [currentDeviceId, setCurrentDeviceId] = useSafeState(null);
+ const [activeKey, setActiveKey] = useSafeState('1');
+ const callback = (key) => {
+ setActiveKey(key)
+ }
+ useEffect(() => {
+ if (info) {
+ if (info?.linkState) {
+ setLinkState(info.linkState)
+ }
+ if (info?.device?.id && info.device.id != currentDeviceId) {
+ setCurrentDeviceId(info.device.id);
+ setActiveKey('1');
+ dispatch(analysis.getDevicesLlinkStatus(info?.device?.id)).then(res => {
+ if (res.success) {
+ setLinkState(res.payload?.data?.status)
+ }
+
+ })
- Request.get(url)
- .then(res => {
- setLinkState(res.status)
- }, error => {
- message.warning('设备在线状态获取失败');
- });
+ dispatch(analysis.findAlarmsDevice(info?.device?.id, { limit: 5 })).then(res => {
+ if (res.success) {
+ setAlarmMsg({ new: res.payload?.data?.new || [], history: res.payload?.data?.history || [] })
+ }
- url = ApiTable.getDeviceAlarms.replace('{deviceId}', info.device.id);
-
- Request.get(url, { limit: 5 })
- .then(res => {
- setAlarmMsg({ new: res.new || [],history: res.history || []})
- }
- , error => {
- message.warning('设备告警信息获取失败');
- });
- }
-
- }
+ })
+ }
- }, [info]);
- let tab = "属性";
- if (info && info?.type == "equipment") {
- tab = "属性"
- } else if (info && info?.type == "dimension") {
- tab = "采集策略"
- }
- return (
-