Browse Source

feat:智能断路器设备开关加入

dev
zhaobing’ 1 year ago
parent
commit
0191b25b1c
  1. 2
      api/.vscode/launch.json
  2. 13
      api/app/lib/controllers/analysis/network.js
  3. 4
      api/app/lib/routes/analysis/network.js
  4. 19
      web-network/client/src/sections/network/actions/network.js
  5. 107
      web-network/client/src/sections/network/containers/tableShow.js
  6. 2
      web-network/client/src/utils/webapi.js

2
api/.vscode/launch.json

@ -29,7 +29,7 @@
"-r fs-workflow", "-r fs-workflow",
// "-e http://10.8.30.60:5601", // "-e http://10.8.30.60:5601",
// "--iotaProxy http://10.8.30.157:17007", // "--iotaProxy http://10.8.30.157:17007",
"--iotaProxy http://iotaproxy.anxinyun.cn", // "--iotaProxy https://iotaproxy.anxinyun.cn", //
// //
"--redisHost localhost", "--redisHost localhost",
"--redisPort 6379", "--redisPort 6379",

13
api/app/lib/controllers/analysis/network.js

@ -422,24 +422,17 @@ async function findAlarmsDevice (ctx, next) {
ctx.body = rslt; ctx.body = rslt;
} }
} }
//查询智能 //查询智能,以及空开设备的开关
async function createInvoke (ctx, next) { async function createInvoke (ctx, next) {
let error = { name: 'CreateError', message: '命令下发失败' }; let error = { name: 'CreateError', message: '命令下发失败' };
const data = ctx.request.body const data = ctx.request.body
let rslt = null, code = null, issuccess = false, text = null; let rslt = null
if (data) { if (data) {
try { try {
const models = ctx.fs.dc.models; const dataToIota = data
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) let iotaResponse = await ctx.app.fs.iotRequest.post(`/capabilities/invoke`, dataToIota)
rslt = JSON.parse(iotaResponse) rslt = JSON.parse(iotaResponse)
error = null; error = null;
} else {
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}`);
} }

4
api/app/lib/routes/analysis/network.js

@ -34,4 +34,8 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/thing/status'] = { content: '获取设备在离线', visible: true }; app.fs.api.logAttr['GET/thing/status'] = { content: '获取设备在离线', visible: true };
router.get('/thing/status', network.getThingStatus); router.get('/thing/status', network.getThingStatus);
//空开设备查询状态和开关设备
app.fs.api.logAttr['POST/capabilities/invoke'] = { content: '及时采集', visible: true };
router.post('/capabilities/invoke', network.createInvoke);
} }

19
web-network/client/src/sections/network/actions/network.js

@ -153,6 +153,22 @@ export function getThingStatus (query, token) {
} }
export function invokeCapability(capabilityData,token) {
return dispatch => basicAction({
type: 'post',
data: capabilityData,
dispatch: dispatch,
actionType: 'REQUEST_INVOKE_CAPABILITY',
url: `${ApiTable.invokeCapability}?token=${token}`,
msg: {
error: '命令下发失败'
},
reducer: {
name: 'invokeCapability'
}
});
}
export default { export default {
getOrganizationsStruc, getOrganizationsStruc,
@ -166,6 +182,7 @@ export default {
findDevicesCardStatus, findDevicesCardStatus,
getDevicesLlinkStatus, getDevicesLlinkStatus,
findAlarmsDevice, findAlarmsDevice,
getThingStatus getThingStatus,
invokeCapability
} }

107
web-network/client/src/sections/network/containers/tableShow.js

@ -1,11 +1,11 @@
import React, { useEffect, useState, useRef, useMemo } from 'react' import React, { useEffect, useState, useRef, useMemo } from 'react'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { Spin, Card, CardGroup, Form, Select, Input, Button, Table, Pagination, Tooltip,Modal } from 'antd' import { Spin, Card, CardGroup, Form, Select, Input, Button, Table, Pagination, Tooltip,Modal,Switch } from 'antd'
import ExportData from '../components/export-data' import ExportData from '../components/export-data'
import moment from 'moment' import moment from 'moment'
const Network = props => { const Network = props => {
const { dispatch, actions, user, clientHeight, thingId, deviceListAlarms, devicesCardStatusList, project, token, } = props const { dispatch, actions, user, clientHeight, thingId, deviceListAlarms, devicesCardStatusList, project, token,thingStatus } = props
const { analysis } = actions const { analysis } = actions
const form = useRef() //表单 const form = useRef() //表单
const [deployData, setDeployData] = useState([]) const [deployData, setDeployData] = useState([])
@ -19,10 +19,13 @@ const Network = props => {
const [searchType, setSearchType] = useState('') const [searchType, setSearchType] = useState('')
const [searchName, setSearchName] = useState('') const [searchName, setSearchName] = useState('')
const [typeList, setTypeList] = useState([]) const [typeList, setTypeList] = useState([])
const [query, setQuery] = useState({ limit: 10, page: 0 }) //页码信息
const [deviceId,setDeviceId] = useState([]) const [deviceId,setDeviceId] = useState([])
const [modalVis,setModalVis]=useState(false) const [modalVis,setModalVis]=useState(false)
const [loading,setLoading]=useState(true) const [loading,setLoading]=useState(true)
const [status,setStatus]=useState(false)//空开设备开关状态
const [controlId,setControlId]=useState('')
const [id,setId]=useState('')//设计设备的id
const [param,setParam]=useState('')//开与关
const DeviceTypes = { const DeviceTypes = {
'DTU': 'DTU', 'DTU': 'DTU',
'gateway': '网关', 'gateway': '网关',
@ -72,16 +75,35 @@ const Network = props => {
if (deviceMetaDeployed && dataList && deviceMetaDeployed.devices) { if (deviceMetaDeployed && dataList && deviceMetaDeployed.devices) {
const sensorsId = [] const sensorsId = []
let deviceIds = [] //所有设备的id let deviceIds = [] //所有设备的id
const sensorsDataItems = {} const sensorsDataItems = {}
for (const id in dataList.instances) { for (const id in dataList.instances) {
let searchId=''//查询e9c设备状态的id
let controlId=''//控制e9c设备开关的id
deviceIds.push(id) deviceIds.push(id)
const instances = dataList.instances[id] const instances = dataList.instances[id]
if (instances.type == 's.d' && instances.instance.properties.deviceType == 'sensor') { if (instances.type == 's.d' && instances.instance.properties.deviceType == 'sensor') {
if(instances.instance.properties.model == 'E9C'){
for(const key in instances?.instance?.interfaces){
Object.keys(instances?.instance?.interfaces[key]?.capabilities).forEach(
(kk,index)=>{
if(index===0){
searchId=instances?.instance?.interfaces[key]?.capabilities[kk]?.dimension?.id
}
if(index===1){
controlId=instances?.instance?.interfaces[key]?.capabilities[kk]?.dimension?.id
}
}
)
}
}
const meta = deviceMetaDeployed.devices.find(m => m.id == instances.instance.deviceMetaId) const meta = deviceMetaDeployed.devices.find(m => m.id == instances.instance.deviceMetaId)
sensorsDataItems[id] = { sensorsDataItems[id] = {
items: {}, items: {},
deviceName: instances.name, deviceName: instances.name,
model:instances.instance.properties.productType model:instances.instance.properties.productType,
searchId:instances.instance.properties.model == 'E9C'?searchId:null,
controlId:instances.instance.properties.model == 'E9C'?controlId:null,
} }
if (meta) { if (meta) {
sensorsDataItems[id].items = meta.capabilities[0].properties.reduce((p, n) => { sensorsDataItems[id].items = meta.capabilities[0].properties.reduce((p, n) => {
@ -140,6 +162,8 @@ const Network = props => {
sensorName: sensorName, sensorName: sensorName,
collectTime: collectTime, collectTime: collectTime,
model:sensorsDataItems[sd.sensorId]?.model, model:sensorsDataItems[sd.sensorId]?.model,
searchId:sensorsDataItems[sd.sensorId]?.searchId,
controlId:sensorsDataItems[sd.sensorId]?.controlId,
data: dataStr, data: dataStr,
deviceType: 'sensor', //传感器 deviceType: 'sensor', //传感器
iotCardStatus: '--', iotCardStatus: '--',
@ -167,6 +191,8 @@ const Network = props => {
data: objRslt ? objRslt.data : p.data, data: objRslt ? objRslt.data : p.data,
deviceType: DeviceTypes[objRslt ? objRslt.deviceType : p.deviceType], deviceType: DeviceTypes[objRslt ? objRslt.deviceType : p.deviceType],
model:objRslt?objRslt?.model:p.model, model:objRslt?objRslt?.model:p.model,
searchId:objRslt?objRslt.searchId:'',
controlId:objRslt?objRslt.controlId:'',
iotCardStatus: iotCardStatus:
res.payload.data && res.payload.data.length&&res.payload.data.find(v => v.deviceId == p.sensorId)?.status === 0 res.payload.data && res.payload.data.length&&res.payload.data.find(v => v.deviceId == p.sensorId)?.status === 0
? '正常' ? '正常'
@ -174,11 +200,9 @@ const Network = props => {
? '未激活':res.payload.data.find(v => v.deviceId == p.sensorId)?.status === 2?'停机' ? '未激活':res.payload.data.find(v => v.deviceId == p.sensorId)?.status === 2?'停机'
: '--', : '--',
status: status:
deviceListAlarms && deviceListAlarms.length thingStatus && thingStatus.length
? deviceListAlarms?.find(v => v.deviceId == p.sensorId) ? thingStatus?.find(v => v.deviceId == p.sensorId)?.status===1?'在线':thingStatus?.find(v => v.deviceId == p.sensorId)?.status===0?'离线':'未知':'--',
? '异常'
: '正常'
: '--',
option: objRslt ? objRslt.option : p.option, option: objRslt ? objRslt.option : p.option,
} }
}) })
@ -225,7 +249,26 @@ const Network = props => {
) )
) )
} }
const searchStatusHandler=async (record)=>{
setControlId(record.controlId)
setId(record.sensorId)
setModalVis(true)
let dimensionId = null
let dtuId = null
const values = {
thingId,
deviceId: record.sensorId,
dimensionId,
dimCapId:record.searchId,
timeout: 60000 * 5,
// param,
// userId: user.id,
dtuId,
};
const res= await dispatch(analysis.invokeCapability(values,token))
setStatus(res?.payload?.data?.data?.info?.includes('离线')?false:true)
}
const columns = [ const columns = [
{ {
title: '设备名称', title: '设备名称',
@ -289,11 +332,36 @@ const Network = props => {
render: (_, r) => { render: (_, r) => {
return ( return (
//E9C,FS-WSD-01M //E9C,FS-WSD-01M
<div> {r.model==='E9C'?<Button onClick={()=>{setModalVis(true)}}>查询</Button>: '--'}</div> <div> {r.model==='E9C'?<Button onClick={()=>{searchStatusHandler(r)}}>查询</Button>: '--'}</div>
) )
} }
}, },
] ]
const switchChange=(e)=>{
if(e){
setParam('开')
}else{
setParam('关')
}
}
//升级按钮
const okHandler=()=>{
let dimensionId = null
let dtuId = null
const values = {
thingId,
deviceId: id,
dimensionId,
dimCapId:controlId,
timeout: 60000 * 5,
param,
// userId: user.id,
dtuId,
};
dispatch(analysis.invokeCapability(values,token))
}
return ( return (
<> <>
<Spin spinning={loading}> <Spin spinning={loading}>
@ -339,21 +407,34 @@ const Network = props => {
<Modal <Modal
title='开关' title='开关'
visible={modalVis} visible={modalVis}
></Modal> onCancel={()=>{setModalVis(false)}}
// sensorId={sensorId}
onOk={okHandler}
okText='升级'
>
<Form>
<Form.Item label='状态' name='status'>
<Input disabled/>
</Form.Item>
<Form.Item label='开关' name='open'>
<Switch disabled={status} onChange={switchChange}></Switch>
</Form.Item>
</Form>
</Modal>
</Spin> </Spin>
</> </>
) )
} }
function mapStateToProps (state) { function mapStateToProps (state) {
const { auth, global, members, webSocket, deviceListAlarms, devicesCardStatus } = state const { auth, global, members, webSocket, deviceListAlarms, devicesCardStatus,thingStatus } = state
return { return {
user: auth.user, user: auth.user,
actions: global.actions, actions: global.actions,
clientHeight: global.clientHeight, clientHeight: global.clientHeight,
deviceListAlarms: deviceListAlarms?.data || [], deviceListAlarms: deviceListAlarms?.data || [],
devicesCardStatusList: devicesCardStatus?.data || [], devicesCardStatusList: devicesCardStatus?.data || [],
thingStatus:thingStatus?.data||[]
} }
} }

2
web-network/client/src/utils/webapi.js

@ -17,7 +17,7 @@ export const ApiTable = {
findDevicesCardStatus: 'devices/cardStatus',//查询物联网卡状态 findDevicesCardStatus: 'devices/cardStatus',//查询物联网卡状态
getDevicesLlinkStatus: 'metrics/devices/{deviceId}/link_status', //设备在线状态获取 getDevicesLlinkStatus: 'metrics/devices/{deviceId}/link_status', //设备在线状态获取
getDeviceAlarms: 'device/{deviceId}/alarms', //获取设备告警信息 getDeviceAlarms: 'device/{deviceId}/alarms', //获取设备告警信息
invokeCapability:'capabilities/invoke',//查询设备状态以及控制设备开关

Loading…
Cancel
Save