Browse Source

feat: 数据服务

lvkun 3 năm trước cách đây
mục cha
commit
161c9ecee5

+ 10 - 2
src/App.vue

@@ -1,7 +1,15 @@
 <template>
-  <router-view/>
-</template>
 
+    <a-config-provider :locale="zhCN">
+      <router-view/>
+    </a-config-provider>
+</template>
+<script setup lang="ts" >
+import zhCN from 'ant-design-vue/es/locale/zh_CN'
+import dayjs from 'dayjs'
+import 'dayjs/locale/zh-cn'
+dayjs.locale('zh-cn')
+</script>
 <style lang="less">
 @import '~@/styles/theme.less';
 </style>

+ 18 - 0
src/api/iot/data.ts

@@ -0,0 +1,18 @@
+
+import request from '@/service/request'
+
+export const getHistoryDataPage = (params: IOT.API.DATA.QueryParams) => {
+  return request<IOT.API.DATA.History[]>({
+    url: '/deviceAttribute/history',
+    method: 'GET',
+    params
+  })
+}
+
+export const getDataApiPage = (params: {page: number, pageSize: number, apiLabel: string}) => {
+  return request<IOT.API.DATA.OpenApi[]>({
+    url: '/dataApi/page',
+    method: 'GET',
+    params
+  })
+}

+ 9 - 1
src/api/iot/device.ts

@@ -7,7 +7,7 @@ import request from '@/service/request'
  * @returns `getDevice` 函数返回一个解析为 `IOT.API.DEVICE.Device` 对象数组的 Promise。 Promise
  * 由“request”函数返回,该函数使用指定的查询参数(“params”)向“/model/page”端点发出 GET 请求。
  */
-export const getDeviceList = (params: IOT.API.DEVICE.QueryPamars) => {
+export const getDevicePage = (params: IOT.API.DEVICE.QueryPamars) => {
   return request<IOT.API.DEVICE.Device[]>({
     url: '/device/page',
     method: 'GET',
@@ -15,6 +15,14 @@ export const getDeviceList = (params: IOT.API.DEVICE.QueryPamars) => {
   })
 }
 
+export const getDeviceList = (params: {modelId: string, deviceLabel: string, limit: number, lastId: string }) => {
+  return request<IOT.API.DEVICE.Device[]>({
+    url: '/device/list',
+    method: 'GET',
+    params
+  })
+}
+
 export const getDeviceById = (id: string) => {
   return request<IOT.API.DEVICE.Device>({
     url: `/device/${id}`,

+ 11 - 0
src/controller/iot/data.ts

@@ -0,0 +1,11 @@
+import { getDataApiPage, getHistoryDataPage } from '@/api/iot/data'
+
+export class DataController {
+  static async pageHistory (params: IOT.API.DATA.QueryParams) {
+    return await getHistoryDataPage(params)
+  }
+
+  static async pageOpenAPiList (params: {page: number, pageSize: number, apiLabel: string}) {
+    return await getDataApiPage(params)
+  }
+}

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

@@ -2,7 +2,7 @@ import {
   addDevice, addSubDevice, delDevice, delDeviceMul, delDeviceTag,
   getDeviceById, getDeviceCount, getDeviceList, getDeviceMsgList, addDeviceMsg, getDeviceTag,
   getSubDeviceList, updateDeviceLabel, addDeviceCmd, getDeviceCmdList, addDeviceTag, addDeviceGroup,
-  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup
+  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage
 } from '@/api/iot/device'
 import { DeviceMsgEnum } from '@/enum/common'
 import { message } from 'ant-design-vue'
@@ -45,7 +45,7 @@ export class DeviceContriller {
   ]
 
   static async page (params: IOT.API.DEVICE.QueryPamars) {
-    const { data: _data, sum } = await getDeviceList(params)
+    const { data: _data, sum } = await getDevicePage(params)
     const data = _data.map(item => {
       return {
         ...item,
@@ -58,6 +58,15 @@ export class DeviceContriller {
     }
   }
 
+  static async list (params: {modelId: string, deviceLabel: string, limit: number, lastId: string } = {
+    modelId: '',
+    deviceLabel: '',
+    limit: 10000,
+    lastId: ''
+  }) {
+    return await getDeviceList(params)
+  }
+
   static async post (data: IOT.API.DEVICE.BodyParams) {
     await addDevice(data)
     message.success('新增成功')

+ 157 - 0
src/pages/Iot/dataServer/history.vue

@@ -0,0 +1,157 @@
+<template>
+<a-card>
+  <a-row>
+    <a-col>
+      <a-space>
+        <a-select v-model:value="queryParams.modelId" style="width: 170px;" >
+          <a-select-option
+            v-for="item in state.modelList"
+            :key="item.id"
+            :value="item.id"
+          >
+            {{item.modelLabel}}
+          </a-select-option>
+        </a-select>
+        <a-select v-model:value="queryParams.deviceId" style="width: 170px;" >
+          <a-select-option
+            v-for="item in state.deviceList"
+            :key="item.id"
+            :value="item.id"
+          >
+            {{item.deviceLabel}}
+          </a-select-option>
+        </a-select>
+        <a-range-picker v-model:value="time" :format="['DD/MM/YYYY', 'DD/MM/YYYY']"  />
+      </a-space>
+
+    </a-col>
+  </a-row>
+  <a-table
+    style="margin-top: 20px;"
+    :columns="columns"
+    :loading="state.loading"
+    :data-source="state.dataSource"
+  >
+
+  </a-table>
+</a-card>
+</template>
+<script lang='ts' setup name="aaa" >
+import { DeviceContriller, ModelController } from '@/controller'
+import { DataController } from '@/controller/iot/data'
+import { onMounted, reactive, ref, watch } from 'vue'
+import dayjs from 'dayjs'
+
+const columns = [
+  {
+    title: '设备ID',
+    dataIndex: 'deviceId'
+  },
+  {
+    title: 'key',
+    dataIndex: 'key'
+  },
+  {
+    title: 'keyLabel',
+    dataIndex: 'keyLabel'
+  },
+  {
+    title: 'stringValue',
+    dataIndex: 'stringValue'
+  },
+  {
+    title: 'doubleValue',
+    dataIndex: 'doubleValue'
+  },
+  {
+    title: 'longValue',
+    dataIndex: 'longValue'
+  },
+  {
+    title: 'booleanValue',
+    dataIndex: 'booleanValue'
+  },
+  {
+    title: 'jsonValue',
+    dataIndex: 'jsonValue'
+  },
+  {
+    title: 'dataUnit',
+    dataIndex: 'dataUnit'
+  }
+]
+
+const time = ref([])
+
+const queryParams = reactive({
+  page: 1,
+  pageSize: 10,
+  total: 0,
+  deviceId: '',
+  modelId: '',
+  attributeKey: '',
+  startTime: '',
+  endTime: ''
+})
+
+const state = reactive<{
+  loading: boolean,
+  dataSource: IOT.API.DATA.History[],
+  modelList: IOT.API.MODEL.Model[]
+  deviceList: IOT.API.DEVICE.Device[]
+}>({
+  loading: false,
+  dataSource: [],
+  modelList: [],
+  deviceList: []
+})
+
+watch(
+  () => time.value,
+  () => {
+    queryParams.startTime = dayjs(time.value[0]).format('YYYY/MM/DD')
+    queryParams.endTime = dayjs(time.value[1]).format('YYYY/MM/DD')
+    getHistoryPage()
+  }
+)
+
+watch(
+  () => queryParams.deviceId,
+  () => getHistoryPage()
+)
+
+watch(
+  () => queryParams.modelId,
+  () => {
+    console.log(queryParams.modelId)
+    getHistoryPage()
+  }
+)
+
+const getDeviceList = async () => {
+  const { data } = await DeviceContriller.list()
+  state.deviceList = data
+}
+
+const getModelList = async () => {
+  const { data: modelData } = await ModelController.list()
+  state.modelList = modelData
+}
+
+const getHistoryPage = async () => {
+  state.loading = true
+
+  const { data: historyData, sum } = await DataController.pageHistory(queryParams)
+  state.loading = false
+  state.dataSource = historyData
+  queryParams.total = sum
+}
+
+onMounted(() => {
+  getModelList()
+  getDeviceList()
+})
+
+</script>
+<style lang='less' scoped >
+</style>

+ 9 - 0
src/pages/Iot/dataServer/openApi.vue

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

+ 17 - 1
src/router/index.ts

@@ -96,7 +96,23 @@ const routes: Array<ROUTER.RoutesProps> = [
             name: '当前告警',
             component: () => import('@/pages/iot/devOps/nowAlert.vue')
           }
-
+        ]
+      },
+      {
+        path: '/dataServer',
+        name: '数据服务',
+        redirect: '/dataServer/history',
+        children: [
+          {
+            path: '/dataServer/history',
+            name: '历史数据',
+            component: () => import('@/pages/iot/dataServer/history.vue')
+          },
+          {
+            path: '/dataServer/openApi',
+            name: '开放接口',
+            component: () => import('@/pages/iot/dataServer/openApi.vue')
+          }
         ]
       }
 

+ 46 - 7
src/type/iot.d.ts

@@ -11,6 +11,7 @@ declare namespace IOT {
       } & Partial<COMMON.QueryParams>
 
       interface Model {
+        id: string
         modelLabel: string,
         transportType: string,
         payloadType: string,
@@ -28,9 +29,9 @@ declare namespace IOT {
 
       interface plugin {
         id: string
-        "modelId": string,
-        "modelPluginType": "JS",
-        "modelPluginBody": string
+        'modelId': string,
+        'modelPluginType': 'JS',
+        'modelPluginBody': string
       }
     }
 
@@ -72,8 +73,6 @@ declare namespace IOT {
       }
     }
 
-    
-
     namespace DEVICE {
       type QueryPamars = {
         page: number
@@ -231,5 +230,45 @@ declare namespace IOT {
         actions: Array
         status: boolean
     }
-  }
-}
+    }
+
+    namespace DATA {
+
+      interface QueryParams {
+        page: number,
+        pageSize: number,
+        deviceId: string
+        modelId: string
+        attributeKey: string,
+        startTime: string,
+        endTime
+      }
+
+      interface History {
+        'deviceId': string,
+        'ts': 1681181164001,
+        'key': string,
+        'keyLabel': string,
+        'stringValue': string,
+        'doubleValue': null,
+        'longValue': null,
+        'booleanValue': null,
+        'jsonValue': null,
+        'dataUnit': null,
+        'scope': null
+      }
+
+      interface OpenApi {
+        id: string
+        'apiUrl': string,
+        'apiLabel': string,
+        'apiDescription':string,
+        'apiParameters': string,
+        'apiParametersDescription': string,
+        'apiResponse': string,
+        'apiResponseDescription': string
+      }
+    }
+}
+
+}