Browse Source

feat 关系平面图选择设备逻辑优化

lihao1 3 years ago
parent
commit
edecfb908a

+ 2 - 2
demo/src/main/java/com/framework/mvvm/model/db/dao/ObjectDao.kt

@@ -65,7 +65,7 @@ interface ObjectDao {
     /**
      * 返回楼层类型的 ObjectEntity
      */
-    @Query("select * from object where obj_type = 'floor' and building_id =:buildingId")
+    @Query("select * from object where obj_type = 'floor' and building_id =:buildingId and valid = 1")
     suspend fun getFloorsByBuildingId(buildingId: String): List<ObjectEntity>
 
     /**
@@ -89,7 +89,7 @@ interface ObjectDao {
     /**
      * 返回所有建筑 ObjectEntity
      */
-    @Query("select * from object where obj_type = 'space' and class_code ='GeneralZone' and floor_id =:floorId")
+    @Query("select * from object where obj_type = 'space' and class_code ='GeneralZone' and floor_id =:floorId and valid = 1")
     suspend fun getSpaceByFloorId(floorId: String): List<ObjectEntity>
 
     /**

+ 2 - 1
demo/src/main/java/com/sybotan/android/demo/activities/ChooseEquipActivity.kt

@@ -322,6 +322,7 @@ class ChooseEquipActivity : BaseActivity(), DIAware {
                     for (pa in param) {
                         chooseRelList.add(pa.entity)
                     }
+                    chooseSpaceVM.getEquips(floorId, groupRelConfigEntity)
                     initRelName()
                 }
                 ChooseSpaceVM.FLOORS_LIST -> {
@@ -329,7 +330,7 @@ class ChooseEquipActivity : BaseActivity(), DIAware {
                     for (floor in floors) {
                         if (floorId == floor.id) {
                             floorTv.setText(floor.localName)
-                            chooseSpaceVM.getEquips(floorId, groupRelConfigEntity)
+//                            chooseSpaceVM.getEquips(floorId, groupRelConfigEntity)
                         }
                     }
                 }

+ 16 - 14
demo/src/main/java/com/sybotan/android/demo/viewmodel/ChooseSpaceVM.kt

@@ -253,25 +253,27 @@ class ChooseSpaceVM(
             val spaces = ArrayList<TunableSpace>()
             val equips = ArrayList<ObjectEntity>()
             for (rel in rels) {
-                val objEntity: ObjectEntity
+                var objEntity: ObjectEntity? = null
                 if (rel.entity.objFrom == deviceId) {
-                    objEntity = repo.getObject(rel.entity.objTo!!)!!
+                    objEntity = repo.getObject(rel.entity.objTo!!)
                 } else {
-                    objEntity = repo.getObject(rel.entity.objFrom!!)!!
+                    objEntity = repo.getObject(rel.entity.objFrom!!)
                 }
-                val obj = objEntity.infos!!.asJsonObject
-                val info = gson.fromJson(obj, SpaceInfo::class.java)
-                equips.add(objEntity)
+                objEntity?.let {
+                    val obj = objEntity.infos!!.asJsonObject
+                    val info = gson.fromJson(obj, SpaceInfo::class.java)
+                    equips.add(objEntity)
 //                spaces.add(info.outline[0])
 
-                val tunableSpace = TunableSpace()
-                tunableSpace.outLine = info.outline
-                tunableSpace.name = ObjectNameUtils.getEquipName(objEntity)
-                tunableSpace.id = objEntity.id
-                val floor = repo.getFloorById(objEntity.floorId!!)
-                tunableSpace.floorName = floor.localName
-                tunableSpace.floorId = objEntity.floorId
-                spaces.add(tunableSpace)
+                    val tunableSpace = TunableSpace()
+                    tunableSpace.outLine = info.outline
+                    tunableSpace.name = ObjectNameUtils.getEquipName(objEntity)
+                    tunableSpace.id = objEntity.id
+                    val floor = repo.getFloorById(objEntity.floorId!!)
+                    tunableSpace.floorName = floor.localName
+                    tunableSpace.floorId = objEntity.floorId
+                    spaces.add(tunableSpace)
+                }
             }
             mEmitter.SendDirective(SERVE_AREAS, spaces)
             mEmitter.SendDirective(EQUIP_RELATION, rels)

+ 1 - 1
demo/src/main/java/com/sybotan/android/demo/viewmodel/GraphyVM.kt

@@ -81,7 +81,7 @@ class GraphyVM(
                 objectEntity?.let {
                     spaceJobModel.buildingId = buildingId
                     spaceJobModel.id = spaceEntity.spaceId
-                    spaceJobModel.localName = objectEntity.localName + ObjectNameUtils.getEquipName(objectEntity)
+                    spaceJobModel.localName = ObjectNameUtils.getEquipName(objectEntity)
                     spaceJobModel.name = objectEntity.name
                     spaceJobModel.projectId = projectId
                     val infos = gson.fromJson(objectEntity.infos, InfosForObj::class.java)

+ 1 - 1
demo/src/main/java/com/sybotan/android/demo/viewmodel/SpaceMapVM.kt

@@ -69,7 +69,7 @@ class SpaceMapVM(
                 if (objectEntity != null) {
                     spaceJobModel.buildingId = buildingId
                     spaceJobModel.id = spaceEntity.spaceId
-                    spaceJobModel.localName = objectEntity.localName + ObjectNameUtils.getEquipName(objectEntity)
+                    spaceJobModel.localName = ObjectNameUtils.getEquipName(objectEntity)
                     spaceJobModel.name = objectEntity.name
                     spaceJobModel.projectId = projectId
                     val infos = gson.fromJson(objectEntity.infos, InfosForObj::class.java)