Browse Source

@fun: flow and offline data

bai 2 years ago
parent
commit
d5ff5f461a
31 changed files with 770 additions and 106 deletions
  1. 2 0
      app/src/main/AndroidManifest.xml
  2. 4 0
      app/src/main/java/com/ys/bdtp/adm/di/Di.kt
  3. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/UserDao.kt
  4. 7 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/BuildingDao.kt
  5. 10 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/FloorDao.kt
  6. 25 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/ProjectDao.kt
  7. 4 4
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/dict/InfoDictEntity.kt
  8. 4 4
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/dict/RelationDictEntity.kt
  9. 21 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/BuildingWithFloors.kt
  10. 16 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/FloorWithCads.kt
  11. 21 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/ProjectWithBuildingAndFloors.kt
  12. 18 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/ProjectWithBuildings.kt
  13. 1 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/relation/UserWithProjects.kt
  14. 2 1
      app/src/main/java/com/ys/bdtp/adm/mvvm/model/nt/Api.kt
  15. 12 10
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/ExpandList.kt
  16. 77 23
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadContent.kt
  17. 4 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadDrawingItem.kt
  18. 68 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadHeadLeft.kt
  19. 86 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadHeadRight.kt
  20. 56 7
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadScreen.kt
  21. 9 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadSide.kt
  22. 4 4
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/Main.kt
  23. 3 3
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/Offline.kt
  24. 75 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineSide.kt
  25. 144 35
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineSide2.kt
  26. 2 2
      app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskSide.kt
  27. 28 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadRepository.kt
  28. 30 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadViewModel.kt
  29. 16 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineRepository.kt
  30. 19 0
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineViewModel.kt
  31. 1 5
      app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectRepository.kt

+ 2 - 0
app/src/main/AndroidManifest.xml

@@ -12,6 +12,8 @@
             android:roundIcon="@mipmap/ic_launcher_round"
             android:usesCleartextTraffic="true"
             android:supportsRtl="true"
+            android:largeHeap="true"
+            android:hardwareAccelerated="false"
             android:theme="@style/Theme.Adm">
         <activity
                 android:name=".MainActivity"

+ 4 - 0
app/src/main/java/com/ys/bdtp/adm/di/Di.kt

@@ -8,6 +8,8 @@ import com.ys.bdtp.adm.app.interceptor.GzipInterceptor
 import com.ys.bdtp.adm.app.interceptor.TokenInterceptor
 import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
 import com.ys.bdtp.adm.mvvm.model.nt.Api
+import com.ys.bdtp.adm.mvvm.vm.cad.CadRepository
+import com.ys.bdtp.adm.mvvm.vm.cad.CadViewModel
 import com.ys.bdtp.adm.mvvm.vm.flash.FlashRepository
 import com.ys.bdtp.adm.mvvm.vm.flash.FlashViewModel
 import com.ys.bdtp.adm.mvvm.vm.login.LoginRepository
@@ -96,6 +98,7 @@ val repositoryModule = DI.Module("repository") {
     bind { provider { ProjectRepository(instance(), instance()) } }
     bind { provider { TaskRepository(instance(), instance()) } }
     bind { provider { OfflineRepository(instance(), instance()) } }
+    bind { provider { CadRepository(instance(), instance()) } }
 }
 
 val viewModelModule = DI.Module("viewModel") {
@@ -105,6 +108,7 @@ val viewModelModule = DI.Module("viewModel") {
     bind { provider { ProjectViewModel(instance()) } }
     bind { provider { TaskViewModel(instance()) } }
     bind { provider { OfflineViewModel(instance()) } }
+    bind { provider { CadViewModel(instance()) } }
 }
 
 val dbModule = DI.Module("dbModule") {

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/UserDao.kt

@@ -2,7 +2,7 @@ package com.ys.bdtp.adm.mvvm.model.db.dao
 
 import androidx.room.*
 import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
-import com.ys.bdtp.adm.mvvm.model.db.entity.relation.UserWithProjects
+import com.ys.bdtp.adm.mvvm.model.db.relation.UserWithProjects
 import kotlinx.coroutines.flow.Flow
 
 /**

+ 7 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/BuildingDao.kt

@@ -3,7 +3,10 @@ package com.ys.bdtp.adm.mvvm.model.db.dao.task
 import androidx.room.Dao
 import androidx.room.Insert
 import androidx.room.Query
+import androidx.room.Transaction
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.BuildingEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
+import kotlinx.coroutines.flow.Flow
 
 /**
  * building 表访问接口
@@ -21,4 +24,8 @@ interface BuildingDao {
 
     @Insert
     suspend fun insBuildings(floors: List<BuildingEntity>)
+
+    @Transaction
+    @Query("select * from building")
+    fun getBuildingWithFloors(): Flow<BuildingWithFloors>
 }

+ 10 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/FloorDao.kt

@@ -3,7 +3,10 @@ package com.ys.bdtp.adm.mvvm.model.db.dao.task
 import androidx.room.Dao
 import androidx.room.Insert
 import androidx.room.Query
+import androidx.room.Transaction
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.FloorWithCads
+import kotlinx.coroutines.flow.Flow
 
 /**
  * floor 表访问接口
@@ -22,4 +25,11 @@ interface FloorDao {
 
     @Insert
     suspend fun insFloors(floors: List<FloorEntity>)
+
+    /**
+     *
+     */
+    @Transaction
+    @Query("select * from floor where id = :id")
+    fun getFloorWithCadsById(id: String): Flow<FloorWithCads>
 }

+ 25 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/dao/task/ProjectDao.kt

@@ -2,6 +2,8 @@ package com.ys.bdtp.adm.mvvm.model.db.dao.task
 
 import androidx.room.*
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildingAndFloors
+import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildings
 import kotlinx.coroutines.flow.Flow
 
 /**
@@ -25,4 +27,27 @@ interface ProjectDao {
 
     @Delete
     suspend fun delProject(project: ProjectEntity)
+
+    /**
+     *
+     */
+    @Transaction
+    @Query("select * from project")
+    fun getProjectWithBuildings(): Flow<List<ProjectWithBuildings>>
+
+    /**
+     * 多表查询
+     */
+    @Transaction
+    @Query("select * from project")
+    fun getProjectWithBuildingAndFloors(): Flow<List<ProjectWithBuildingAndFloors>>
+
+    /**
+     * 多表查询
+     */
+    @Transaction
+    @Query("select * from project where id = :id")
+    fun getProjectWithBuildingAndFloorsById(id: String): Flow<ProjectWithBuildingAndFloors>
+
+
 }

+ 4 - 4
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/dict/InfoDictEntity.kt

@@ -52,13 +52,13 @@ data class InfoDictEntity(
     @ColumnInfo(name = "is_delivery") val isDelivery: Boolean,
     @ColumnInfo(name = "is_multiple") val isMultiple: Boolean,
     @ColumnInfo(name = "is_region") val isRegion: Boolean,
-    @ColumnInfo(name = "priority") val priority: String,
+    @ColumnInfo(name = "priority") val priority: String? = "",
     @ColumnInfo(name = "source_from") var sourceFrom: Int,
     @ColumnInfo(name = "sub_flag") var subFlag: Boolean,
     @ColumnInfo(name = "weak_point") var weakPoint: Boolean,
     @ColumnInfo(name = "valid") var valid: Int?,
-    @ColumnInfo(name = "version") val version: String?,
-    @ColumnInfo(name = "creator") val creator: String,
-    @ColumnInfo(name = "creation_time") val creationTime: Long,
+    @ColumnInfo(name = "version") val version: String? = "",
+    @ColumnInfo(name = "creator") val creator: String? = "",
+    @ColumnInfo(name = "creation_time") val creationTime: Long = 0L,
     @ColumnInfo(name = "data_source") val dataSource: JsonElement? = null,
 )

+ 4 - 4
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/dict/RelationDictEntity.kt

@@ -37,11 +37,11 @@ data class RelationDictEntity(
     @ColumnInfo(name = "from_obj_type") val fromObjType: String?,
     @ColumnInfo(name = "to_obj_type") val toObjType: String?,
     @ColumnInfo(name = "target_objs") val targetObjs: String?,
-    @ColumnInfo(name = "manual") val manual: Int,
+    @ColumnInfo(name = "manual") val manual: Int = 0,
     @ColumnInfo(name = "project_id") val projectId: String,
-    @ColumnInfo(name = "prompting") val prompting: String,
+    @ColumnInfo(name = "prompting") val prompting: String? = "",
     @ColumnInfo(name = "source_flag") val sourceFlag: Boolean,
-    @ColumnInfo(name = "system_type") val systemType: Int,
+    @ColumnInfo(name = "system_type") val systemType: Int = 0,
     @ColumnInfo(name = "before_cal_rels") val beforeCalRels: JsonElement? = null,
     @ColumnInfo(name = "cal_rules") val calRules: JsonElement? = null,
     @ColumnInfo(name = "source_type_codes") val sourceTypeCodes: JsonElement? = null,
@@ -53,4 +53,4 @@ data class RelationDictEntity(
     @ColumnInfo(name = "creator") val creator: String,
     @ColumnInfo(name = "creation_time") val creationTime: Long,
 
-)
+    )

+ 21 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/BuildingWithFloors.kt

@@ -0,0 +1,21 @@
+package com.ys.bdtp.adm.mvvm.model.db.relation
+
+import androidx.room.Embedded
+import androidx.room.Relation
+import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.BuildingEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
+import com.ys.bdtp.adm.mvvm.ui.compose.Building
+
+/**
+ * Building 与 Floor 一对多关系表
+ */
+data class BuildingWithFloors(
+    @Embedded val building: BuildingEntity,
+    @Relation(
+        parentColumn = "id",
+        entityColumn = "building_id"
+    )
+    val floors: List<FloorEntity>
+)

+ 16 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/FloorWithCads.kt

@@ -0,0 +1,16 @@
+package com.ys.bdtp.adm.mvvm.model.db.relation
+
+import androidx.room.Embedded
+import androidx.room.Relation
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.CadEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+
+data class FloorWithCads(
+    @Embedded
+    val floor: FloorEntity,
+    @Relation(
+        parentColumn = "id",
+        entityColumn = "floor_id"
+    )
+    val cads: List<CadEntity>
+)

+ 21 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/ProjectWithBuildingAndFloors.kt

@@ -0,0 +1,21 @@
+package com.ys.bdtp.adm.mvvm.model.db.relation
+
+import androidx.room.Embedded
+import androidx.room.Relation
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.BuildingEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
+
+/**
+ * 嵌套关系
+ *  Project 与 Building 一对多
+ *  Building 与 Floor 一对多
+ */
+data class ProjectWithBuildingAndFloors(
+    @Embedded val project: ProjectEntity,
+    @Relation(
+        entity = BuildingEntity::class,
+        parentColumn = "id",
+        entityColumn = "project_id"
+    )
+    val buildings: List<BuildingWithFloors>
+)

+ 18 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/relation/ProjectWithBuildings.kt

@@ -0,0 +1,18 @@
+package com.ys.bdtp.adm.mvvm.model.db.relation
+
+import androidx.room.Embedded
+import androidx.room.Relation
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.BuildingEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.ProjectEntity
+
+/**
+ * Project 与 Building 一对多关系表
+ */
+data class ProjectWithBuildings(
+    @Embedded val project: ProjectEntity,
+    @Relation(
+        parentColumn = "id",
+        entityColumn = "project_id"
+    )
+    val buildings: List<BuildingEntity>
+)

+ 1 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/model/db/entity/relation/UserWithProjects.kt

@@ -1,4 +1,4 @@
-package com.ys.bdtp.adm.mvvm.model.db.entity.relation
+package com.ys.bdtp.adm.mvvm.model.db.relation
 
 import androidx.room.Embedded
 import androidx.room.Relation

+ 2 - 1
app/src/main/java/com/ys/bdtp/adm/mvvm/model/nt/Api.kt

@@ -54,13 +54,14 @@ interface Api {
     /**
      * 下载任务数据
      */
+    //@Headers("Content-Encoding: gzip")
     @POST("adm/download")
     suspend fun getMission(@Body map: Map<String, String>): Model<Mission>
 
     /**
      * 上传任务数据
      */
-    @Headers("Content-Encoding: gzip")
+    //@Headers("Content-Encoding: gzip")
     @POST("adm/upload")
     suspend fun uploadMission(@Body mission: Mission)
 

+ 12 - 10
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/compose/ExpandList.kt

@@ -28,6 +28,8 @@ import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.app.theme.underColor
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
 
 data class Building(val id: String, val name: String, val floors: List<String>)
 
@@ -41,7 +43,7 @@ val buildings = listOf(
 
 
 @Composable
-fun ExpandList(items: List<Building>) {
+fun ExpandList(items: List<BuildingWithFloors>, click: (FloorEntity) -> Unit) {
     var selectId by remember { mutableStateOf("1") }
     var isExpand by remember { mutableStateOf(true) }
 
@@ -52,47 +54,47 @@ fun ExpandList(items: List<Building>) {
     ) {
         items(
             items = items,
-            key = { item -> item.id }
+            key = { item -> item.building.id }
         ) { building ->
             Row(
                 modifier = Modifier
                     .height(60.dp)
                     .fillMaxWidth()
                     .clickable {
-                        if (selectId == building.id) {
+                        if (selectId == building.building.id) {
                             isExpand = !isExpand
                         } else {
                             isExpand = true
-                            selectId = building.id
+                            selectId = building.building.id
                         }
                     },
                 verticalAlignment = Alignment.CenterVertically
             ) {
                 Spacer(modifier = Modifier.width(24.dp))
                 Icon(
-                    imageVector = if (building.id == selectId && isExpand)
+                    imageVector = if (building.building.id == selectId && isExpand)
                         Icons.Default.ArrowDropDown
                     else
                         Icons.Default.ArrowRight,
                     contentDescription = ""
                 )
-                Text(text = building.name, color = textBlackColor)
+                Text(text = building.building.name, color = textBlackColor)
             }
 
-            if (building.id == selectId && isExpand) {
+            if (building.building.id == selectId && isExpand) {
                 building.floors.forEach { floor ->
                     Row(
                         modifier = Modifier
                             .height(60.dp)
                             .fillMaxWidth()
                             .clickable {
-
+                                click(floor)
                             },
                         verticalAlignment = Alignment.CenterVertically
                     ) {
                         Spacer(modifier = Modifier.width(48.dp))
                         Text(
-                            text = floor,
+                            text = floor.name,
                             color = textBlackColor,
                         )
                     }
@@ -105,5 +107,5 @@ fun ExpandList(items: List<Building>) {
 @Preview
 @Composable
 fun PreviewExpandList() {
-    ExpandList(buildings)
+    //ExpandList(buildings)
 }

+ 77 - 23
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadContent.kt

@@ -3,21 +3,43 @@ package com.ys.bdtp.adm.mvvm.ui.screen.cad
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.*
 import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
 import androidx.compose.material.Text
-import androidx.compose.runtime.Composable
+import androidx.compose.runtime.*
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.flowWithLifecycle
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.app.theme.trDivColor
 import com.ys.bdtp.adm.app.theme.whiteColor
+import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.mvvm.model.State
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.CadEntity
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.ui.compose.Blank
 import com.ys.bdtp.adm.mvvm.ui.compose.SelectState
 import com.ys.bdtp.adm.mvvm.ui.compose.Table
+import com.ys.bdtp.adm.mvvm.vm.cad.CadViewModel
+import org.kodein.di.compose.rememberViewModel
 
 @Composable
-fun CadContent(selectState: SelectState) {
+fun CadContent(selectState: SelectState, floorEntity: FloorEntity?) {
+    val vm by rememberViewModel<CadViewModel>()
+    val floorState by remember { mutableStateOf(floorEntity) }
+    // 根据floor 获取 cad 文件
+    val lifecycleOwner = LocalLifecycleOwner.current
+    val lifecycleWare = remember(lifecycleOwner) {
+        vm.getFloorWithCads(floorEntity?.id ?: "")
+            .flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
+
+    }
+    val projectData = lifecycleWare.collectAsState(Data.loading())
+
     Column(
         modifier = Modifier
             .fillMaxSize()
@@ -33,18 +55,27 @@ fun CadContent(selectState: SelectState) {
                     CadDrawingTitle()
                 },
                 tr = {
-                    LazyColumn(modifier = Modifier.fillMaxSize()) {
-                        items(20) {
-                            Box {
-                                CadDrawingItem()
-                                Spacer(
-                                    modifier = Modifier
-                                        .align(Alignment.BottomCenter)
-                                        .fillMaxWidth().height(1.dp)
-                                        .background(trDivColor)
-                                )
+                    val data = projectData.value
+                    when (data.state) {
+                        is State.Loading -> {}
+                        is State.Success -> {
+                            LazyColumn(modifier = Modifier.fillMaxSize()) {
+                                data.data?.let {
+                                    items(it.cads) { cad: CadEntity ->
+                                        Box {
+                                            CadDrawingItem(cad)
+                                            Spacer(
+                                                modifier = Modifier
+                                                    .align(Alignment.BottomCenter)
+                                                    .fillMaxWidth().height(1.dp)
+                                                    .background(trDivColor)
+                                            )
+                                        }
+                                    }
+                                }
                             }
                         }
+                        is State.Failure -> {}
                     }
                 }
             )
@@ -57,19 +88,42 @@ fun CadContent(selectState: SelectState) {
                     CadDrawingTitle()
                 },
                 tr = {
-                    LazyColumn(modifier = Modifier.fillMaxSize()) {
-                        items(20) {
-                            Box {
-                                CadDrawingItem()
-                                Spacer(
-                                    modifier = Modifier
-                                        .align(Alignment.BottomCenter)
-                                        .fillMaxWidth().height(1.dp)
-                                        .background(trDivColor)
-                                )
+                    val data = projectData.value
+                    when (data.state) {
+                        is State.Loading -> {}
+                        is State.Success -> {
+                            LazyColumn(modifier = Modifier.fillMaxSize()) {
+                                data.data?.let {
+                                    items(it.cads) { cad: CadEntity ->
+                                        Box {
+                                            CadDrawingItem(cad)
+                                            Spacer(
+                                                modifier = Modifier
+                                                    .align(Alignment.BottomCenter)
+                                                    .fillMaxWidth().height(1.dp)
+                                                    .background(trDivColor)
+                                            )
+                                        }
+                                    }
+                                }
                             }
                         }
+                        is State.Failure -> {}
                     }
+
+                    /*   LazyColumn(modifier = Modifier.fillMaxSize()) {
+                           items(20) {
+                               Box {
+                                   CadDrawingItem()
+                                   Spacer(
+                                       modifier = Modifier
+                                           .align(Alignment.BottomCenter)
+                                           .fillMaxWidth().height(1.dp)
+                                           .background(trDivColor)
+                                   )
+                               }
+                           }
+                       }*/
                 }
             )
         }
@@ -80,5 +134,5 @@ fun CadContent(selectState: SelectState) {
 @Preview(widthDp = 910, heightDp = 711)
 @Composable
 fun PreviewCadContent() {
-    CadContent(SelectState.Left)
+    // CadContent(SelectState.Left)
 }

+ 4 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadDrawingItem.kt

@@ -20,9 +20,10 @@ import com.ys.bdtp.adm.app.theme.blueColor
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.app.theme.textBlueColor
 import com.ys.bdtp.adm.app.theme.trBgColor
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.CadEntity
 
 @Composable
-fun CadDrawingItem() {
+fun CadDrawingItem(cad: CadEntity) {
     Row(
         modifier = Modifier
             .fillMaxWidth()
@@ -33,7 +34,7 @@ fun CadDrawingItem() {
 
     ) {
         Text(
-            text = "xxxxxxxxx.dwg",
+            text = cad.fileName,
             fontSize = 16.sp,
             color = textBlackColor,
             textAlign = TextAlign.Center,
@@ -92,5 +93,5 @@ fun CadDrawingItem() {
 @Preview(widthDp = 900)
 @Composable
 fun PreviewCadDrawingItem() {
-    CadDrawingItem()
+   // CadDrawingItem()
 }

+ 68 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadHeadLeft.kt

@@ -0,0 +1,68 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.cad
+
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.IconButton
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.ys.bdtp.adm.R
+
+
+@Composable
+fun CadHeadLeft(
+    title: String,
+    click: () -> Unit
+) {
+    Row(
+        verticalAlignment = Alignment.CenterVertically,
+        horizontalArrangement = Arrangement.Start
+    ) {
+
+        Spacer(modifier = Modifier.width(32.dp))
+
+        IconButton(
+            modifier = Modifier.height(56.dp),
+            onClick = {
+                click()
+            }
+        ) {
+            Image(
+                painter = painterResource(R.drawable.arrow_back),
+                contentDescription = "",
+                modifier = Modifier.size(24.dp)
+            )
+        }
+
+        Spacer(
+            modifier = Modifier
+                .width(1.dp)
+                .height(16.dp)
+                .background(Color(0xFFD8D8D8))
+        )
+
+        Spacer(
+            modifier = Modifier
+                .width(16.dp)
+                .background(Color(0xFFD8D8D8))
+        )
+
+        Text(text = title, fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Color(0xFF1F2329))
+    }
+}
+
+
+@Preview
+@Composable
+fun PreviewCadHeadLeft() {
+    CadHeadLeft("京东", {})
+}

+ 86 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadHeadRight.kt

@@ -0,0 +1,86 @@
+package com.ys.bdtp.adm.mvvm.ui.screen.cad
+
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
+import androidx.compose.foundation.layout.*
+import androidx.compose.material.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.ys.bdtp.adm.R
+
+
+@Composable
+fun CadHeadRight(
+    role: () -> String,
+    click: () -> Unit
+) {
+    Row(
+        modifier = Modifier.height(56.dp),
+        verticalAlignment = Alignment.CenterVertically,
+        horizontalArrangement = Arrangement.End
+    ) {
+        Box(
+            modifier = Modifier.size(56.dp).padding(12.dp)
+        ) {
+            Image(
+                painter = painterResource(R.drawable.bell),
+                contentDescription = "",
+                modifier = Modifier.fillMaxSize()
+            )
+
+            Box(
+                modifier = Modifier.size(16.dp).align(Alignment.TopEnd)
+            ) {
+                Image(
+                    painter = painterResource(R.drawable.red_circle),
+                    contentDescription = "",
+                    modifier = Modifier.align(Alignment.Center)
+                )
+                Text(
+                    text = "2",
+                    fontSize = 10.sp,
+                    color = Color.White,
+                    modifier = Modifier.align(Alignment.Center)
+                )
+            }
+        }
+
+        Spacer(modifier = Modifier.width(4.dp))
+        Spacer(
+            modifier = Modifier.width(1.dp).height(24.dp).background(Color(0xFFD8D8D8))
+        )
+        Spacer(modifier = Modifier.width(16.dp))
+        Text(text = role(), fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Color(0xFF1F2329), maxLines = 1)
+        Spacer(modifier = Modifier.width(4.dp))
+
+        Row(
+            modifier = Modifier
+                .height(56.dp)
+                .clickable {
+                    click()
+                }
+                .padding(12.dp),
+            verticalAlignment = Alignment.CenterVertically
+        ) {
+            Image(
+                painter = painterResource(R.drawable.avatar),
+                contentDescription = "",
+                Modifier.size(32.dp)
+            )
+            Spacer(modifier = Modifier.width(8.dp))
+            Image(
+                painter = painterResource(R.drawable.arrow_down),
+                contentDescription = "",
+                modifier = Modifier.size(16.dp)
+            )
+        }
+        Spacer(modifier = Modifier.width(20.dp))
+    }
+}

+ 56 - 7
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadScreen.kt

@@ -3,18 +3,49 @@ package com.ys.bdtp.adm.mvvm.ui.screen.cad
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Column
 import androidx.compose.foundation.layout.fillMaxSize
-import androidx.compose.runtime.*
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.setValue
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.tooling.preview.Preview
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.flowWithLifecycle
+import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.mvvm.model.State
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
 import com.ys.bdtp.adm.mvvm.ui.compose.*
+import com.ys.bdtp.adm.mvvm.ui.screen.main.LocalNavHostController
+import com.ys.bdtp.adm.mvvm.vm.cad.CadViewModel
+import org.kodein.di.compose.rememberViewModel
 
 @Composable
-fun CadScreen() {
+fun CadScreen(projectId: String) {
     var selectState by remember { mutableStateOf<SelectState>(SelectState.Left) }
+    val nav = LocalNavHostController.current!!
+    val vm by rememberViewModel<CadViewModel>()
+
+    val lifecycleOwner = LocalLifecycleOwner.current
+    val lifecycleWare = remember(lifecycleOwner) {
+        vm.getProjectWithBuildingAndFloors(projectId)
+            .flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
+    }
+    val projectData = lifecycleWare.collectAsState(Data.loading())
+    var floorState by remember { mutableStateOf<FloorEntity?>(null) }
     Column(modifier = Modifier.background(Color.White)) {
         Head(
-            left = { HeadLeft() },
+            left = {
+                CadHeadLeft(
+                    title = "CAD图纸核查",
+                    click = {
+                        nav.navigateUp()
+                    }
+                )
+            },
             middle = {
                 SelectButton(
                     SelectState.Left,
@@ -36,11 +67,29 @@ fun CadScreen() {
         Body(
             modifier = Modifier.fillMaxSize(),
             side = {
-                CadSide(buildings)
+                when (projectData.value.state) {
+                    is State.Loading -> {
+
+                    }
+                    is State.Success -> {
+                        val project = projectData.value.data
+                        if (project != null) {
+                            CadSide(
+                                buildings = project.buildings,
+                                click = { floorEntity ->
+                                    floorState = floorEntity
+                                }
+
+                            )
+                        }
+                    }
+                    is State.Failure -> {
+
+                    }
+                }
             },
             content = {
-                //Blank()
-                CadContent(selectState)
+                CadContent(selectState, floorState)
             },
             div = { Div(Div.Col) }
         )
@@ -50,5 +99,5 @@ fun CadScreen() {
 @Preview(widthDp = 1137, heightDp = 711)
 @Composable
 fun PreviewCadScreen() {
-    CadScreen()
+    CadScreen("nihao")
 }

+ 9 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/cad/CadSide.kt

@@ -10,12 +10,14 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import com.ys.bdtp.adm.app.theme.textBlackColor
 import com.ys.bdtp.adm.app.theme.underColor
+import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
 import com.ys.bdtp.adm.mvvm.ui.compose.Building
 import com.ys.bdtp.adm.mvvm.ui.compose.ExpandList
 import com.ys.bdtp.adm.mvvm.ui.compose.buildings
 
 @Composable
-fun CadSide(buildings: List<Building>) {
+fun CadSide(buildings: List<BuildingWithFloors>, click: (FloorEntity) -> Unit) {
     Column(
         modifier = Modifier
             .width(280.dp)
@@ -30,12 +32,16 @@ fun CadSide(buildings: List<Building>) {
         ) {
             Text(text = "选择楼层", fontSize = 16.sp, color = textBlackColor)
         }
-        ExpandList(buildings)
+        ExpandList(
+            items = buildings,
+            click = {
+                click(it)
+            })
     }
 }
 
 @Preview
 @Composable
 fun PreviewCadSide() {
-    CadSide(buildings)
+    // CadSide(buildings)
 }

+ 4 - 4
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/main/Main.kt

@@ -37,11 +37,11 @@ fun Main() {
             composable(Route.Tasks) {
                 Tasks()
             }
-            composable(Route.Offline) {
-                Offline()
+            composable("${Route.Offline}/{projectId}") { backStackEntry ->
+                Offline(backStackEntry.arguments?.getString("projectId")!!)
             }
-            composable(Route.Cad) {
-                CadScreen()
+            composable("${Route.Cad}/{projectId}") { backStackEntry ->
+                CadScreen(backStackEntry.arguments?.getString("projectId")!!)
             }
         }
     }

+ 3 - 3
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/Offline.kt

@@ -23,7 +23,7 @@ import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
 import org.kodein.di.compose.rememberViewModel
 
 @Composable
-fun Offline() {
+fun Offline(projectId: String) {
     val nav = LocalNavHostController.current!!
     val vm by rememberViewModel<OfflineViewModel>()
     val scope = rememberCoroutineScope()
@@ -46,7 +46,7 @@ fun Offline() {
         )
 
         Row {
-            OfflineSide2()
+            OfflineSide2(projectId)
             Spacer(
                 modifier = Modifier
                     .width(1.dp)
@@ -68,5 +68,5 @@ fun Offline() {
 @Preview(widthDp = 1137, heightDp = 711)
 @Composable
 fun PreviewOfflineScreen() {
-    Offline()
+    //Offline()
 }

+ 75 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineSide.kt

@@ -8,18 +8,29 @@ import androidx.compose.material.Button
 import androidx.compose.material.ButtonDefaults
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.rememberCoroutineScope
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.flowWithLifecycle
 import com.ys.bdtp.adm.R
 import com.ys.bdtp.adm.app.theme.bgBlueColor
 import com.ys.bdtp.adm.app.theme.blueColor
 import com.ys.bdtp.adm.app.theme.underColor
 import com.ys.bdtp.adm.app.theme.whiteColor
+import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.mvvm.model.vo.request.requestBody
 import com.ys.bdtp.adm.mvvm.ui.compose.Div
+import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
+import kotlinx.coroutines.launch
+import org.kodein.di.compose.rememberViewModel
 
 
 /**
@@ -27,6 +38,16 @@ import com.ys.bdtp.adm.mvvm.ui.compose.Div
  */
 @Composable
 fun OfflineSide() {
+    val vm by rememberViewModel<OfflineViewModel>()
+
+    val lifecycleOwner = LocalLifecycleOwner.current
+    val projectsAware = remember(vm.projectWithBuildingsFlow, lifecycleOwner) {
+        vm.projectWithBuildingsFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
+    }
+
+    val projectsState = projectsAware.collectAsState(Data.loading())
+    val scope = rememberCoroutineScope()
+
     Column(
         modifier = Modifier
             .width(280.dp)
@@ -39,6 +60,60 @@ fun OfflineSide() {
         Button(
             modifier = Modifier.size(220.dp, 42.dp),
             onClick = {
+                scope.launch {
+                    // 下载字典
+                    projectsState.value.data?.forEach {
+                        vm.getDict(
+                            body = requestBody(
+                                userId = it.project.userId,
+                                groupCode = it.project.groupCode,
+                                projectId = it.project.projectId,
+                            ),
+                            success = {
+                                println("success: $it")
+                            },
+                            failure = {
+                                println("failure: $it")
+                            }
+                        )
+                    }
+                }
+                scope.launch {
+                    // 下载配置
+                    projectsState.value.data?.forEach {
+                        vm.getConfig(
+                            body = requestBody(
+                                userId = it.project.userId,
+                                groupCode = it.project.groupCode,
+                                projectId = it.project.projectId,
+                            ),
+                            success = {
+                                println("success: $it")
+                            },
+                            failure = {
+                                println("failure: $it")
+                            }
+                        )
+                    }
+                }
+                scope.launch {
+                    // 下载建筑与楼层数据
+                    projectsState.value.data?.forEach {
+                        vm.getBuildingsAndFloors(
+                            body = requestBody(
+                                userId = it.project.userId,
+                                groupCode = it.project.groupCode,
+                                projectId = it.project.projectId,
+                            ),
+                            success = {
+                                println("success: $it")
+                            },
+                            failure = {
+                                println("failure: $it")
+                            }
+                        )
+                    }
+                }
 
             },
             colors = ButtonDefaults.buttonColors(

+ 144 - 35
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/offline/OfflineSide2.kt

@@ -6,14 +6,21 @@ import androidx.compose.material.Button
 import androidx.compose.material.ButtonDefaults
 import androidx.compose.material.Text
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.remember
 import androidx.compose.runtime.rememberCoroutineScope
 import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
+import androidx.compose.ui.platform.LocalLifecycleOwner
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
+import androidx.lifecycle.Lifecycle
+import androidx.lifecycle.flowWithLifecycle
 import com.ys.bdtp.adm.app.theme.bgBlueColor
 import com.ys.bdtp.adm.app.theme.underColor
 import com.ys.bdtp.adm.app.theme.whiteColor
+import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.mvvm.model.State
 import com.ys.bdtp.adm.mvvm.model.vo.request.requestBody
 import com.ys.bdtp.adm.mvvm.vm.offline.OfflineViewModel
 import org.kodein.di.compose.rememberViewModel
@@ -23,9 +30,18 @@ import org.kodein.di.compose.rememberViewModel
  * 离线数据左侧UI
  */
 @Composable
-fun OfflineSide2() {
+fun OfflineSide2(projectId: String) {
     val vm by rememberViewModel<OfflineViewModel>()
     val scope = rememberCoroutineScope()
+
+
+    val lifecycleOwner = LocalLifecycleOwner.current
+    val projectsAware = remember(vm.projectWithBuildingsFlow, lifecycleOwner) {
+        vm.projectWithBuildingsFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
+    }
+
+    val projectsState = projectsAware.collectAsState(Data.loading())
+
     Column(
         modifier = Modifier
             .width(280.dp)
@@ -65,19 +81,31 @@ fun OfflineSide2() {
         Button(
             modifier = Modifier.size(220.dp, 42.dp),
             onClick = {
-                vm.getDict(
-                    body = requestBody(
-                        userId = "17337681032",
-                        groupCode = "JDKJ",
-                        projectId = "Pj1101080665",
-                    ),
-                    success = {
-                        println("success: $it")
-                    },
-                    failure = {
-                        println("failure: $it")
+                when (projectsState.value.state) {
+                    is State.Loading -> {
+
+                    }
+                    is State.Success -> {
+                        projectsState.value.data?.forEach {
+                            vm.getDict(
+                                body = requestBody(
+                                    userId = it.project.userId,
+                                    groupCode = it.project.groupCode,
+                                    projectId = it.project.projectId,
+                                ),
+                                success = {
+                                    println("success: $it")
+                                },
+                                failure = {
+                                    println("failure: $it")
+                                }
+                            )
+                        }
+                    }
+                    is State.Failure -> {
+
                     }
-                )
+                }
             },
             colors = ButtonDefaults.buttonColors(
                 contentColor = whiteColor,
@@ -91,7 +119,32 @@ fun OfflineSide2() {
         Button(
             modifier = Modifier.size(220.dp, 42.dp),
             onClick = {
-                vm.getConfig(
+                when (projectsState.value.state) {
+                    is State.Loading -> {
+
+                    }
+                    is State.Success -> {
+                        projectsState.value.data?.forEach {
+                            vm.getConfig(
+                                body = requestBody(
+                                    userId = it.project.userId,
+                                    groupCode = it.project.groupCode,
+                                    projectId = it.project.projectId,
+                                ),
+                                success = {
+                                    println("success: $it")
+                                },
+                                failure = {
+                                    println("failure: $it")
+                                }
+                            )
+                        }
+                    }
+                    is State.Failure -> {
+
+                    }
+                }
+                /*vm.getConfig(
                     body = requestBody(
                         userId = "17337681032",
                         groupCode = "JDKJ",
@@ -103,7 +156,7 @@ fun OfflineSide2() {
                     failure = {
                         println("failure: $it")
                     }
-                )
+                )*/
             },
             colors = ButtonDefaults.buttonColors(
                 contentColor = whiteColor,
@@ -117,19 +170,45 @@ fun OfflineSide2() {
         Button(
             modifier = Modifier.size(220.dp, 42.dp),
             onClick = {
-                vm.getBuildingsAndFloors(
-                    body = requestBody(
-                        userId = "17337681032",
-                        groupCode = "JDKJ",
-                        projectId = "Pj1101080665",
-                    ),
-                    success = {
-                        println("success: $it")
-                    },
-                    failure = {
-                        println("failure: $it")
+                when (projectsState.value.state) {
+                    is State.Loading -> {
+
+                    }
+                    is State.Success -> {
+                        projectsState.value.data?.forEach {
+                            vm.getBuildingsAndFloors(
+                                body = requestBody(
+                                    userId = it.project.userId,
+                                    groupCode = it.project.groupCode,
+                                    projectId = it.project.projectId,
+                                ),
+                                success = {
+                                    println("success: $it")
+                                },
+                                failure = {
+                                    println("failure: $it")
+                                }
+                            )
+                        }
+                    }
+                    is State.Failure -> {
+
                     }
-                )
+                }
+
+                /* vm.getBuildingsAndFloors(
+                     body = requestBody(
+                         userId = "17337681032",
+                         groupCode = "JDKJ",
+                         projectId = "Pj1101080665",
+                     ),
+                     success = {
+                         println("success: $it")
+                     },
+                     failure = {
+                         println("failure: $it")
+                     }
+                 )*/
             },
             colors = ButtonDefaults.buttonColors(
                 contentColor = whiteColor,
@@ -139,24 +218,54 @@ fun OfflineSide2() {
         ) {
             Text(text = "获取建筑与楼层数据")
         }
+
         Spacer(modifier = Modifier.height(32.dp))
         Button(
             modifier = Modifier.size(220.dp, 42.dp),
             onClick = {
-                vm.getMission(
+                when (projectsState.value.state) {
+                    is State.Loading -> {
+
+                    }
+                    is State.Success -> {
+                        projectsState.value.data?.forEach { project ->
+                            project.buildings.forEach { building ->
+                                vm.getMission(
+                                    body = requestBody(
+                                        userId = project.project.userId,
+                                        groupCode = project.project.groupCode,
+                                        projectId = project.project.projectId,
+                                        buildingId = building.id
+                                    ),
+                                    success = {
+                                        println("success: ")
+                                    },
+                                    failure = {
+                                        println("failure: $it")
+                                    }
+                                )
+                            }
+                        }
+                    }
+                    is State.Failure -> {
+
+                    }
+                }
+
+                /*vm.getMission(
                     body = requestBody(
-                        userId = "17337681032",
-                        groupCode = "JDKJ",
-                        projectId = "Pj1101080665",
-                        buildingId = "Bd990999000204fb9e7d54f54f43a0280b616623d91e"
+                        userId = "1468407036472936433",
+                        groupCode = "XG",
+                        projectId = "Pj5001120003",
+                        buildingId = "Bd5001120003a9b2f891b91d11ea82bfaf908bb0a852"
                     ),
                     success = {
-                        println("success: $it")
+                        println("success: ")
                     },
                     failure = {
                         println("failure: $it")
                     }
-                )
+                )*/
             },
             colors = ButtonDefaults.buttonColors(
                 contentColor = whiteColor,
@@ -173,5 +282,5 @@ fun OfflineSide2() {
 @Preview
 @Composable
 fun PreviewOfflineSide2() {
-    OfflineSide2()
+    OfflineSide2("")
 }

+ 2 - 2
app/src/main/java/com/ys/bdtp/adm/mvvm/ui/screen/task/TaskSide.kt

@@ -22,7 +22,7 @@ fun TaskSide(nav: NavHostController, projectId: String) {
         horizontalAlignment = Alignment.CenterHorizontally
     ) {
         TaskType(R.drawable.project_task_cad, "CAD核查") {
-            nav.navigate(Route.Cad)
+            nav.navigate("${Route.Cad}/$projectId")
         }
         Spacer(modifier = Modifier.height(20.dp))
         TaskType(R.drawable.project_task_space, "空间模型核查") {
@@ -34,7 +34,7 @@ fun TaskSide(nav: NavHostController, projectId: String) {
         TaskType(R.drawable.project_task_relation, "交付关系") {}
         Spacer(modifier = Modifier.height(20.dp))
         TaskType(R.drawable.project_task_offline, "离线数据") {
-            nav.navigate(Route.Offline)
+            nav.navigate("${Route.Offline}/$projectId")
         }
     }
 }

+ 28 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadRepository.kt

@@ -0,0 +1,28 @@
+package com.ys.bdtp.adm.mvvm.vm.cad
+
+import com.ys.bdtp.adm.mvvm.model.Data
+import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
+import com.ys.bdtp.adm.mvvm.model.db.relation.FloorWithCads
+import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
+import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildingAndFloors
+import com.ys.bdtp.adm.mvvm.model.nt.Api
+import com.ys.bdtp.adm.mvvm.model.toStateFlow
+import kotlinx.coroutines.flow.Flow
+
+
+class CadRepository(private val api: Api, private val db: AdmDatabase) {
+
+
+
+    /**
+     * 获取项目以及项目下的建筑和楼层
+     */
+    fun getProjectWithBuildingAndFloors(id: String): Flow<Data<ProjectWithBuildingAndFloors>> {
+        return db.projectDao().getProjectWithBuildingAndFloorsById(id).toStateFlow()
+    }
+
+    fun getFloorWithCads(id: String): Flow<Data<FloorWithCads>> {
+        return db.floorDao().getFloorWithCadsById(id).toStateFlow()
+    }
+
+}

+ 30 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/cad/CadViewModel.kt

@@ -0,0 +1,30 @@
+package com.ys.bdtp.adm.mvvm.vm.cad
+
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.ys.bdtp.adm.mvvm.model.Data
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.stateIn
+
+class CadViewModel(private val repo: CadRepository) : ViewModel() {
+
+    /**
+     * 建筑楼层一对多 Flow
+     */
+
+
+    fun getProjectWithBuildingAndFloors(id: String) = repo.getProjectWithBuildingAndFloors(id)
+        .stateIn(
+            scope = viewModelScope,
+            started = SharingStarted.WhileSubscribed(5000),
+            initialValue = Data.loading()
+        )
+
+    fun getFloorWithCads(id: String) = repo.getFloorWithCads(id)
+        .stateIn(
+            scope = viewModelScope,
+            started = SharingStarted.WhileSubscribed(5000),
+            initialValue = Data.loading()
+        )
+
+}

+ 16 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineRepository.kt

@@ -1,17 +1,22 @@
 package com.ys.bdtp.adm.mvvm.vm.offline
 
+import com.ys.bdtp.adm.mvvm.model.Data
 import com.ys.bdtp.adm.mvvm.model.nt.Fail
 import com.ys.bdtp.adm.mvvm.model.nt.request
 import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.BuildingEntity
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.EquipmentEntity
 import com.ys.bdtp.adm.mvvm.model.db.entity.task.FloorEntity
+import com.ys.bdtp.adm.mvvm.model.db.relation.BuildingWithFloors
+import com.ys.bdtp.adm.mvvm.model.db.relation.ProjectWithBuildings
 import com.ys.bdtp.adm.mvvm.model.nt.Api
+import com.ys.bdtp.adm.mvvm.model.toStateFlow
 import com.ys.bdtp.adm.mvvm.model.vo.Config
 import com.ys.bdtp.adm.mvvm.model.vo.Dict
 import com.ys.bdtp.adm.mvvm.model.vo.BuildingsAndFloors
 import com.ys.bdtp.adm.mvvm.model.vo.Mission
 import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.withContext
 
 /**
@@ -240,4 +245,15 @@ class OfflineRepository(
             )
         }
     }
+
+
+    fun getBuildingWithFloors(): Flow<Data<BuildingWithFloors>> {
+        return db.buildingDao().getBuildingWithFloors().toStateFlow()
+    }
+
+
+    fun getProjectWithBuildings(): Flow<Data<List<ProjectWithBuildings>>> {
+        return db.projectDao().getProjectWithBuildings().toStateFlow()
+    }
+
 }

+ 19 - 0
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/offline/OfflineViewModel.kt

@@ -2,11 +2,14 @@ package com.ys.bdtp.adm.mvvm.vm.offline
 
 import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
+import com.ys.bdtp.adm.mvvm.model.Data
 import com.ys.bdtp.adm.mvvm.model.nt.Fail
 import com.ys.bdtp.adm.mvvm.model.vo.Config
 import com.ys.bdtp.adm.mvvm.model.vo.Dict
 import com.ys.bdtp.adm.mvvm.model.vo.BuildingsAndFloors
 import com.ys.bdtp.adm.mvvm.model.vo.Mission
+import kotlinx.coroutines.flow.SharingStarted
+import kotlinx.coroutines.flow.stateIn
 import kotlinx.coroutines.launch
 
 /**
@@ -84,4 +87,20 @@ class OfflineViewModel(private val repo: OfflineRepository) : ViewModel() {
             )
         }
     }
+
+    val buildingWithFloorsFlow = repo.getBuildingWithFloors()
+        .stateIn(
+            scope = viewModelScope,
+            started = SharingStarted.WhileSubscribed(5000),
+            initialValue = Data.loading()
+        )
+
+    val projectWithBuildingsFlow = repo.getProjectWithBuildings()
+        .stateIn(
+            scope = viewModelScope,
+            started = SharingStarted.WhileSubscribed(5000),
+            initialValue = Data.loading()
+        )
+
+
 }

+ 1 - 5
app/src/main/java/com/ys/bdtp/adm/mvvm/vm/project/ProjectRepository.kt

@@ -1,13 +1,9 @@
 package com.ys.bdtp.adm.mvvm.vm.project
 
-import android.util.Log
 import com.ys.bdtp.adm.mvvm.model.Data
 import com.ys.bdtp.adm.mvvm.model.db.AdmDatabase
-import com.ys.bdtp.adm.mvvm.model.db.entity.UserEntity
-import com.ys.bdtp.adm.mvvm.model.db.entity.relation.UserWithProjects
+import com.ys.bdtp.adm.mvvm.model.db.relation.UserWithProjects
 import com.ys.bdtp.adm.mvvm.model.nt.Api
-import com.ys.bdtp.adm.mvvm.model.nt.Fail
-import com.ys.bdtp.adm.mvvm.model.nt.request
 import com.ys.bdtp.adm.mvvm.model.toStateFlow
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.Flow