Browse Source

@task: upload data

bai 3 years ago
parent
commit
ee129cc1b1

+ 17 - 5
demo/src/main/java/com/framework/mvvm/model/repository/AdmRepository.kt

@@ -239,8 +239,14 @@ class AdmRepository(
     }
 
 
-    suspend fun getRelByGraphCodeAndRelCodeAndObjFromAndObjTo(graphCode: String, relCode: String, objFrom: String, objto: String): RelationEntity? {
-        return db.relationDao().getRelByGraphCodeAndRelCodeAndObjFromAndObjTo(graphCode, relCode, objFrom, objto)
+    suspend fun getRelByGraphCodeAndRelCodeAndObjFromAndObjTo(
+        graphCode: String,
+        relCode: String,
+        objFrom: String,
+        objto: String
+    ): RelationEntity? {
+        return db.relationDao()
+            .getRelByGraphCodeAndRelCodeAndObjFromAndObjTo(graphCode, relCode, objFrom, objto)
     }
 
     /**
@@ -266,12 +272,11 @@ class AdmRepository(
         request(
             from = { api.getFrame(request) },
             to = { frame ->
-                println("frame: $frame")
                 val projects = frame.projects
                 val objects = frame.buildingsAndFloors
                 try {
                     db.projectDao().insProject(projects)
-                    db.objectDao().insObjects(objects)
+                    objects.forEach { it.state = 2 }.let { db.objectDao().insObjects(objects) }
                 } catch (e: Exception) {
                     Log.d("IRepository:${AdmRepository::class.simpleName}", e.message!!)
                 }
@@ -398,7 +403,12 @@ class AdmRepository(
     /**
      * 上传建筑数据
      */
-    suspend fun uploadBuilding(projectId: String, buildingId: String) {
+    suspend fun uploadBuilding(
+        userId: String,
+        groupCode: String,
+        projectId: String,
+        buildingId: String
+    ) {
         try {
             val pipeDao = db.pipeDao()
             val fileDao = db.fileDao()
@@ -456,6 +466,8 @@ class AdmRepository(
             )
 
             val uploadBuilding = UploadBuilding(
+                userId = userId,
+                groupCode = groupCode,
                 projectId = projectId,
                 clientId = clientId,
                 uploadData = building

+ 2 - 0
demo/src/main/java/com/framework/mvvm/model/vo/UploadBuilding.kt

@@ -1,6 +1,8 @@
 package com.framework.mvvm.model.vo
 
 data class UploadBuilding(
+    val userId: String,
+    val groupCode: String,
     val projectId: String,
     val clientId: String,
     val uploadData: Building

+ 1 - 1
demo/src/main/java/com/framework/mvvm/model/vo/User.kt

@@ -3,4 +3,4 @@ package com.framework.mvvm.model.vo
 /**
  * User
  */
-data class User(val userId: String)
+data class User(val userId: String = "bdtp")

+ 6 - 1
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -71,7 +71,12 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
         viewModelScope.launch(Dispatchers.IO) {
             val buildings = repository.getBuildings()
             for (building in buildings) {
-                repository.uploadBuilding(building.projectId!!, building.id)
+                repository.uploadBuilding(
+                    userId = "bdtp",
+                    groupCode = building.groupCode!!,
+                    projectId = building.projectId!!,
+                    buildingId = building.id
+                )
             }
             withContext(Dispatchers.Main) {
                 block?.invoke()

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

@@ -92,7 +92,7 @@ class DemoApp : Application(), DIAware {
 
         val clientId = sp.getString(CLIENT_ID, "") ?: ""
         if (clientId.isEmpty()) {
-            mVm.getClient(User(IdUtil.simpleUUID()))
+            mVm.getClient(User())
         }
 
     } // Function onCreate()