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 ( - - - {info && parentNode ? - info.type == "equipment" ? - - { - parentNode && info && info.meta && info.meta.filteredResource && (JSON.parse(info.meta.filteredResource.properties).deviceType != 'dau.node') ? - - - : null - } - - ) + } + + }, [info]); + let tab = "属性"; + if (info && info?.type == "equipment") { + tab = "属性" + } else if (info && info?.type == "dimension") { + tab = "采集策略" + } + return ( + + + {info && parentNode ? + info.type == "equipment" ? + + { + parentNode && info && info.meta && info.meta.filteredResource && (JSON.parse(info.meta.filteredResource.properties).deviceType != 'dau.node') ? + + + : null + } + + ) } diff --git a/web-network/client/src/sections/network/components/device-tree/index.js b/web-network/client/src/sections/network/components/device-tree/index.js index 72cb739..ea90bc9 100644 --- a/web-network/client/src/sections/network/components/device-tree/index.js +++ b/web-network/client/src/sections/network/components/device-tree/index.js @@ -17,7 +17,7 @@ const { ModifyEquipmentNetworking } = AuthorizationCode; export default function ({ ...props }) { const { - dispatch, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct, + dispatch,actions, clientHeight, deviceMetasWithFollow, deviceList, dimensionlist, struct, } = props; const [g6TreeDirection, setG6TreeDirection] = useSafeState('TB'); const [devices, setDevices] = useSafeState(null); @@ -305,6 +305,7 @@ export default function ({ ...props }) { dimensions={dimensionlist} height={containerHeight} dispatch={dispatch} + actions={actions} /> 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 21ea88d..bdf3779 100644 --- a/web-network/client/src/sections/network/containers/device-monitor.js +++ b/web-network/client/src/sections/network/containers/device-monitor.js @@ -14,7 +14,7 @@ import { DeviceTypes } from '../constant'; import qs from "qs"; import '../style.less'; -import TableShow from './tableShow' +import TableShow from './tableShow' function DeviceMonitor ({ ...props }) { const { dispatch, actions, user, clientWidth, clientHeight, loading, @@ -30,13 +30,19 @@ function DeviceMonitor ({ ...props }) { let strucParam = JSON.parse((qs.parse(props.location?.search.slice(1)) || {})?.strucData) - console.log(1111, strucParam) - - useEffect(() => { if (strucParam?.thingId) { - dispatch(analysis.getThingsDeploy(strucParam?.thingId)) + dispatch(analysis.getThingsDeploy(strucParam?.thingId)).then(res => { + console.log(3213, 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 })); + } + } + }) dispatch(analysis.getDeviceMetaDeployed(strucParam?.thingId)) } }, []); @@ -107,59 +113,6 @@ function DeviceMonitor ({ ...props }) { return result; }, [devices, deviceListAlarms]); - // 筛选过滤数据 - const filterDataSource = () => { - const { - name, deviceType, productType, productName, location, status, - } = params; - return dataSource.filter((s) => (name ? s.name ? (s.name.indexOf(name) != -1 || PinyinHelper.isPinyinMatched(s.name, name)) : false : true) - && (location ? s.location ? (s.location.indexOf(location) != -1 || PinyinHelper.isPinyinMatched(s.location, location)) : false : true) - && (deviceType ? s.deviceTypeId == deviceType : true) - && (productType ? s.productType == productType : true) - && (status ? s.status == status : true) - && (productName ? s.productName ? (s.productName.indexOf(productName) != -1 || PinyinHelper.isPinyinMatched(s.productName, productName)) : false : true)); - }; - - // const deviceTypeIds = Func.uniqueArr(dataSource, 'deviceTypeId'); - // const productTypeIds = Func.uniqueArr(dataSource, 'productType'); - - const columns = [{ - title: '名称', - dataIndex: 'name', - ellipsis: true, - - }, { - title: '设备类型', - dataIndex: 'deviceType', - // valueEnum: Func.transValueEnum(deviceTypeIds, 'deviceTypeId', 'deviceType'), - // fieldProps: Func.getSelectCommonProps(), - - }, { - title: '产品名称', - dataIndex: 'productName', - ellipsis: true, - - }, { - title: '产品型号', - dataIndex: 'productType', - // valueEnum: Func.transValueEnum(productTypeIds, 'productType', 'productType'), - // fieldProps: Func.getSelectCommonProps(), - }, { - title: '测点', - dataIndex: 'location', - - }, { - title: '状态', - dataIndex: 'status', - filters: true, - onFilter: true, - valueEnum: { - normal: { text: '正常', status: 'Success' }, - alarm: { text: '异常', status: 'Error' }, - }, - // fieldProps: Func.getSelectCommonProps(), - }]; - const renderTitle = () => (
设备总数: @@ -177,10 +130,9 @@ function DeviceMonitor ({ ...props }) { 个;
); - const data = filterDataSource(); + return ( - //
div
- // + { @@ -193,18 +145,18 @@ function DeviceMonitor ({ ...props }) { deviceList={devices} dimensionlist={dimensions} dispatch={dispatch} + actions={actions} struct={strucParam} clientHeight={clientHeight} clientWidth={clientWidth} /> ) : : ( - + ) } - // ); }