【代码评审】IoT:设备日志 TDengine 表与模拟设备

This commit is contained in:
YunaiV 2025-01-09 12:54:16 +08:00
parent f2f414a965
commit 3dc7d20005
5 changed files with 39 additions and 23 deletions

View File

@ -58,19 +58,20 @@ export interface DeviceHistoryDataVO {
// IoT 设备状态枚举
export enum DeviceStatusEnum {
INACTIVE = 0, // 未激活
ONLINE = 1, // 在线
OFFLINE = 2, // 离线
DISABLED = 3 // 已禁用
ONLINE = 1, // 在线
OFFLINE = 2, // 离线
DISABLED = 3 // 已禁用
}
// IoT 模拟设备数据
// TODO @superDeviceSimulatorDataReqVO
export interface SimulatorDataVO {
productKey: string
deviceKey: string
type: string
subType: string
reportTime: number // 时间戳
content: string // 存储 JSON 字符串
content: string // 存储 JSON 字符串
}
// 设备 API
@ -101,10 +102,7 @@ export const DeviceApi = {
},
// 修改设备分组
updateDeviceGroup: async (data: {
ids: number[]
groupIds: number[]
}) => {
updateDeviceGroup: async (data: { ids: number[]; groupIds: number[] }) => {
return await request.put({ url: `/iot/device/update-group`, data })
},
@ -150,10 +148,12 @@ export const DeviceApi = {
// 模拟设备
simulatorDevice: async (data: SimulatorDataVO) => {
// TODO @super/iot/device/simulator
return await request.post({ url: `/iot/device/data/simulator`, data })
},
//查询设备日志分页
// 查询设备日志分页
getDeviceLogPage: async (params: any) => {
// TODO @super/iot/log-page 或者 /iot/log/page
return await request.get({ url: `/iot/device/data/log/page`, params })
}
}

View File

@ -20,8 +20,9 @@ export interface ThingModelData {
/**
* IoT
*/
// TODO @super和 ThingModelSimulatorData 会不会好点
export interface SimulatorData extends ThingModelData {
simulateValue?: string | number // 用于存储模拟值
simulateValue?: string | number // 用于存储模拟值 TODO @super字段使用 value 会不会好点
}
/**

View File

@ -5,6 +5,7 @@
<el-form-item>
<el-select v-model="queryParams.type" placeholder="所有" class="!w-120px">
<el-option label="所有" value="" />
<!-- TODO @super搞成枚举 -->
<el-option label="状态" value="state" />
<el-option label="事件" value="event" />
<el-option label="属性" value="property" />
@ -48,7 +49,6 @@
<script setup lang="ts">
import { DeviceApi } from '@/api/iot/device/device'
import { DICT_TYPE } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
const props = defineProps<{
@ -68,11 +68,12 @@ const queryParams = reactive({
//
const loading = ref(false)
const total = ref(0)
// TODO @super table
const logList = ref([])
const autoRefresh = ref(false)
let timer: any = null
let timer: any = null // TODO @superautoRefreshEnableautoRefreshTimer
//
// TODO @super
const typeMap = {
lifetime: '生命周期',
state: '设备状态',
@ -88,6 +89,7 @@ const getLogList = async () => {
try {
const res = await DeviceApi.getDeviceLogPage(queryParams)
total.value = res.total
// TODO @super
logList.value = res.list.map((item: any) => {
const log = {
time: item.reportTime,
@ -138,7 +140,7 @@ watch(autoRefresh, (newValue) => {
}
})
/** 监听设备ID变化 */
/** 监听设备 ID 变化 */
watch(
() => props.deviceKey,
(newValue) => {

View File

@ -1,5 +1,6 @@
<template>
<ContentWrap>
<!-- TODO @super建议每个 tab 做成一个小的组件命名为了排版整齐点可以叫 DeviceDetailsSimulatorPropertyUpstreamDeviceDetailsSimulatorEventUpstream -->
<el-row :gutter="20">
<!-- 左侧指令调试区域 -->
<el-col :span="12">
@ -10,7 +11,12 @@
<!-- 属性上报 -->
<el-tab-pane label="属性上报" name="property">
<ContentWrap>
<el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
<el-table
v-loading="loading"
:data="list"
:show-overflow-tooltip="true"
:stripe="true"
>
<el-table-column align="center" label="功能名称" prop="name" />
<el-table-column align="center" label="标识符" prop="identifier" />
<el-table-column align="center" label="数据类型" prop="identifier">
@ -188,8 +194,8 @@
<script setup lang="ts">
import { ProductVO } from '@/api/iot/product/product'
import { ThingModelApi, ThingModelData,SimulatorData } from '@/api/iot/thingmodel'
import { DeviceApi, DeviceVO,SimulatorDataVO } from '@/api/iot/device/device'
import { ThingModelApi, SimulatorData } from '@/api/iot/thingmodel'
import { DeviceApi, DeviceVO, SimulatorDataVO } from '@/api/iot/device/device'
import DeviceDetailsLog from './DeviceDetailsLog.vue'
import {
DataSpecsDataType,
@ -219,7 +225,7 @@ const getList = async () => {
queryParams.productId = props.product?.id || -1
const data = await ThingModelApi.getThingModelList(queryParams)
// simulateValue
list.value = data.map(item => ({
list.value = data.map((item) => ({
...item,
simulateValue: ''
}))
@ -313,7 +319,7 @@ const handlePropertyReport = async () => {
type: 'property',
subType: 'report',
reportTime: Date.now(), // reportTime
content: JSON.stringify(contentObj) // JSON
content: JSON.stringify(contentObj) // JSON
}
try {
@ -384,4 +390,5 @@ const handlePropertyGet = async () => {
onMounted(() => {
getList()
})
// TODO @ review
</script>

View File

@ -17,11 +17,16 @@
<el-tab-pane label="子设备管理" v-if="product.deviceType === DeviceTypeEnum.GATEWAY" />
<el-tab-pane label="设备影子" />
<el-tab-pane label="设备日志" name="log">
<DeviceDetailsLog v-if="activeTab === 'log'" :deviceKey="device.deviceKey" />
<!-- TODO @super字段类型:device-keyidea 会告警应该是 string -->
<DeviceDetailsLog v-if="activeTab === 'log'" :device-key="device.deviceKey" />
</el-tab-pane>
<el-tab-pane label="模拟设备" name="simulator">
<DeviceDetailsSimulator v-if="activeTab === 'simulator'" :product="product" :device="device" />
</el-tab-pane>
<DeviceDetailsSimulator
v-if="activeTab === 'simulator'"
:product="product"
:device="device"
/>
</el-tab-pane>
</el-tabs>
</el-col>
</template>
@ -34,6 +39,7 @@ import DeviceDetailsInfo from './DeviceDetailsInfo.vue'
import DeviceDetailsModel from './DeviceDetailsModel.vue'
import DeviceDetailsLog from './DeviceDetailsLog.vue'
import DeviceDetailsSimulator from './DeviceDetailsSimulator.vue'
defineOptions({ name: 'IoTDeviceDetail' })
const route = useRoute()