Pārlūkot izejas kodu

refactor(修改):
- 修复断网情况锁发错的问题

周文健 5 mēneši atpakaļ
vecāks
revīzija
95af12ac41

+ 21 - 8
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -68,6 +68,10 @@ import com.grkj.iscs.view.activity.LoginActivity
 import com.grkj.iscs.view.base.BaseActivity
 import com.grkj.iscs.view.dialog.TipDialog
 import com.sik.sikcore.activity.ActivityTracker
+import com.sik.sikcore.extension.getMMKVData
+import com.sik.sikcore.extension.saveMMKVData
+import com.sik.sikcore.extension.toJson
+import com.tencent.mmkv.MMKV
 import pub.devrel.easypermissions.AfterPermissionGranted
 
 /**
@@ -1445,6 +1449,9 @@ object BusinessManager {
         }
     }
 
+    /**
+     * 获取当前钥匙的状态
+     */
     fun getCurrentStatus(
         from: Int,
         bleDevice: BleDevice,
@@ -1781,14 +1788,10 @@ object BusinessManager {
                                 if (isSuccess == false) {
                                     LogUtil.e("Lock take report fail")
                                     ToastUtils.tip(R.string.lock_take_report_fail)
-                                    if (mDeviceTakeList.any { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == info.ticketId }) {
-//                                        sendLoadingEventMsg(
-//                                            MyApplication.instance?.applicationContext?.getString(
-//                                                R.string.take_out_lock_tip,
-//                                                mDeviceTakeList.count { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == info.ticketId })
-//                                        )
-                                        sendLoadingEventMsg(null, false)
-                                    }
+                                    SPUtils.saveTicketTakeLockException(info.ticketId)
+                                    mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_LOCK && it.nfc == info.nfc }
+                                    mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_KEY &&  it.ticketId == info.ticketId }
+                                    sendLoadingEventMsg(null, false)
                                     return@runOnMain
                                 }
                                 // 检查是不是要发钥匙了
@@ -1807,6 +1810,10 @@ object BusinessManager {
                                     LogUtil.i("All locks are taken")
                                     sendLoadingEventMsg(null, false)
                                 }
+                                if (SPUtils.getTicketTakeLockException(info.ticketId)) {
+                                    ToastUtils.tip(R.string.current_ticket_report_lock_take_exception_tip)
+                                    return@runOnMain
+                                }
                                 // 检查有无当前工作票的钥匙
                                 mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == info.ticketId }
                                     ?.let { itKey ->
@@ -1819,6 +1826,9 @@ object BusinessManager {
         }
     }
 
+    /**
+     * 分配钥匙
+     */
     private fun handleGiveKey(deviceTakeUpdateBO: DeviceTakeUpdateBO) {
         getCurrentStatus(
             2,
@@ -1862,6 +1872,9 @@ object BusinessManager {
         }
     }
 
+    /**
+     * 根据当前模式进行处理
+     */
     private fun handleCurrentMode(currentModeMsg: CurrentModeMsg) {
         when (currentModeMsg.mode) {
             // 工作模式

+ 2 - 1
app/src/main/java/com/grkj/iscs/MyApplication.kt

@@ -34,7 +34,8 @@ class MyApplication : Application() {
         NetHttpManager.getInstance().initCtx(this)
 
         BusinessManager.initMsgEventBus()
-        ArcSoftUtil.checkActiveStatus(this)
+        //todo 模拟器用不了
+//        ArcSoftUtil.checkActiveStatus(this)
 
         SIKCore.init(this)
 

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

@@ -40,6 +40,8 @@ object SPUtils {
 
     private const val KEY_SYSTEM_ATTRIBUTE = "system_attribute"
 
+    private const val KEY_TICKET_TAKE_LOCK_EXCEPTION = "ticket_take_lock_exception"
+
     fun getLoginUser(context: Context): LoginUserBO? {
         val sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE)
         if (sp.getLong(KEY_LOGIN_USER_USER_ID, -1) == -1L) {
@@ -248,4 +250,25 @@ object SPUtils {
     fun returnKey(ticketId: Long) {
         MMKV.defaultMMKV().remove("${ticketId}_TakeKey")
     }
+
+    /**
+     * 保存作业获取锁异常状态
+     */
+    fun saveTicketTakeLockException(ticketId: Long) {
+        "${ticketId}${KEY_TICKET_TAKE_LOCK_EXCEPTION}".saveMMKVData(true)
+    }
+
+    /**
+     * 获取作业获取锁异常状态
+     */
+    fun getTicketTakeLockException(ticketId: Long): Boolean {
+        return "${ticketId}${KEY_TICKET_TAKE_LOCK_EXCEPTION}".getMMKVData(false)
+    }
+
+    /**
+     * 重置作业获取锁异常状态
+     */
+    fun resetTicketTakeLockException(ticketId: Long) {
+        MMKV.defaultMMKV().remove("${ticketId}${KEY_TICKET_TAKE_LOCK_EXCEPTION}")
+    }
 }

+ 1 - 0
app/src/main/java/com/grkj/iscs/view/presenter/JobProgressPresenter.kt

@@ -104,6 +104,7 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
      * 上锁人上锁流程
      */
     fun handleLockProcess(ticketId: Long) {
+        SPUtils.resetTicketTakeLockException(ticketId)
         NetApi.checkBeforeAction(ticketId, true) {
             if (!it) {
                 LogUtil.w("handleLockProcess check false")

+ 1 - 0
app/src/main/res/values-en/strings.xml

@@ -334,4 +334,5 @@
     <string name="all_point_have_other_job_not_finish">all point have other job not finish,do you want to continue?</string>
     <string name="lock_is_not_enough_stop_issue_ticket">lock is not enough, stop issue ticket</string>
     <string name="ticket_lost">{"msg":"作业票数据丢失啦!","code":500}</string>
+    <string name="current_ticket_report_lock_take_exception_tip">current ticket report lock take exception, please return lock</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh/strings.xml

@@ -334,4 +334,5 @@
     <string name="all_point_have_other_job_not_finish">所有隔离点存在其他作业未完成,是否继续拆锁恢复?</string>
     <string name="lock_is_not_enough_stop_issue_ticket">锁具数量不足,停止下发作业票</string>
     <string name="ticket_lost">{"msg":"作业票数据丢失啦!","code":500}</string>
+    <string name="current_ticket_report_lock_take_exception_tip">当前作业挂锁上报异常,请归还挂锁</string>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -334,4 +334,5 @@
     <string name="all_point_have_other_job_not_finish">所有隔离点存在其他作业未完成,是否继续拆锁恢复?</string>
     <string name="lock_is_not_enough_stop_issue_ticket">锁具数量不足,停止下发作业票</string>
     <string name="ticket_lost">{"msg":"作业票数据丢失啦!","code":500}</string>
+    <string name="current_ticket_report_lock_take_exception_tip">当前作业挂锁上报异常,请归还挂锁</string>
 </resources>