Explorar o código

修改设置-仓储、机器人调试页面

hh hai 1 ano
pai
achega
ad3dcbcb30

+ 10 - 10
entry/src/main/ets/model/StorageSpace.ets

@@ -3,23 +3,23 @@
  * */
 export default class StorageSpace {
   // id
-  id: number;
+  id?: number;
   // 仓储id
-  storageId: number;
+  storageId?: number;
   // x坐标
-  x: number;
+  x?: number;
   // y坐标
-  y: number;
+  y?: number;
   // 启用状态(1:启用 2:禁用)
-  enableState: number
+  enableState?: number
   // 仓储类型(多个用逗号隔开)(1:电子元器件 2:电路板 3:结构件 4:辅助材料)
-  storageType: string
+  storageType?: string
   // 容量(单位:层)
-  capacity: number
+  capacity?: number
   // 能否途经(1:启用 2:禁用)
-  canWay: number
+  canWay?: number
   // 是否为停靠点(1:是 2:否)
-  canPark: number
+  canPark?: number
   // 停靠点类型(1:出入库位置 2:充电位置 3:工作台 4:其他)
-  parkType: number
+  parkType?: number
 }

+ 7 - 15
entry/src/main/ets/model/database/StorageSpaceModel.ets

@@ -85,21 +85,12 @@ class StorageSpaceModel {
 
   /**
    * 添加储位
-   * @param storageId 储位id
-   * @param x x坐标
-   * @param y y坐标
-   * @param ySize y尺寸
-   * @param enableState 启用状态
-   * @param storageType 仓储类型
-   * @param capacity 容量
-   * @param canWay 能否途经
-   * @param canPark 是否为停靠点
-   * @param parkType 停靠点类型
+   * @param space 储位信息
    * @returns 储位id
    */
-  addStorageSpace(storageId: number, x: number, y: number, enableState: number, storageType: string, capacity: number, canWay: number, canPark: number, parkType?: number): Promise<number>{
-      return this.rdbStore.insert(this.tableName, {STORAGE_ID: storageId, X: x, Y: y, ENABLE_STATE: enableState, STORAGE_TYPE: storageType, CAPACITY: capacity,
-        CAN_WAY: canWay, CAN_PARK: canPark, PARK_TYPE: parkType})
+  addStorageSpace(space: StorageSpace): Promise<number>{
+      return this.rdbStore.insert(this.tableName, {STORAGE_ID: space.storageId, X: space.x, Y: space.y, ENABLE_STATE: space.enableState, STORAGE_TYPE: space.storageType, CAPACITY: space.capacity,
+        CAN_WAY: space.canWay, CAN_PARK: space.canPark, PARK_TYPE: space.parkType})
   }
 
   /**
@@ -148,13 +139,14 @@ class StorageSpaceModel {
     if (storage.xSize && storage.xSize > 0 && storage.ySize && storage.ySize > 0) {
       for (let y = 1; y <= storage.ySize; y++) {
         for (let x = 1; x <= storage.xSize; x++) {
-          this.addStorageSpace(storage.id, x, y, 1, '', storage.defaultLayer, 1, 0)
+          let space = {storageId: storage.id, x: x, y: y, enableState: 1, storageType: '', capacity: storage.defaultLayer, canWay: 1, canPark: 0}
+          this.addStorageSpace(space)
         }
       }
     }
   }
 
-  batchInsert(array: []) {
+  batchInsert(array: any[]) {
     return this.rdbStore.batchInsert(this.tableName, array)
   }
 }

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 78 - 101
entry/src/main/ets/pages/RobotDebug.ets


+ 33 - 2
entry/src/main/ets/view/RobotSetView.ets

@@ -6,13 +6,18 @@ import StorageInfo from '../model/StorageInfo'
 import TimeUtil from '../common/util/TimeUtil'
 import router from '@ohos.router'
 import { RobotPreviewComp } from '../common/component/RobotPreviewComp'
+import StorageConfig from '../viewmodel/StorageConfig'
+import JGRequest from '../common/util/request/Request'
+import StorageModel from '../model/database/StorageModel'
+import StorageSpace from '../model/StorageSpace'
+import StorageSpaceModel from '../model/database/StorageSpaceModel'
 
 @Component
 export struct RobotSetView {
   @State list: Resource[] =  [$r('app.media.car_preview'),$r('app.media.car_preview'),$r('app.media.car_preview')]
   @State selectRobot : number = 1
   @State robots: RobotInfo[] = CommonConstants.ROBOTS
-  @State storages: StorageInfo[] = CommonConstants.STORAGES
+  @State storages: StorageInfo[] = []
 
   @State robotX: number = 0
   @State robotY: number = 0
@@ -20,13 +25,39 @@ export struct RobotSetView {
   // 视频播放
   @State videoSrc: Resource = $rawfile('robot.mp4')
   videoController: VideoController = new VideoController()
-  aboutToAppear() {
+
+  async aboutToAppear() {
     if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].x) {
       this.robotX = this.robots[this.selectRobot].x
     }
     if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].y) {
       this.robotY = this.robots[this.selectRobot].y
     }
+
+
+    // 查询本地数据库,没有则从后台获取
+    this.storages = await StorageModel.getStorageList()
+
+    if (!this.storages || this.storages.length <= 0) {
+      // 查询后台数据库的线边库
+      let config: StorageConfig = await JGRequest.get("/api/v1/wms/position/houseConfigInfo/" + 1, {})
+      if (!config) {
+        return
+      }
+      let storage = {storageName: config.houseName, xSize: config.xNum, ySize: config.yNum, defaultLayer: config.layer} as StorageInfo
+      this.storages.push(storage)
+      let storageId = await StorageModel.addStorage(config.houseName, config.xNum, config.yNum, config.layer)
+      storage.id = storageId
+      if (config.xNum && config.xNum > 0 && config.yNum && config.yNum > 0) {
+        for (let y = 1; y <= config.yNum; y++) {
+          for (let x = 1; x <= config.xNum; x++) {
+            let space: StorageSpace = {storageId: storageId, x: x, y: y, enableState: 1, storageType: '', capacity: config.layer, canWay: 1, canPark: 0}
+            await StorageSpaceModel.addStorageSpace(space)
+          }
+        }
+      }
+    }
+
     for (const storage of this.storages) {
       if (this.robots && this.robots[this.selectRobot] && this.robots[this.selectRobot].storageId && this.robots[this.selectRobot].storageId === storage.id) {
         this.robotStorage = storage

+ 31 - 32
entry/src/main/ets/view/StorageSetView.ets

@@ -6,6 +6,7 @@ import StorageSpace from '../model/StorageSpace'
 import StorageSpaceGrid from '../common/component/StorageSpaceGrid'
 import SpaceStateList from '../model/SpaceStateList'
 import JGRequest from '../common/util/request/Request'
+import StorageConfig from '../viewmodel/StorageConfig'
 
 let storageTypeArray: string[] = CommonConstants.STORAGE_TYPE
 let parkTypeArray: string[] = CommonConstants.PARK_TYPE
@@ -95,7 +96,7 @@ export struct StorageSetView {
     builder: EditStorageSizeDialog({
       currentStorage: $currentStorage,
       confirm: ()=> {
-        this.updateStorageSpaceData()
+        this.updateStorageSpaceData(true)
       }
     }),
     autoCancel: true,
@@ -118,26 +119,30 @@ export struct StorageSetView {
   async aboutToAppear() {
     // 查询后台数据库的线边库
     let config: StorageConfig = await JGRequest.get("/api/v1/wms/position/houseConfigInfo/" + 1, {})
-    if (!config) {
-      return
-    }
+
     // 查询本地数据库,没有则添加数据(仓储和储位数据)
     this.storages = await StorageModel.getStorageList()
-    if (!this.storages || this.storages.length <= 0) {
+    if (!config && (!this.storages || this.storages.length <= 0)) {
+      return
+    }
+
+    if ((!this.storages || this.storages.length <= 0) && config) {
       this.storages.push({storageName: config.houseName, xSize: config.xNum, ySize: config.yNum, defaultLayer: config.layer} as StorageInfo)
       let storageId = await StorageModel.addStorage(config.houseName, config.xNum, config.yNum, config.layer)
+      this.storages[0].id = storageId
       if (config.xNum && config.xNum > 0 && config.yNum && config.yNum > 0) {
         for (let y = 1; y <= config.yNum; y++) {
-          for (let x = 1; x <= config.yNum; x++) {
-            await StorageSpaceModel.addStorageSpace(storageId, x, y, 1, '', config.layer, 1, 2)
+          for (let x = 1; x <= config.xNum; x++) {
+            let space: StorageSpace = {storageId: storageId, x: x, y: y, enableState: 1, storageType: '', capacity: config.layer, canWay: 1, canPark: 0}
+            await StorageSpaceModel.addStorageSpace(space)
           }
         }
       }
-    } else if (this.storages[0].xSize != config.xNum || this.storages[0].ySize != config.yNum) {
+    } else if ((this.storages[0].xSize != config.xNum || this.storages[0].ySize != config.yNum) && config) {
       // 如果本地数据保存数据和后台不匹配,后台数据库为主
       this.currentStorage = this.storages[0]
       StorageModel.updateStorage(this.storages[0].id, this.storages[0].storageName, config.xNum, config.yNum, config.layer)
-      this.updateStorageSpaceData()
+      this.updateStorageSpaceData(false)
     }
     // 渲染封装数据
     this.currentStorage = this.storages[0]
@@ -182,7 +187,14 @@ export struct StorageSetView {
     })
   }
 
-  updateStorageSpaceData() {
+  /*
+   * updateArray
+   * */
+  /**
+   * 更新本地数据库的仓储储位
+   * @param updateArray 是否更新spaceArray(aboutToAppear调用时不更新)
+   */
+  async updateStorageSpaceData(updateArray: boolean) {
     this.spaceArray = []
     this.stateArray = []
     let y = 1
@@ -202,14 +214,16 @@ export struct StorageSetView {
       this.yNum.push(index)
       y++
     }
-    StorageSpaceModel.initDataByStorage(this.currentStorage)
-    StorageSpaceModel.getListByStorageId(this.currentStorage.id).then(spaces => {
-      if (spaces && spaces.length > 0) {
-        for (const space of spaces) {
-          this.spaceArray[space.y - 1][space.x - 1].id = space.id
+    await StorageSpaceModel.initDataByStorage(this.currentStorage)
+    if (updateArray) {
+      StorageSpaceModel.getListByStorageId(this.currentStorage.id).then(spaces => {
+        if (spaces && spaces.length > 0) {
+          for (const space of spaces) {
+            this.spaceArray[space.y - 1][space.x - 1].id = space.id
+          }
         }
-      }
-    })
+      })
+    }
   }
 
   build() {
@@ -1138,19 +1152,4 @@ function getParkTypeStr(parkType: number, typeArray: string[]): string {
     return ''
   }
   return typeArray[parkType - 1]
-}
-
-class StorageConfig {
-  // 干燥柜及货架区域
-  area?: number;
-  // 仓库名称
-  houseName?: string
-  // 储位类型 1 线边仓 2 干燥柜 3 货架
-  houseType: string
-  // 使用层数
-  layer?: number;
-  // x尺寸
-  xNum?: number;
-  // y尺寸
-  yNum?: number;
 }

+ 17 - 0
entry/src/main/ets/viewmodel/StorageConfig.ets

@@ -0,0 +1,17 @@
+/*
+ * 仓库配置
+ * */
+export default class StorageConfig {
+  // 干燥柜及货架区域
+  area?: number;
+  // 仓库名称
+  houseName?: string
+  // 储位类型 1 线边仓 2 干燥柜 3 货架
+  houseType: string
+  // 使用层数
+  layer?: number;
+  // x尺寸
+  xNum?: number;
+  // y尺寸
+  yNum?: number;
+}