【功能优化】Bpm:设备属性上报

This commit is contained in:
YunaiV 2025-01-28 04:55:48 +08:00
parent 3dc7d20005
commit 3d65f1c599
3 changed files with 61 additions and 57 deletions

View File

@ -63,15 +63,12 @@ export enum DeviceStatusEnum {
DISABLED = 3 // 已禁用
}
// IoT 模拟设备数据
// TODO @superDeviceSimulatorDataReqVO
export interface SimulatorDataVO {
productKey: string
deviceKey: string
type: string
subType: string
reportTime: number // 时间戳
content: string // 存储 JSON 字符串
// IoT 模拟设备上报数据 Request VO
export interface IotDeviceSimulationReportReqVO {
id: number // 设备编号
type: string // 消息类型
identifier: string // 标识符
data: object // 请求参数
}
// 设备 API
@ -146,11 +143,12 @@ export const DeviceApi = {
return await request.download({ url: `/iot/device/get-import-template` })
},
// 模拟设备
simulatorDevice: async (data: SimulatorDataVO) => {
// 模拟设备上报
simulationReportDevice: async (data: IotDeviceSimulationReportReqVO) => {
// TODO @super/iot/device/simulator
return await request.post({ url: `/iot/device/data/simulator`, data })
return await request.post({ url: `/iot/device/simulation-report`, data })
},
// 查询设备日志分页
getDeviceLogPage: async (params: any) => {
// TODO @super/iot/log-page 或者 /iot/log/page

View File

@ -52,7 +52,7 @@ import { DeviceApi } from '@/api/iot/device/device'
import { formatDate } from '@/utils/formatTime'
const props = defineProps<{
deviceKey: number
deviceKey: string
}>()
//TODO:使 type subType

View File

@ -1,6 +1,5 @@
<template>
<ContentWrap>
<!-- TODO @super建议每个 tab 做成一个小的组件命名为了排版整齐点可以叫 DeviceDetailsSimulatorPropertyUpstreamDeviceDetailsSimulatorEventUpstream -->
<el-row :gutter="20">
<!-- 左侧指令调试区域 -->
<el-col :span="12">
@ -17,6 +16,7 @@
:show-overflow-tooltip="true"
:stripe="true"
>
<!-- TODO @super每个 colum 搞下宽度避免 table 每一列最后有个 . -->
<el-table-column align="center" label="功能名称" prop="name" />
<el-table-column align="center" label="标识符" prop="identifier" />
<el-table-column align="center" label="数据类型" prop="identifier">
@ -38,9 +38,8 @@
].includes(row.property.dataType)
"
>
取值范围{{
`${row.property.dataSpecs.min}~${row.property.dataSpecs.max}`
}}
取值范围
{{ `${row.property.dataSpecs.min}~${row.property.dataSpecs.max}` }}
</div>
<!-- 非列表型文本 -->
<div v-if="DataSpecsDataType.TEXT === row.property.dataType">
@ -95,12 +94,19 @@
</el-table-column>
</el-table>
<div class="mt-10px">
<el-button type="primary" @click="handlePropertyReport">发送</el-button>
<el-button
type="primary"
@click="handlePropertyReport"
v-hasPermi="['iot:device:simulation-report']"
>
发送
</el-button>
</div>
</ContentWrap>
</el-tab-pane>
<!-- 事件上报 -->
<!-- TODO @super待实现 -->
<el-tab-pane label="事件上报" name="event">
<ContentWrap>
<!-- <el-table v-loading="loading" :data="eventList" :stripe="true">
@ -129,12 +135,12 @@
<el-tab-pane label="状态变更" name="status">
<ContentWrap>
<div class="flex gap-4">
<el-button type="primary" @click="handleDeviceState('online')"
>设备上线</el-button
>
<el-button type="primary" @click="handleDeviceState('offline')"
>设备下线</el-button
>
<el-button type="primary" @click="handleDeviceState('online')">
设备上线
</el-button>
<el-button type="primary" @click="handleDeviceState('offline')">
设备下线
</el-button>
</div>
</ContentWrap>
</el-tab-pane>
@ -142,6 +148,7 @@
</el-tab-pane>
<!-- 下行指令调试 -->
<!-- TODO @super待实现 -->
<el-tab-pane label="下行指令调试" name="down">
<el-tabs v-model="subTab" v-if="activeTab === 'down'">
<!-- 属性调试 -->
@ -170,6 +177,7 @@
</el-tab-pane>
<!-- 服务调用 -->
<!-- TODO @super待实现 -->
<el-tab-pane label="服务调用" name="service">
<ContentWrap>
<!-- 服务调用相关内容 -->
@ -184,7 +192,7 @@
<el-col :span="12">
<el-tabs type="border-card">
<el-tab-pane label="设备日志">
<DeviceDetailsLog :deviceKey="device.deviceKey" />
<DeviceDetailsLog :device-key="device.deviceKey" />
</el-tab-pane>
</el-tabs>
</el-col>
@ -195,7 +203,7 @@
<script setup lang="ts">
import { ProductVO } from '@/api/iot/product/product'
import { ThingModelApi, SimulatorData } from '@/api/iot/thingmodel'
import { DeviceApi, DeviceVO, SimulatorDataVO } from '@/api/iot/device/device'
import { DeviceApi, DeviceVO } from '@/api/iot/device/device'
import DeviceDetailsLog from './DeviceDetailsLog.vue'
import {
DataSpecsDataType,
@ -205,26 +213,33 @@ import {
ThingModelType
} from '@/views/iot/thingmodel/config'
const message = useMessage() //
const loading = ref(false)
const activeTab = ref('up')
const subTab = ref('property')
const props = defineProps<{
product: ProductVO
device: DeviceVO
}>()
const message = useMessage() //
const activeTab = ref('up') // TODO @superupstream downstream
const subTab = ref('property') // TODO @superupstreamTab
const loading = ref(false)
const queryParams = reactive({
type: undefined,
type: undefined, // TODO @supertype tab watch
productId: -1
})
const list = ref<SimulatorData[]>([]) // TODO @superthingModelList
// TODO @superdataTypeOptionsLabel getDataTypeOptionsLabel template 使
const dataTypeOptionsLabel = computed(() => (value: string) => getDataTypeOptionsLabel(value)) //
const props = defineProps<{ product: ProductVO; device: DeviceVO }>()
const list = ref<SimulatorData[]>([]) //
/** 查询列表 */
/** 查询物模型列表 */
// TODO @supergetThingModelList
const getList = async () => {
loading.value = true
try {
queryParams.productId = props.product?.id || -1
const data = await ThingModelApi.getThingModelList(queryParams)
// simulateValue
// TODO @super simulateValue
list.value = data.map((item) => ({
...item,
simulateValue: ''
@ -262,7 +277,8 @@ const getList = async () => {
// }))
// })
// todo:
/** 监听标签页变化 */
// todo:
watch(
[activeTab, subTab],
([newActiveTab, newSubTab]) => {
@ -294,36 +310,26 @@ watch(
{ immediate: true }
)
// interface ReportData {
// productKey: string
// deviceKey: string
// type: string
// subType: string
// reportTime: string
// content: string // string JSON
// }
// TODO:
/** 处理属性上报 */
const handlePropertyReport = async () => {
const contentObj: Record<string, any> = {}
// TODO @super:
const data: Record<string, object> = {}
list.value.forEach((item) => {
// simulateValue content
// TODO @super if (item.simulateValue) js
if (item.simulateValue !== undefined && item.simulateValue !== '') {
contentObj[item.identifier] = item.simulateValue
// TODO @super idea
data[item.identifier] = item.simulateValue
}
})
const reportData: SimulatorDataVO = {
productKey: props.product.productKey,
deviceKey: props.device.deviceKey,
type: 'property',
subType: 'report',
reportTime: Date.now(), // reportTime
content: JSON.stringify(contentObj) // JSON
}
try {
await DeviceApi.simulatorDevice(reportData)
await DeviceApi.simulationReportDevice({
id: props.device.id,
type: 'property',
identifier: 'report',
data: data
})
message.success('属性上报成功')
} catch (error) {
message.error('属性上报失败')