Browse Source

@task: unUpload data

bai 3 years ago
parent
commit
464cb11a57

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/FileDao.kt

@@ -31,4 +31,7 @@ interface FileDao {
 
     @Delete
     suspend fun delFile(file: FileEntity)
+
+    @Query("select count(*) from file where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
 }

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/JobSpaceDao.kt

@@ -37,4 +37,7 @@ interface JobSpaceDao {
 
     @Delete
     suspend fun delSpace(space: JobSpaceEntity)
+
+    @Query("select count(*) from job_space where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
 }

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

@@ -98,4 +98,7 @@ interface ObjectDao {
     // @Transaction
     // @Query("select * from object")
     // fun getObjectAndInfosWithOutlines() : List<ObjectAndInfosWithOutlines>
+
+    @Query("select count(*) from object where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
 }

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/PipeDao.kt

@@ -41,4 +41,7 @@ interface PipeDao {
 
     @Delete
     suspend fun delConfig(config: PipeConfigEntity)
+
+    @Query("select count(*) from pipe where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
 }

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/ProblemArchDao.kt

@@ -35,4 +35,7 @@ interface ProblemArchDao {
     @Delete
     suspend fun delProblem(problem: ProblemArchEntity)
 
+    @Query("select count(*) from problem_arch where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
+
 }

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/ProblemEquipDao.kt

@@ -31,4 +31,7 @@ interface ProblemEquipDao {
 
     @Delete
     suspend fun delProblem(config: ProblemEquipEntity)
+
+    @Query("select count(*) from problem_equip where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
 }

+ 4 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/QrCodeDao.kt

@@ -31,4 +31,8 @@ interface QrCodeDao {
 
     @Delete
     suspend fun delQrCode(qrCode: QrCodeEntity)
+
+    @Query("select count(*) from qr_code where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
+
 }

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/RelationDao.kt

@@ -49,4 +49,7 @@ interface RelationDao {
     @Delete
     suspend fun delRelation(relation: RelationEntity)
 
+    @Query("select count(*) from relation where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
+
 }

+ 3 - 0
demo/src/main/java/com/framework/mvvm/model/db/dao/ServeAreaDao.kt

@@ -26,4 +26,7 @@ interface ServeAreaDao {
 
     @Insert(onConflict = OnConflictStrategy.REPLACE)
     suspend fun insertArea(areas: ServeAreaEntity)
+
+    @Query("select count(*) from serve_area where project_id = :projectId and (state = 0 or state = 1)")
+    suspend fun countUnDone(projectId: String): Int
 }

+ 40 - 0
demo/src/main/java/com/framework/mvvm/model/repository/AdmRepository.kt

@@ -550,6 +550,46 @@ class AdmRepository(
         }
     }
 
+    // 项目未完成数量
+    suspend fun unUploadTaskByProjectId(projectId: String): Int {
+        return try {
+            val pipeDao = db.pipeDao()
+            val fileDao = db.fileDao()
+            val spaceDao = db.jobSpaceDao()
+            val qrCodeDao = db.qrCodeDao()
+            val objectDao = db.objectDao()
+            val relationDao = db.relationDao()
+            val problemArchDao = db.problemArchDao()
+            val problemEquipDao = db.problemEquipDao()
+            val serveAreaDao = db.serveAreaDao()
+
+            val pipes = pipeDao.countUnDone(projectId)
+
+            val files = fileDao.countUnDone(projectId)
+
+            val spaces = spaceDao.countUnDone(projectId)
+
+            val qrCodes = qrCodeDao.countUnDone(projectId)
+            // 只计算,有问题
+            val objects = objectDao.countUnDone(projectId)
+
+            val relations = relationDao.countUnDone(projectId)
+
+            val problemArchs = problemArchDao.countUnDone(projectId)
+
+            val problemEquips = problemEquipDao.countUnDone(projectId)
+
+            val areas = serveAreaDao.countUnDone(projectId)
+
+            pipes + files + spaces + qrCodes + objects + relations + problemArchs + problemEquips + areas
+
+        } catch (e: Exception) {
+            Log.d("getNoDoneBuildings", "$e")
+            -1
+        }
+
+    }
+
     /**
      *  获取文件信息
      */

+ 4 - 0
demo/src/main/java/com/framework/mvvm/mv/AdmViewModel.kt

@@ -288,4 +288,8 @@ class AdmViewModel(private val repository: AdmRepository) : ViewModel() {
     suspend fun getCurrentUser(): UserEntity {
         return repository.getUserByState(1)
     }
+
+    suspend fun getNoDoneTaskByProjectId(projectId: String): Int {
+        return repository.unUploadTaskByProjectId(projectId)
+    }
 }

+ 35 - 8
demo/src/main/java/com/sybotan/android/demo/activities/PocActivity.kt

@@ -3,14 +3,11 @@ package com.sybotan.android.demo.activities
 import android.Manifest
 import android.app.AlertDialog
 import android.app.ProgressDialog
-import android.content.Intent
 import android.content.SharedPreferences
 import android.content.pm.PackageManager
-import android.net.Uri
+import android.graphics.Color
 import android.os.Build
 import android.os.Bundle
-import android.os.Environment
-import android.provider.Settings
 import android.widget.Button
 import android.widget.TextView
 import androidx.annotation.RequiresApi
@@ -62,10 +59,13 @@ class PocActivity : BaseActivity(), DIAware {
 
     private lateinit var version: TextView
 
+    private lateinit var unUploadTv: TextView
+    private lateinit var unUploadLabelTv: TextView
+
     // 测试用,后期动态设置
-   /* private val request =
-        AdmRequest(userId = "admjd", projectId = "Pj9909990002", groupCode = "JD")
-*/
+    /* private val request =
+         AdmRequest(userId = "admjd", projectId = "Pj9909990002", groupCode = "JD")
+ */
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_poc)
@@ -85,10 +85,25 @@ class PocActivity : BaseActivity(), DIAware {
         scene3DBtn = findViewById(R.id.scene3DBtn)
 
         version = findViewById(R.id.version)
+        unUploadTv = findViewById(R.id.unUploadTv)
+        unUploadLabelTv = findViewById(R.id.unUploadLabelTv)
 
         space3DBtn.setOnClickListener { startActivity<Space3DActivity>() }
         scene3DBtn.setOnClickListener { startActivity<Scene3DActivity>() }
 
+        lifecycleScope.launchWhenStarted {
+            val unUploadNum = mVm.getNoDoneTaskByProjectId(projectId)
+            unUploadTv.text = "$unUploadNum"
+            if (unUploadNum > 0) {
+                unUploadLabelTv.setTextColor(Color.RED)
+                unUploadTv.setTextColor(Color.RED)
+            } else {
+                unUploadLabelTv.setTextColor(resources.getColor(R.color.black_1F2429))
+                unUploadTv.setTextColor(resources.getColor(R.color.black_1F2429))
+            }
+
+        }
+
         downloadBtn.setOnClickListener {
             mVm.downloadBuilding(request, sp) {
                 // ToastUtils.showMyToast("下载完成")
@@ -115,6 +130,19 @@ class PocActivity : BaseActivity(), DIAware {
                         dialog.dismiss()
                     }.create()
                 dialog.show()
+
+                lifecycleScope.launch {
+                    val unUploadNum = mVm.getNoDoneTaskByProjectId(projectId)
+                    unUploadTv.text = "$unUploadNum"
+                    if (unUploadNum > 0) {
+                        unUploadLabelTv.setTextColor(Color.RED)
+                        unUploadTv.setTextColor(Color.RED)
+                    } else {
+                        unUploadLabelTv.setTextColor(resources.getColor(R.color.black_1F2429))
+                        unUploadTv.setTextColor(resources.getColor(R.color.black_1F2429))
+                    }
+                }
+
             }
         }
 
@@ -231,6 +259,5 @@ class PocActivity : BaseActivity(), DIAware {
                 1
             )
         }
-
     }
 }

+ 33 - 8
demo/src/main/res/layout/activity_poc.xml

@@ -109,13 +109,12 @@
         android:id="@+id/uploadBtn"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginTop="16dp"
+        android:layout_marginStart="32dp"
         android:text="上传建筑数据"
         android:textSize="18sp"
-        app:layout_constraintEnd_toEndOf="@+id/downloadBtn"
-        app:layout_constraintHorizontal_bias="0.0"
-        app:layout_constraintStart_toStartOf="@+id/downloadBtn"
-        app:layout_constraintTop_toBottomOf="@+id/downloadBtn" />
+        app:layout_constraintBottom_toBottomOf="@+id/unUploadTv"
+        app:layout_constraintStart_toEndOf="@+id/unUploadTv"
+        app:layout_constraintTop_toTopOf="@+id/unUploadTv" />
 
     <TextView
         android:id="@+id/version"
@@ -124,9 +123,9 @@
         android:layout_marginTop="16dp"
         android:text=""
         android:textSize="12sp"
-        app:layout_constraintEnd_toEndOf="@+id/uploadBtn"
-        app:layout_constraintStart_toStartOf="@+id/uploadBtn"
-        app:layout_constraintTop_toBottomOf="@+id/uploadBtn" />
+        app:layout_constraintEnd_toEndOf="@+id/unUploadTv"
+        app:layout_constraintStart_toStartOf="@+id/unUploadTv"
+        app:layout_constraintTop_toBottomOf="@+id/unUploadTv" />
 
     <Button
         android:id="@+id/dictBtn"
@@ -189,5 +188,31 @@
         app:layout_constraintStart_toStartOf="@+id/configBtn"
         app:layout_constraintTop_toBottomOf="@+id/configBtn" />
 
+    <TextView
+        android:id="@+id/unUploadLabelTv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="32dp"
+        android:text="未上传数据: "
+        android:textColor="@color/black_1F2429"
+        android:textSize="18sp"
+        app:layout_constraintBottom_toBottomOf="@+id/unUploadTv"
+        app:layout_constraintEnd_toStartOf="@+id/unUploadTv"
+        app:layout_constraintTop_toTopOf="@+id/unUploadTv"
+        app:layout_constraintVertical_bias="0.0" />
+
+    <TextView
+        android:id="@+id/unUploadTv"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="36dp"
+        android:hint="0"
+        android:textColor="@color/black_1F2429"
+        android:textSize="18sp"
+        app:layout_constraintEnd_toEndOf="@+id/downloadBtn"
+        app:layout_constraintHorizontal_bias="0.493"
+        app:layout_constraintStart_toStartOf="@+id/downloadBtn"
+        app:layout_constraintTop_toBottomOf="@+id/downloadBtn" />
+
 
 </androidx.constraintlayout.widget.ConstraintLayout>