浏览代码

feat: device下的ota

lvkun996 2 年之前
父节点
当前提交
36ede6a94e

+ 28 - 0
src/api/iot/device.ts

@@ -290,3 +290,31 @@ export const getDeviceAttributes = (params: {deviceId: string, start: number, en
     params
   })
 }
+
+/** ota  */
+export const getOtaByDeviceId = (deviceId: string) => {
+  return request<IOT.API.DEVICE.Ota>({
+    url: `/deviceOta/${deviceId}`,
+    method: 'GET'
+  })
+}
+
+export const getOtaPageByDeviceId = (params: IOT.API.DEVICE.OtaQueryParams) => {
+  return request<IOT.API.DEVICE.Ota[]>({
+    url: '/deviceOta/page',
+    method: 'GET',
+    params
+  })
+}
+
+/** 根据设备id, ota包id来升级设备 */
+export const upgradationOtaByDeviceId = (deviceId: string, otaPkgId: string) => {
+  return request<string>({
+    url: '/deviceOta',
+    method: 'POST',
+    data: {
+      deviceId,
+      otaPkgId
+    }
+  })
+}

+ 1 - 0
src/controller/index.ts

@@ -7,5 +7,6 @@ export { EventController } from './iot/event'
 export { DeviceContriller } from './iot/device'
 export { RuleController } from './iot/rule'
 export { SysController } from './iot/sys'
+export { OtaController } from './iot/ota'
 
 export { UserController } from './user/index'

+ 33 - 2
src/controller/iot/device.ts

@@ -2,9 +2,9 @@ import {
   addDevice, addSubDevice, delDevice, delDeviceMul, delDeviceTag,
   getDeviceById, getDeviceCount, getDeviceList, getDeviceMsgList, addDeviceMsg, getDeviceTag,
   getSubDeviceList, updateDeviceLabel, addDeviceCmd, getDeviceCmdList, addDeviceTag, addDeviceGroup,
-  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology, getDeviceSession, getDeviceAttributes, getDeviceSecret
+  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology, getDeviceSession, getDeviceAttributes, getDeviceSecret, getOtaByDeviceId, getOtaPageByDeviceId, upgradationOtaByDeviceId
 } from '@/api/iot/device'
-import { DeviceMsgEnum } from '@/enum/common'
+import { DeviceMsgEnum, OtaStatusEnum } from '@/enum/common'
 import { message } from 'ant-design-vue'
 import dayjs from 'dayjs'
 
@@ -45,6 +45,24 @@ export class DeviceContriller {
     { name: '设备名称', key: 'deviceLabel' }
   ]
 
+  static otaStatusMap = new Map([
+    [OtaStatusEnum.QUEUED, { key: OtaStatusEnum.QUEUED, label: '在消息队列中' }],
+    [OtaStatusEnum.SENT, { key: OtaStatusEnum.SENT, label: '已经发送' }],
+    [OtaStatusEnum.DELIVERED, { key: OtaStatusEnum.DELIVERED, label: '设备已收到' }],
+    [OtaStatusEnum.SUCCESSFUL, { key: OtaStatusEnum.SUCCESSFUL, label: '成功' }],
+    [OtaStatusEnum.TIMEOUT, { key: OtaStatusEnum.TIMEOUT, label: '超时' }],
+    [OtaStatusEnum.FAILED, { key: OtaStatusEnum.FAILED, label: '失败' }]
+  ])
+
+  static otaStatusList = [
+    { key: OtaStatusEnum.QUEUED, label: '在消息队列中' },
+    { key: OtaStatusEnum.SENT, label: '已经发送' },
+    { key: OtaStatusEnum.DELIVERED, label: '设备已收到' },
+    { key: OtaStatusEnum.SUCCESSFUL, label: '成功' },
+    { key: OtaStatusEnum.TIMEOUT, label: '超时' },
+    { key: OtaStatusEnum.FAILED, label: '失败' }
+  ]
+
   static async page (params: IOT.API.DEVICE.QueryPamars) {
     const { data: _data, sum } = await getDevicePage(params)
     const data = _data.map(item => {
@@ -235,4 +253,17 @@ export class DeviceContriller {
   static async getAttr (params: {deviceId: string, start: number, end: number}) {
     return await getDeviceAttributes(params)
   }
+
+  static async OtaByDeviceId (deviceId: string) {
+    return await getOtaByDeviceId(deviceId)
+  }
+
+  static async OtaPageByDeviceId (params: IOT.API.DEVICE.OtaQueryParams) {
+    return await getOtaPageByDeviceId(params)
+  }
+
+  static async upgradationOtaByDeviceId ({ deviceId, otaPkgId }: {deviceId: string, otaPkgId: string}) {
+    await upgradationOtaByDeviceId(deviceId, otaPkgId)
+    message.success('升级设备成功')
+  }
 }

+ 9 - 0
src/enum/common.ts

@@ -57,3 +57,12 @@ export enum PkgTypeEnum {
   'FILE_URL' = 'FILE_URL',
   'FILE_ZIP' = 'FILE_ZIP'
 }
+
+export enum OtaStatusEnum {
+  'QUEUED' = 'QUEUED',
+  'SENT' = 'SENT',
+  'DELIVERED' = 'DELIVERED',
+  'SUCCESSFUL' = 'SUCCESSFUL',
+  'TIMEOUT' = 'TIMEOUT',
+  'FAILED' = 'FAILED',
+}

+ 9 - 0
src/pages/Iot/device/components/ota.vue

@@ -0,0 +1,9 @@
+<template>
+  <a-card>ota</a-card>
+</template>
+
+<script setup lang="ts" >
+</script>
+
+<style lang="less" >
+</style>

+ 6 - 0
src/pages/Iot/device/detail.vue

@@ -13,6 +13,7 @@
     <MsgTrack v-else-if="state.tabsActive === '4'" />
     <SubDevice @goDetail="goDetail" v-else-if="state.tabsActive === '5'" />
     <DeviceTag @goDetail="goDetail" v-else-if="state.tabsActive === '6'" />
+    <Ota v-else-if="state.tabsActive === '7'" />
   </a-card>
 </template>
 
@@ -24,6 +25,7 @@ import DeviceShadow from './components/deviceShadow.vue'
 import MsgTrack from './components/msgTrack.vue'
 import SubDevice from './components/subDevice.vue'
 import DeviceTag from './components/deviceTag.vue'
+import Ota from './components/ota.vue'
 import { useRoute } from 'vue-router'
 import { DeviceContriller } from '@/controller'
 import { StateEffect } from '@codemirror/state'
@@ -52,6 +54,10 @@ const tabs = [
   {
     name: '标签',
     key: '6'
+  },
+  {
+    name: 'OTA',
+    key: '7'
   }
 ]
 

+ 19 - 0
src/type/iot.d.ts

@@ -246,6 +246,25 @@ declare namespace IOT {
         }[]
         [key: string]: any
       }
+
+      interface Ota {
+        'deviceId': string,
+        'otaTime': 0, // 设备当前ota 升级名称,如果是0 说明从未升级过,有值的情况是 毫秒数字
+        'msgId': null,
+        'status': null, // QUEUED,SENT,DELIVERED,SUCCESSFUL,TIMEOUT,FAILED
+        'otaPkgId': null, // ota包id
+        'otaPkgLabel': string, // 设备当前ota 名称,如果是-- 说明从未升级过
+        'otaPkgVersion': string // 设备当前ota 版本,如果是-- 说明从未升级过
+      }
+
+      interface OtaQueryParams {
+        page: number
+        pageSize: number
+        deviceId: string
+        otaLabel: string
+        otaVersion: string
+        otaStatus: 'QUEUED' | 'SENT' | 'DELIVERED' | 'SUCCESSFUL' | 'TIMEOUT' | 'FAILED'
+      }
     }
 
     namespace EVENT {