Browse Source

feat 数字化交付编码功能完善

lihao1 3 years ago
parent
commit
6d51670d7b

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

@@ -79,7 +79,7 @@ class AdmRepository(
         return db.jobSpaceDao().getSpaceByEquipStateFloorId(id, equipState)
     }
 
-    suspend fun getBuildByObjType(objType: String): List<ObjectEntity> {
+    suspend fun getObjectByObjType(objType: String): List<ObjectEntity> {
         return db.objectDao().getObjectByObjType(objType)
     }
 

+ 18 - 2
demo/src/main/java/com/sybotan/android/demo/activities/EquipDeliveryCodeActivity.kt

@@ -22,6 +22,7 @@ import org.kodein.di.DI
 import org.kodein.di.DIAware
 import org.kodein.di.android.closestDI
 import java.util.*
+import kotlin.collections.HashMap
 
 class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
 
@@ -38,6 +39,7 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
     private lateinit var spaceId: String
     private lateinit var deviceId: String
     private lateinit var equipment: EquipmentEntity
+    private lateinit var hashmap: HashMap<String,Any>
 
     lateinit var viewModel: EquipDeliveryCodeVM
 
@@ -48,6 +50,7 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
     private lateinit var tv1: TextView
     private lateinit var tv2: TextView
     private lateinit var edt3: TextView
+    private lateinit var titleTv: TextView
     private lateinit var edt4: EditText
     private lateinit var root: LinearLayout
     val gson = Gson()
@@ -69,6 +72,7 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
         spaceId = params.getString("spaceId", "")!!
         deviceId = params.getString("deviceId", "")!!
         equipment = (params.getSerializable("equipment") as EquipmentEntity?)!!
+        hashmap = (params.getSerializable("hashmap") as HashMap<String, Any>?)!!
         backIv = findViewById(R.id.backIv)
         edt1 = findViewById(R.id.edt1)
         edt2 = findViewById(R.id.edt2)
@@ -78,6 +82,7 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
         edt3 = findViewById(R.id.edt3)
         edt4 = findViewById(R.id.edt4)
         root = findViewById(R.id.root)
+        titleTv = findViewById(R.id.titleTv)
     }
 
     private fun initListener() {
@@ -129,10 +134,12 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
                 EquipDeliveryCodeVM.EQUIP_ENTITY -> {
                     if (equipment != null || !TextUtils.isEmpty(equipment.code)) {
                         tv1.text = equipment.code
+                        titleTv.text = equipment.name
                     }
                     if (param != null) {
                         val equipEntity = param as ObjectEntity
                         tv1.text = equipEntity.classCode
+                        titleTv.text = "${equipment.name}:${equipEntity.localId}"
                         val info = gson.fromJson(equipEntity.infos, HashMap::class.java)
                         val spaceDeliveryCode = info["digitalDeliveryID"]
                         if (spaceDeliveryCode != null && !TextUtils.isEmpty(spaceDeliveryCode.toString())) {
@@ -145,6 +152,15 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
                             }
                         }
                     }
+                    if (hashmap != null && hashmap["digitalDeliveryID"]!=null &&!TextUtils.isEmpty(hashmap["digitalDeliveryID"].toString())) {
+                        val split = hashmap["digitalDeliveryID"].toString().split("-")
+                        if (split.size >= 5) {
+                            edt1.setText(split[0])
+                            edt2.setText("${split[1]}-${split[2]}")
+                            edt3.text = split[3]
+                            edt4.setText(split[4])
+                        }
+                    }
 
                 }
                 EquipDeliveryCodeVM.SPACE_ENTITY -> {
@@ -155,10 +171,10 @@ class EquipDeliveryCodeActivity : BaseActivity(), DIAware {
                         if (spaceDeliveryCode != null && !TextUtils.isEmpty(spaceDeliveryCode.toString())) {
                             tv2.text = spaceDeliveryCode.toString()
                         } else {
-                            tv2.text = "??????-RM??"
+                            tv2.text = "??????-RM???"
                         }
                     } else {
-                        tv2.text = "??????-RM??"
+                        tv2.text = "??????-RM???"
                     }
                 }
             }

+ 1 - 0
demo/src/main/java/com/sybotan/android/demo/activities/EquipDetailActivity.kt

@@ -284,6 +284,7 @@ class EquipDetailActivity : BaseActivity(), View.OnTouchListener {
             bundle.putString("spaceId", spaceId)
             bundle.putString("deviceId", if (TextUtils.isEmpty(deviceId)) uuid else deviceId)
             bundle.putSerializable("equipment", equipEntity)
+            bundle.putSerializable("hashmap", staticInfoAdapter.hashMap)
             intent.putExtra("params", bundle)
             startActivityForResult(intent, REQUEST_EQUIP_CODE)
         }

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

@@ -105,7 +105,7 @@ class SpaceDeliveryCodeActivity : BaseActivity(), DIAware {
                         } else {
                             tv1.text = "??????"
                         }
-                        titleTv.text = (floorEntity.localName)
+                        titleTv.text = ("物业分区-${floorEntity.localName}")
                     }
                 }
                 SpaceDeliveryCodeVM.SERIAL_NUMBER -> {

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

@@ -26,7 +26,7 @@ class BuildVM(app: Application, b: BaseViewModelInterface, a: BaseActivity) :
 
     fun getBuilds() {
         viewModelScope.launch {
-            val builds = repo.getBuildByObjType("building")
+            val builds = repo.getObjectByObjType("building")
             var t = ArrayList<Build>()
             for (build in builds) {
                 val floors = repo.getFloorByBuildingId(build.id, "floor")

+ 15 - 0
demo/src/main/java/com/sybotan/android/demo/viewmodel/EquipDeliveryCodeVM.kt

@@ -11,6 +11,7 @@ import com.framework.mvvm.model.repository.AdmRepository
 import com.google.gson.Gson
 import com.sybotan.android.demo.activities.BaseActivity
 import com.sybotan.android.demo.retrofit.BaseViewModelInterface
+import com.sybotan.android.demo.tools.ToastUtils
 import com.zbar.lib.CaptureActivity
 import kotlinx.coroutines.launch
 import org.kodein.di.DI
@@ -47,6 +48,20 @@ class EquipDeliveryCodeVM(
 
     fun insSerialNumber(deviceId: String, content1: String, content2: String, content3: String, content4: String) {
         viewModelScope.launch {
+
+            val equips = repo.getObjectByObjType("equipment")
+            for (equip in equips) {
+                if (equip.infos != null && !equip.infos!!.asJsonObject.keySet().isEmpty()) {
+                    val hashMap = gson.fromJson(equip.infos, HashMap::class.java) as HashMap<String, Any>
+                    if (hashMap != null && hashMap["digitalDeliveryID"] != null && !TextUtils.isEmpty(hashMap["digitalDeliveryID"].toString())) {
+                        if (hashMap["digitalDeliveryID"].toString() == "$content1-$content2-$content3-$content4" && equip.id != deviceId) {
+                            ToastUtils.showMyToast("数字化交付编码重复!")
+                            return@launch
+                        }
+                    }
+                }
+            }
+
             val equipEntity = repo.getObject(deviceId)
             val code = "$content1-$content2-$content3-$content4"
             if (equipEntity != null) {

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

@@ -163,7 +163,9 @@ class EquipDetailVM(
                 localId = hashMap["localName"].toString()
             }
             hashMap!!.put("equipContent", equipContent)
-            hashMap!!.put("equipPhoto", gson.toJson(beans))
+            var photos= ArrayList<Photos>()
+            beans.filter { bean -> bean.itemType != 1 }.forEach { photos.add(it) }
+            hashMap!!.put("equipPhoto", gson.toJson(photos))
             hashMap!!.put("equipCheck", checked)
             val z = PointZ()
             z.x = position.x.toFloat()

+ 13 - 0
demo/src/main/java/com/sybotan/android/demo/viewmodel/SpaceDeliveryCodeVM.kt

@@ -11,6 +11,7 @@ import com.framework.mvvm.model.repository.AdmRepository
 import com.google.gson.Gson
 import com.sybotan.android.demo.activities.BaseActivity
 import com.sybotan.android.demo.retrofit.BaseViewModelInterface
+import com.sybotan.android.demo.tools.ToastUtils
 import com.zbar.lib.CaptureActivity
 import kotlinx.coroutines.launch
 import org.kodein.di.DI
@@ -67,6 +68,18 @@ class SpaceDeliveryCodeVM(
 
     fun insSerialNumber(spaceId: String, content1: String, content2: String) {
         viewModelScope.launch {
+            val spaces = repo.getObjectByObjType("space")
+            for (space in spaces) {
+                if (space.infos != null && !space.infos!!.asJsonObject.keySet().isEmpty()) {
+                    val hashMap = gson.fromJson(space.infos, HashMap::class.java) as HashMap<String, Any>
+                    if (hashMap != null && hashMap["digitalDeliveryID"] != null && !TextUtils.isEmpty(hashMap["digitalDeliveryID"].toString())) {
+                        if (hashMap["digitalDeliveryID"].toString() == "$content1-RM$content2" && space.id != spaceId) {
+                            ToastUtils.showMyToast("数字化交付编码重复!")
+                            return@launch
+                        }
+                    }
+                }
+            }
             val spaceEntity = repo.getObject(spaceId)
             if (spaceEntity != null) {
                 val hashMap = gson.fromJson(spaceEntity.infos, HashMap::class.java) as HashMap<String, Any>