소스 검색

修复锁定站地图潜在的数组问题;补充App初始化时,存在工作模式钥匙,处理钥匙内工作票数据的逻辑

Frankensteinly 7 달 전
부모
커밋
0196e904ba

+ 52 - 7
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -1,6 +1,7 @@
 package com.grkj.iscs
 
 import android.bluetooth.BluetoothGatt
+import android.content.Context
 import androidx.appcompat.app.AppCompatActivity
 import androidx.lifecycle.MutableLiveData
 import com.clj.fastble.BleManager
@@ -34,6 +35,7 @@ import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
 import com.grkj.iscs.model.bo.DeviceTakeUpdateBO
+import com.grkj.iscs.model.bo.UpdateKeyReturnBO
 import com.grkj.iscs.model.bo.WorkTicketGetBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
@@ -1111,16 +1113,21 @@ object BusinessManager {
                 updateList.add(updateVO)
             }
 
-            // 上报点位钥匙绑定
-            NetApi.updateLockPointBatch(updateList) { isSuccess ->
-                data.taskCode?.toLong()?.let {
-                    mEventBus.postValue(MsgEvent(MSG_EVENT_UPDATE_TICKET_PROGRESS, UpdateTicketProgressMsg(it)))
+            if (CAN_RETURN) {
+                // 上报点位钥匙绑定
+                NetApi.updateLockPointBatch(updateList) { isSuccess ->
+                    data.taskCode?.toLong()?.let {
+                        mEventBus.postValue(MsgEvent(MSG_EVENT_UPDATE_TICKET_PROGRESS, UpdateTicketProgressMsg(it)))
+                    }
                 }
-            }
 
-            // 上报钥匙归还
-            NetApi.updateKeyReturn(data.taskCode?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()) { isSuccess ->
+                // 上报钥匙归还
+                NetApi.updateKeyReturn(data.taskCode?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()) { isSuccess ->
 
+                }
+            } else {
+                SPUtils.saveUpdateLockPoint(MyApplication.instance!!, updateList)
+                SPUtils.saveUpdateKeyReturn(MyApplication.instance!!, UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!))
             }
         }
     }
@@ -1263,4 +1270,42 @@ object BusinessManager {
             }
         }
     }
+
+    fun submitKeyData(context: Context) {
+        if (!CAN_RETURN) return
+        val updateList = SPUtils.getUpdateLockPoint(context)
+        if (updateList.isNotEmpty()) {
+            NetApi.updateLockPointBatch(updateList) { isSuccess ->
+                if (isSuccess) {
+                    SPUtils.clearUpdateLockPoint(context)
+                }
+            }
+        }
+
+        val returnList = SPUtils.getUpdateKeyReturn(context)
+        if (returnList.isEmpty()) {
+            return
+        }
+        val itemsToRemove = returnList.toList()
+        var count = 0
+        itemsToRemove.forEach { itData ->
+            NetApi.updateKeyReturn(
+                itData.ticketId, itData.keyNfc, context.serialNo()
+            ) { isSuccess ->
+                count++
+                if (isSuccess) {
+                    returnList.remove(itData)
+                }
+                if (count == itemsToRemove.size) {
+                    if (returnList.isEmpty()) {
+                        SPUtils.clearUpdateKeyReturn(context)
+                    } else {
+                        returnList.forEach {
+                            SPUtils.saveUpdateKeyReturn(context, it)
+                        }
+                    }
+                }
+            }
+        }
+    }
 }

+ 6 - 0
app/src/main/java/com/grkj/iscs/model/bo/UpdateKeyReturnBO.kt

@@ -0,0 +1,6 @@
+package com.grkj.iscs.model.bo
+
+data class UpdateKeyReturnBO(
+    val ticketId: Long,
+    val keyNfc: String
+)

+ 33 - 27
app/src/main/java/com/grkj/iscs/util/BitmapUtil.kt

@@ -56,40 +56,46 @@ object BitmapUtil {
         return stream.toByteArray()
     }
 
-    fun loadBitmapFromUrl(ctx: Context, url: String, reqWidth: Int? = null, reqHeight: Int? = null, callback: (Bitmap?) -> Unit) {
+    fun loadBitmapFromUrl(
+        ctx: Context,
+        url: String,
+        reqWidth: Int? = null,
+        reqHeight: Int? = null,
+        callback: (Bitmap?) -> Unit
+    ) {
         try {
             val builder = Glide.with(ctx)
                 .asBitmap()
                 .load(url)
-                if (reqWidth != null && reqHeight != null) {
-                    builder.override(reqWidth, reqHeight)
-                }
-                builder.listener(object : RequestListener<Bitmap> {
-                    override fun onLoadFailed(
-                        e: GlideException?,
-                        model: Any?,
-                        target: Target<Bitmap>?,
-                        isFirstResource: Boolean
-                    ): Boolean {
-                        Executor.runOnMain {
-                            callback(null)
-                        }
-                        return false
+            if (reqWidth != null && reqHeight != null) {
+                builder.override(reqWidth, reqHeight)
+            }
+            builder.listener(object : RequestListener<Bitmap> {
+                override fun onLoadFailed(
+                    e: GlideException?,
+                    model: Any?,
+                    target: Target<Bitmap>?,
+                    isFirstResource: Boolean
+                ): Boolean {
+                    Executor.runOnMain {
+                        callback(null)
                     }
+                    return false
+                }
 
-                    override fun onResourceReady(
-                        resource: Bitmap?,
-                        model: Any?,
-                        target: Target<Bitmap>?,
-                        dataSource: DataSource?,
-                        isFirstResource: Boolean
-                    ): Boolean {
-                        Executor.runOnMain {
-                            callback(resource)
-                        }
-                        return false
+                override fun onResourceReady(
+                    resource: Bitmap?,
+                    model: Any?,
+                    target: Target<Bitmap>?,
+                    dataSource: DataSource?,
+                    isFirstResource: Boolean
+                ): Boolean {
+                    Executor.runOnMain {
+                        callback(resource)
                     }
-                })
+                    return false
+                }
+            })
                 .submit()
         } catch (e: Exception) {
             e.printStackTrace()

+ 70 - 0
app/src/main/java/com/grkj/iscs/util/SPUtils.kt

@@ -1,12 +1,19 @@
 package com.grkj.iscs.util
 
 import android.content.Context
+import com.google.gson.Gson
+import com.google.gson.reflect.TypeToken
+import com.grkj.iscs.model.bo.UpdateKeyReturnBO
 import com.grkj.iscs.model.vo.card.CardInfoRespVO
+import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
+import com.grkj.iscs.util.log.LogUtil
+import java.util.Collections
 
 object SPUtils {
 
     private const val SP_NAME = "iscs"
     private const val SP_CONFIG_NAME = "iscs_config"
+    private const val SP_DATA = "iscs_data"
 
     private const val KEY_LOGIN_USER_CARD_ID = "card_id"
     private const val KEY_LOGIN_USER_CARD_CODE = "card_code"
@@ -20,6 +27,9 @@ object SPUtils {
     private const val KEY_DOCK_CONFIG = "dock_config"
     private const val KEY_PORT_CONFIG = "port_config"
 
+    private const val KEY_DATA_UPDATE_LOCK_POINT = "update_lock_point"
+    private const val KEY_DATA_UPDATE_KEY_RETURN = "update_key_return"
+
     fun getLoginUser(context: Context): CardInfoRespVO? {
         val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
         if (sp.getString(KEY_LOGIN_USER_CARD_NFC, null) == null) {
@@ -102,4 +112,64 @@ object SPUtils {
         val sp = context.getSharedPreferences(SP_CONFIG_NAME, Context.MODE_PRIVATE)
         return sp.getString(KEY_PORT_CONFIG, null)
     }
+
+    fun saveUpdateLockPoint(context: Context, list: MutableList<LockPointUpdateReqVO>) {
+        val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
+        val edit = sp.edit()
+        val tempList = getUpdateLockPoint(context)
+        tempList.addAll(list)
+        edit.putString(KEY_DATA_UPDATE_LOCK_POINT, Gson().toJson(tempList))
+        edit.apply()
+    }
+
+    fun getUpdateLockPoint(context: Context): MutableList<LockPointUpdateReqVO> {
+        val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
+        val listJson = sp.getString(KEY_DATA_UPDATE_LOCK_POINT, null)
+        try {
+            val tempList: MutableList<LockPointUpdateReqVO> = Gson().fromJson(
+                listJson,
+                object : TypeToken<MutableList<LockPointUpdateReqVO>>() {}.type
+            )
+            return tempList
+        } catch (e: Exception) {
+            LogUtil.e("${e.message}")
+            return Collections.emptyList()
+        }
+    }
+
+    fun clearUpdateLockPoint(context: Context) {
+        val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
+        val edit = sp.edit()
+        edit.putString(KEY_DATA_UPDATE_LOCK_POINT, null)
+        edit.apply()
+    }
+
+    fun saveUpdateKeyReturn(context: Context, returnBO: UpdateKeyReturnBO) {
+        val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
+        val edit = sp.edit()
+        val tempList = getUpdateKeyReturn(context)
+        tempList.add(returnBO)
+        edit.putString(KEY_DATA_UPDATE_KEY_RETURN, Gson().toJson(tempList))
+        edit.apply()
+    }
+
+    fun getUpdateKeyReturn(context: Context): MutableList<UpdateKeyReturnBO> {
+        val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
+        val listJson = sp.getString(KEY_DATA_UPDATE_KEY_RETURN, null)
+        try {
+            val tempList: MutableList<UpdateKeyReturnBO> =
+                Gson().fromJson(listJson, object : TypeToken<UpdateKeyReturnBO>() {}.type)
+            return tempList
+        } catch (e: Exception) {
+            LogUtil.e("${e.message}")
+            return Collections.emptyList()
+        }
+    }
+
+    fun clearUpdateKeyReturn(context: Context) {
+        val sp = context.getSharedPreferences(SP_DATA, Context.MODE_PRIVATE)
+        val edit = sp.edit()
+        edit.putString(KEY_DATA_UPDATE_KEY_RETURN, null)
+        edit.apply()
+    }
 }

+ 1 - 0
app/src/main/java/com/grkj/iscs/view/activity/LoginActivity.kt

@@ -65,6 +65,7 @@ class LoginActivity : BaseMvpActivity<ILoginView, LoginPresenter, ActivityLoginB
                         intent.putExtra("userInfo", userInfoRespVO)
                     }
                     startActivity(intent)
+                    BusinessManager.submitKeyData(this@LoginActivity)
                 }
             }
         }

+ 3 - 1
app/src/main/java/com/grkj/iscs/view/fragment/StepFragment.kt

@@ -235,9 +235,11 @@ class StepFragment(val goBack: () -> Unit, val changePage: (PageChangeBO) -> Uni
                                             mMachineryDetail?.pointIdList?.contains(itPoint.entityId) == true
                                         )
                                     )
+                                    if (mStationList.size == itMapInfo.pointList.size) {
+                                        mBinding?.mapview?.loadMap(it)
+                                    }
                                 }
                             }
-                            mBinding?.mapview?.loadMap(it)
                         }
                     }
                 }