Bläddra i källkod

refactor(更新) :
- 增加还钥匙的时候判断锁rfid和点位rfid是否存在重复的问题

周文健 5 månader sedan
förälder
incheckning
8168a0a30c

+ 118 - 154
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -94,8 +94,7 @@ object BusinessManager {
 
     // Modbus数据页面监听
     class DeviceListener(
-        val key: Any,
-        val callBack: (DockBean) -> Unit
+        val key: Any, val callBack: (DockBean) -> Unit
     )
 
     private val listeners = ArrayList<DeviceListener>()
@@ -131,8 +130,7 @@ object BusinessManager {
                     Executor.runOnMain {
                         val loadingMsg = it.data as LoadingMsg
                         (ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(
-                            loadingMsg.isShow,
-                            loadingMsg.loadingText
+                            loadingMsg.isShow, loadingMsg.loadingText
                         )
                     }
                 }
@@ -170,14 +168,10 @@ object BusinessManager {
                                         ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
                                     keyBean.isReady = false
                                     ModBusController.controlKeyBuckle(
-                                        true,
-                                        keyBean.isLeft,
-                                        dock?.addr
+                                        true, keyBean.isLeft, dock?.addr
                                     )
                                     ModBusController.updateKeyReadyStatus(
-                                        it.data.bleBean.bleDevice.mac,
-                                        false,
-                                        1
+                                        it.data.bleBean.bleDevice.mac, false, 1
                                     )
                                     ToastUtils.tip(R.string.take_out_key)
                                 }
@@ -192,9 +186,7 @@ object BusinessManager {
                         2 -> {
                             if (it.data.res == 1) {
                                 ModBusController.updateKeyReadyStatus(
-                                    it.data.bleBean.bleDevice.mac,
-                                    true,
-                                    2
+                                    it.data.bleBean.bleDevice.mac, true, 2
                                 )
                                 // 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
                                 Executor.delayOnMain(500) {
@@ -253,15 +245,11 @@ object BusinessManager {
             withContext(Dispatchers.Default) {
                 val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
                 getOneKey(
-                    slotsPage?.records
-                        ?.filter {
-                            it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue &&
-                                    it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
-                        }?.toMutableList() ?: mutableListOf(),
-                    (keyPage?.records
-                        ?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
-                        ?.map { it.keyNfc ?: "" }
-                        ?.toMutableList() ?: mutableListOf()),
+                    slotsPage?.records?.filter {
+                        it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
+                    }?.toMutableList() ?: mutableListOf(),
+                    (keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
+                        ?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()),
                     mutableListOf(exceptKeyMac)
                 )
             }
@@ -351,31 +339,26 @@ object BusinessManager {
                         if (keyBean.isExist) {
                             // 放回钥匙,读取rfid
                             ModBusController.readKeyRfid(
-                                dockBean.addr,
-                                if (keyBean.isLeft) 0 else 1
+                                dockBean.addr, if (keyBean.isLeft) 0 else 1
                             ) { isLeft, res ->
                                 ModBusController.controlKeyCharge(
-                                    true,
-                                    keyBean.isLeft,
-                                    dockBean.addr
+                                    true, keyBean.isLeft, dockBean.addr
                                 )
                                 if (res.size < 11) {
                                     LogUtil.e("Key rfid error")
                                     return@readKeyRfid
                                 }
-                                val rfid = res.copyOfRange(3, 11).toHexStrings(false)
-                                    .removeLeadingZeros()
+                                val rfid =
+                                    res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
                                 ThreadUtils.runOnIO {
                                     val slotStatus =
                                         async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
                                     val slotType =
                                         async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
-                                    val slotsPageReq =
-                                        async { getSlotsPage() }
+                                    val slotsPageReq = async { getSlotsPage() }
                                     val keyStatusReq =
                                         async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_KEY_STATUS) }
-                                    val keyPageReq =
-                                        async { getKeyPage() }
+                                    val keyPageReq = async { getKeyPage() }
                                     var keyStatus = keyStatusReq.await()
                                     var keyData = keyPageReq.await()
                                     val slotsPage = slotsPageReq.await()
@@ -391,13 +374,10 @@ object BusinessManager {
                                                 R.string.key_exception_tag
                                             )
                                         )
-                                    } else if (slotsPage?.records
-                                            ?.filter {
-                                                it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue &&
-                                                        it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
-                                            }
-                                            ?.find { it.row?.toInt() == dockBean.row && it.col?.toInt() == (dockBean.col + (if (keyBean.isLeft) 0 else 1) * 2) } != null
-                                    ) {
+                                    } else if (slotsPage?.records?.filter {
+                                            it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
+                                        }
+                                            ?.find { it.row?.toInt() == dockBean.row && it.col?.toInt() == (dockBean.col + (if (keyBean.isLeft) 0 else 1) * 2) } != null) {
                                         ToastUtils.tip(
                                             MyApplication.instance?.applicationContext!!.getString(
                                                 R.string.slot_exception_tag
@@ -405,27 +385,19 @@ object BusinessManager {
                                         )
                                     } else {
                                         ModBusController.updateKeyRfid(
-                                            dockBean.addr,
-                                            keyBean.isLeft,
-                                            rfid
+                                            dockBean.addr, keyBean.isLeft, rfid
                                         )
                                         // 放回钥匙,上锁
                                         ModBusController.controlKeyBuckle(
-                                            false,
-                                            keyBean.isLeft,
-                                            dockBean.addr
+                                            false, keyBean.isLeft, dockBean.addr
                                         ) {
                                             NetApi.getKeyInfo(rfid) {
                                                 if (it != null && !it.macAddress.isNullOrEmpty()) {
                                                     ModBusController.updateKeyMac(
-                                                        dockBean.addr,
-                                                        keyBean.isLeft,
-                                                        it.macAddress
+                                                        dockBean.addr, keyBean.isLeft, it.macAddress
                                                     )
                                                     ModBusController.updateKeyReadyStatus(
-                                                        it.macAddress,
-                                                        false,
-                                                        5
+                                                        it.macAddress, false, 5
                                                     )
                                                 } else {
                                                     LogUtil.e("Get key info fail : $rfid")
@@ -459,12 +431,10 @@ object BusinessManager {
                                     LogUtil.e("Lock rfid error")
                                     return@readLockRfid
                                 }
-                                val rfid = res.copyOfRange(3, 11).toHexStrings(false)
-                                    .removeLeadingZeros()
+                                val rfid =
+                                    res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
                                 ModBusController.updateLockRfid(
-                                    dockBean.addr,
-                                    lockBean.idx,
-                                    rfid
+                                    dockBean.addr, lockBean.idx, rfid
                                 )
                                 ThreadUtils.runOnIO {
                                     val lockStatusReq =
@@ -473,8 +443,7 @@ object BusinessManager {
                                         async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
                                     val slotType =
                                         async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
-                                    val slotsPageReq =
-                                        async { getSlotsPage() }
+                                    val slotsPageReq = async { getSlotsPage() }
                                     var lockStatus = lockStatusReq.await()
                                     val slotsPage = slotsPageReq.await()
                                     val slotStatusList = slotStatus.await()
@@ -490,13 +459,10 @@ object BusinessManager {
                                                     R.string.lock_exception_tag
                                                 )
                                             )
-                                        } else if (slotsPage?.records
-                                                ?.filter {
-                                                    it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue &&
-                                                            it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
-                                                }
-                                                ?.find { it.row?.toInt() == dockBean.row && (lockBean.idx + 1) == it.col?.toInt() } != null
-                                        ) {
+                                        } else if (slotsPage?.records?.filter {
+                                                it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
+                                            }
+                                                ?.find { it.row?.toInt() == dockBean.row && (lockBean.idx + 1) == it.col?.toInt() } != null) {
                                             ToastUtils.tip(
                                                 MyApplication.instance?.applicationContext!!.getString(
                                                     R.string.slot_exception_tag
@@ -507,9 +473,7 @@ object BusinessManager {
                                                 if (it != null) {
                                                     // TODO 考虑快速拿取
                                                     ModBusController.controlLockBuckle(
-                                                        false,
-                                                        dockBean.addr,
-                                                        lockBean.idx
+                                                        false, dockBean.addr, lockBean.idx
                                                     ) { itRst ->
                                                         if (itRst.isNotEmpty()) {
                                                             // 上报锁具信息
@@ -548,8 +512,7 @@ object BusinessManager {
                             when (deviceBean.type) {
                                 DEVICE_TYPE_KEY -> {
                                     ModBusController.readKeyRfid(
-                                        dockBean.addr,
-                                        deviceBean.idx
+                                        dockBean.addr, deviceBean.idx
                                     ) { isLeft, res ->
                                         if (res.size < 11) {
                                             LogUtil.e("Key rfid error")
@@ -558,9 +521,7 @@ object BusinessManager {
                                         val rfid = res.copyOfRange(3, 11).toHexStrings(false)
                                             .removeLeadingZeros()
                                         ModBusController.updateKeyRfid(
-                                            dockBean.addr,
-                                            true,
-                                            rfid
+                                            dockBean.addr, true, rfid
                                         )
                                         NetApi.getKeyInfo(rfid) {
                                             ModBusController.updateKeyNewHardware(
@@ -593,12 +554,11 @@ object BusinessManager {
                                             dockBean.addr, deviceBean.idx, rfid
                                         )
                                         ThreadUtils.runOnIO {
-                                            val lockStatusReq =
-                                                async {
-                                                    fetchDict<CommonDictRespVO>(
-                                                        DictAndSystemConstants.KEY_PAD_LOCK_STATUS
-                                                    )
-                                                }
+                                            val lockStatusReq = async {
+                                                fetchDict<CommonDictRespVO>(
+                                                    DictAndSystemConstants.KEY_PAD_LOCK_STATUS
+                                                )
+                                            }
                                             var lockStatus = lockStatusReq.await()
                                             NetApi.getIsLockPage { lockData ->
                                                 //锁rfid未异常正常请求锁数据,关锁
@@ -772,11 +732,9 @@ object BusinessManager {
     }
 
     // 2. 把原本同步的字典查询留在 IO 线程
-    private suspend fun <T> fetchDict(key: String): List<T> =
-        withContext(Dispatchers.IO) {
-            @Suppress("UNCHECKED_CAST")
-            NetApi.getDictData(key) as List<T>
-        }
+    private suspend fun <T> fetchDict(key: String): List<T> = withContext(Dispatchers.IO) {
+        @Suppress("UNCHECKED_CAST") NetApi.getDictData(key) as List<T>
+    }
 
     // 3. 重写 checkEquipCount
     fun checkEquipCount(
@@ -812,15 +770,11 @@ object BusinessManager {
                 val lockMap = withContext(Dispatchers.Default) {
                     ModBusController.getLocks(
                         needLockCount,
-                        slotsPage?.records
-                            ?.filter {
-                                it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue &&
-                                        it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
-                            }?.toMutableList() ?: mutableListOf(),
-                        locksPage?.records
-                            ?.filter { it.exStatus == lockStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
-                            ?.map { it.lockNfc ?: "" }
-                            ?.toMutableList() ?: mutableListOf()
+                        slotsPage?.records?.filter {
+                            it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
+                        }?.toMutableList() ?: mutableListOf(),
+                        locksPage?.records?.filter { it.exStatus == lockStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
+                            ?.map { it.lockNfc ?: "" }?.toMutableList() ?: mutableListOf()
                     )
                 }
 
@@ -840,15 +794,11 @@ object BusinessManager {
                     val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
                     keyPair = withContext(Dispatchers.Default) {
                         getOneKey(
-                            slotsPage?.records
-                                ?.filter {
-                                    it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue &&
-                                            it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
-                                }?.toMutableList() ?: mutableListOf(),
-                            keyPage?.records
-                                ?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
-                                ?.map { it.keyNfc ?: "" }
-                                ?.toMutableList() ?: mutableListOf()
+                            slotsPage?.records?.filter {
+                                it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
+                            }?.toMutableList() ?: mutableListOf(),
+                            keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
+                                ?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()
                         )
                     }
                     if (keyPair == null) {
@@ -884,9 +834,7 @@ object BusinessManager {
      * 注册连接监听
      */
     fun registerConnectListener(
-        mac: String,
-        connectNow: Boolean = false,
-        callBack: ((
+        mac: String, connectNow: Boolean = false, callBack: ((
             Boolean, BleBean?
         ) -> Unit)? = null
     ) {
@@ -1410,9 +1358,7 @@ object BusinessManager {
      * ticketFinished主要是后端的作业票是否已经结束,结束了,就直接修改状态就好了
      */
     private fun handleKeyReturn(
-        bleDevice: BleDevice,
-        workTicketGetBO: WorkTicketGetBO?,
-        ticketFinished: Boolean
+        bleDevice: BleDevice, workTicketGetBO: WorkTicketGetBO?, ticketFinished: Boolean
     ) {
         val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
         val keyBean = dock?.getKeyList()?.find { it.mac == bleDevice.mac }
@@ -1442,14 +1388,40 @@ object BusinessManager {
                 }
 
                 sendLoadingEventMsg(null, false)
-                ToastUtils.tip(R.string.key_return_success)
                 if (CAN_RETURN) {
                     // 上报点位钥匙绑定
-                    NetApi.updateLockPointBatch(updateList) { isSuccess, msg ->
-                        if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
-                                R.string.lock_nfc_lost
-                            )
-                        ) {
+                    NetApi.updateLockPointBatch(updateList) { isSuccess, msg, code ->
+                        LogUtil.i("还锁操作:${isSuccess},${msg},${code}")
+                        if (isSuccess) {
+                            // 上报钥匙归还
+                            NetApi.updateKeyReturn(
+                                data.taskCode?.toLong()!!,
+                                keyNfc!!,
+                                MyApplication.instance!!.serialNo()
+                            ) { isSuccess, msg, code ->
+                                if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
+                                        R.string.ticket_lost
+                                    )
+                                ) {
+                                    SPUtils.saveUpdateKeyReturn(
+                                        MyApplication.instance!!,
+                                        UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!)
+                                    )
+                                    if (msg == MyApplication.instance?.applicationContext!!.getString(
+                                            R.string.ticket_lost
+                                        )
+                                    ) {
+                                        sendEventMsg(
+                                            MsgEvent(
+                                                MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
+                                            )
+                                        )
+                                    }
+                                    ToastUtils.tip(R.string.key_return_success)
+                                }else{
+                                    ToastUtils.tip(R.string.key_return_success)
+                                }
+                            }
                             data.taskCode?.toLong()?.let {
                                 sendEventMsg(
                                     MsgEvent(
@@ -1460,34 +1432,26 @@ object BusinessManager {
                             }
                             // 确认归还,切换为待机模式
                             switchReadyMode(bleDevice)
-                        } else if (msg != MyApplication.instance?.applicationContext!!.getString(R.string.lock_nfc_lost)) {
-                            SPUtils.saveUpdateLockPoint(MyApplication.instance!!, updateList)
-                        }
-                    }
-
-                    // 上报钥匙归还
-                    NetApi.updateKeyReturn(
-                        data.taskCode?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()
-                    ) { isSuccess, msg ->
-                        if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
-                                R.string.ticket_lost
-                            )
-                        ) {
-                            SPUtils.saveUpdateKeyReturn(
-                                MyApplication.instance!!,
-                                UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!)
-                            )
-                            if (msg == MyApplication.instance?.applicationContext!!.getString(
-                                    R.string.ticket_lost
-                                )
-                            ) {
-                                sendEventMsg(
-                                    MsgEvent(
-                                        MsgEventConstants.MSG_EVENT_TICKET_FINISHED,
-                                        null
-                                    )
-                                )
+                        } else {
+                            ThreadUtils.runOnMain {
+                                // 当前策略:作业票未完成禁止归还钥匙
+                                showKeyReturnDialog {
+                                    sendLoadingEventMsg(null, false)
+                                    ToastUtils.tip(R.string.continue_the_ticket)
+                                    BleManager.getInstance().disconnect(bleDevice)
+                                    // 打开卡扣,防止初始化的时候选择不处理钥匙导致无法使用
+                                    val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
+                                    val keyBean =
+                                        dock?.getKeyList()?.find { it.mac == bleDevice.mac }
+                                    keyBean?.let {
+                                        ModBusController.controlKeyBuckle(
+                                            true, keyBean.isLeft, dock.addr
+                                        )
+                                    }
+                                }
                             }
+                            SPUtils.clearUpdateKeyReturn(MyApplication.instance!!)
+                            SPUtils.clearUpdateLockPoint(MyApplication.instance!!)
                         }
                     }
                 } else {
@@ -1522,7 +1486,7 @@ object BusinessManager {
         // 上报钥匙归还
         NetApi.updateKeyReturn(
             taskCode, keyNfc, MyApplication.instance!!.serialNo()
-        ) { isSuccess, msg ->
+        ) { isSuccess, msg, code ->
             if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
                     R.string.ticket_lost
                 )
@@ -1536,8 +1500,7 @@ object BusinessManager {
                 ) {
                     sendEventMsg(
                         MsgEvent(
-                            MsgEventConstants.MSG_EVENT_TICKET_FINISHED,
-                            null
+                            MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
                         )
                     )
                 }
@@ -1800,7 +1763,10 @@ object BusinessManager {
                                 ?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
                                     step = it
                                 }
-                            NetApi.getTicketDetail(itBO.ticketId) { ticketDetail ->
+                            NetApi.getTicketDetail(itBO.ticketId) { ticketDetail, _ ->
+                                if (ticketDetail == null) {
+                                    return@getTicketDetail
+                                }
                                 val role = ticketDetail?.ticketUserVOList?.find {
                                     it.userId == SPUtils.getLoginUser(MyApplication.instance?.applicationContext!!)?.userId && it.userType == USER_TYPE_LOCKER
                                 }
@@ -1857,12 +1823,11 @@ object BusinessManager {
         if (!CAN_RETURN) return
         val updateList = SPUtils.getUpdateLockPoint(context)
         if (updateList.isNotEmpty()) {
-            NetApi.updateLockPointBatch(updateList) { isSuccess, msg ->
-                if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
-                        R.string.lock_nfc_lost
-                    )
-                ) {
+            NetApi.updateLockPointBatch(updateList) { isSuccess, msg, code ->
+                LogUtil.i("submitKeyData还锁操作:${isSuccess},${msg},${code}")
+                if (isSuccess || code == 500) {
                     SPUtils.clearUpdateLockPoint(context)
+                    SPUtils.clearUpdateKeyReturn(context)
                 }
             }
         }
@@ -1877,7 +1842,7 @@ object BusinessManager {
         itemsToRemove.forEach { itData ->
             NetApi.updateKeyReturn(
                 itData.ticketId, itData.keyNfc, context.serialNo()
-            ) { isSuccess, msg ->
+            ) { isSuccess, msg, code ->
                 count++
                 if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
                         R.string.ticket_lost
@@ -1893,8 +1858,7 @@ object BusinessManager {
                     ) {
                         sendEventMsg(
                             MsgEvent(
-                                MsgEventConstants.MSG_EVENT_TICKET_FINISHED,
-                                null
+                                MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
                             )
                         )
                     }

+ 3 - 0
app/src/main/java/com/grkj/iscs/ble/BleConnectionManager.kt

@@ -143,6 +143,9 @@ object BleConnectionManager {
         }
         val listener = connectListeners.first()
         currentConnectingMac = listener.mac
+        ThreadUtils.runOnIODelayed(10 * 1000) {
+            isPreparing = false
+        }
         isPreparing = true
         if (ActivityTracker.getCurrentActivity() == null) {
             LogUtil.w("蓝牙连接-Ignore connectKey : ${listener.mac} no current activity")

+ 17 - 3
app/src/main/java/com/grkj/iscs/model/bo/WorkTicketGetBO.kt

@@ -1,5 +1,7 @@
 package com.grkj.iscs.model.bo
 
+import com.grkj.iscs.MyApplication
+import com.grkj.iscs.R
 import com.grkj.iscs.util.NetApi
 import com.grkj.iscs.util.log.LogUtil
 import kotlin.coroutines.resume
@@ -93,13 +95,25 @@ class WorkTicketGetBO {
         if (data.isNullOrEmpty()) return true to false
 
         var anyRemoteFinished = false
-
+        //点位的rfid是否被刷到锁的rfid
+        val pointRfidEqLockRfid = data?.any { dataDto ->
+            dataDto.dataList?.any { dataListDto ->
+                dataDto.dataList?.map { it.equipRfidNo }?.contains(dataListDto.infoRfidNo) == true
+            } == true
+        }
+        if (pointRfidEqLockRfid == true) {
+            return false to false
+        }
         for (item in data) {
             // 1. 调用回调接口获取远程的 ticketStatus,并根据情况设置两个标志
             val (localTicketFinish, remoteTicketFinished) = suspendCoroutine<Pair<Boolean, Boolean>> { cont ->
-                NetApi.getTicketDetail(item.taskCode?.toLong() ?: 0) { res ->
+                NetApi.getTicketDetail(item.taskCode?.toLong() ?: 0) { res, code ->
                     LogUtil.i("作业票状态: ${res?.ticketStatus}")
-                    if (res?.ticketStatus in listOf("5", "6")) {
+                    if (res?.ticketStatus in listOf(
+                            "5",
+                            "6"
+                        ) || code == 500
+                    ) {
                         // 只要远程状态是 5 或 6,就认为 remoteTicketFinished = true
                         cont.resume(true to true)
                     } else {

+ 11 - 11
app/src/main/java/com/grkj/iscs/util/NetApi.kt

@@ -449,14 +449,14 @@ object NetApi {
     /**
      * 获取作业票和关联数据
      */
-    fun getTicketDetail(ticketId: Long, callBack: (TicketDetailRespVO?) -> Unit) {
+    fun getTicketDetail(ticketId: Long, callBack: (TicketDetailRespVO?, Int?) -> Unit) {
         NetHttpManager.getInstance().doRequestNet(
             UrlConsts.TICKET_EQUIP_DETAIL,
             false,
             mapOf("ticketId" to ticketId),
-            { res, _, _ ->
+            { res, msg, code ->
                 res?.let {
-                    callBack.invoke(getRefBean(it))
+                    callBack.invoke(getRefBean(it), code)
                 }
             }, isGet = true, isAuth = true
         )
@@ -493,7 +493,7 @@ object NetApi {
         keyNfc: String,
         serialNumber: String,
         retryCount: Int = 3,
-        callBack: (Boolean, String) -> Unit
+        callBack: (Boolean, String?, Int) -> Unit
     ) {
         NetHttpManager.getInstance().doRequestNet(
             UrlConsts.KEY_RETURN_UPDATE,
@@ -503,9 +503,9 @@ object NetApi {
                 "keyNfc" to keyNfc,
                 "serialNumber" to serialNumber
             ),
-            { res, msg, _ ->
+            { res, msg, code ->
                 res?.let {
-                    callBack(true, msg ?: "")
+                    callBack(true, msg, code)
                 } ?: let {
                     if (retryCount > 0) {
                         Executor.delayOnIO(500) {
@@ -518,7 +518,7 @@ object NetApi {
                             )
                         }
                     } else {
-                        callBack.invoke(false, msg ?: "")
+                        callBack.invoke(false, msg, code)
                     }
                 }
                 // TODO isAuth需要配置
@@ -549,7 +549,7 @@ object NetApi {
     fun updateLockPointBatch(
         list: MutableList<LockPointUpdateReqVO>,
         retryCount: Int = 3,
-        callBack: (Boolean, String) -> Unit
+        callBack: (Boolean, String, Int) -> Unit
     ) {
         NetHttpManager.getInstance().doRequestNet(
             UrlConsts.LOCK_POINT_UPDATE_BATCH,
@@ -557,16 +557,16 @@ object NetApi {
             mapOf(
                 "list" to list
             ),
-            { res, msg, _ ->
+            { res, msg, code ->
                 res?.let {
-                    callBack(true, msg.toString())
+                    callBack(true, msg.toString(),code)
                 } ?: let {
                     if (retryCount > 0) {
                         Executor.delayOnIO(500) {
                             updateLockPointBatch(list, retryCount - 1, callBack)
                         }
                     } else {
-                        callBack.invoke(false, msg.toString())
+                        callBack.invoke(false, msg.toString(),code)
                     }
                 }
             }, isGet = false, isAuth = true

+ 12 - 10
app/src/main/java/com/grkj/iscs/util/NetHttpManager.kt

@@ -18,7 +18,7 @@ import com.grkj.iscs.model.Constants.DEVICE_TYPE_NORMAL
 import com.grkj.iscs.model.Constants.DEVICE_TYPE_PORTABLE
 import com.grkj.iscs.model.Token
 import com.grkj.iscs.model.UrlConsts
-import com.grkj.iscs.model.UrlConsts.LOGIN_CARD
+import com.grkj.iscs.model.vo.BaseVO
 import com.grkj.iscs.model.vo.FileStreamReqParam
 import com.grkj.iscs.util.log.LogUtil
 import okhttp3.logging.HttpLoggingInterceptor
@@ -69,12 +69,14 @@ class NetHttpManager {
                 it.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
             }
             .addSerialPreprocessor { itPreChain ->
-                itPreChain.task.addHeader("Module", when (DEVICE_TYPE) {
-                    2 -> DEVICE_TYPE_MATERIAL
-                    3 -> DEVICE_TYPE_PORTABLE
-                    4 -> DEVICE_TYPE_HYBRID
-                    else -> DEVICE_TYPE_NORMAL
-                })
+                itPreChain.task.addHeader(
+                    "Module", when (DEVICE_TYPE) {
+                        2 -> DEVICE_TYPE_MATERIAL
+                        3 -> DEVICE_TYPE_PORTABLE
+                        4 -> DEVICE_TYPE_HYBRID
+                        else -> DEVICE_TYPE_NORMAL
+                    }
+                )
                 if (!itPreChain.task.isTagged(tagAuth)) {
                     itPreChain.proceed()
                     return@addSerialPreprocessor
@@ -157,11 +159,11 @@ class NetHttpManager {
                                 ToastUtils.tip(itMsg)
                                 BusinessManager.sendLoadingEventMsg(null, false)
                             }
-                            val bobyStr = it.body.toString()
+                            val bodyStr = it.body.toString()
                             callback(
-                                null, bobyStr.ifEmpty {
+                                null, baseVO?.msg ?: bodyStr.ifEmpty {
                                     it.toString()
-                                }, it.status
+                                }, baseVO?.code ?: it.status
                             )
                         }
                     } catch (e: Exception) {

+ 76 - 27
app/src/main/java/com/grkj/iscs/view/activity/HomeActivity.kt

@@ -23,6 +23,7 @@ import com.grkj.iscs.model.eventmsg.MsgEvent
 import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_EXCEPTION
 import com.grkj.iscs.model.vo.user.UserInfoRespVO
 import com.grkj.iscs.util.SPUtils
+import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.adapter.MenuAdapter
 import com.grkj.iscs.view.base.BaseFragment
@@ -44,7 +45,7 @@ import com.zhy.adapter.recyclerview.base.ViewHolder
  */
 class HomeActivity : BaseMvpActivity<IHomeView, HomePresenter, ActivityHomeBinding>() {
 
-    private var cardNo = ""
+    private var cardNo: String? = ""
     val cardNoLiveData = MutableLiveData("")
     private var mMenuList = mutableListOf<Menu>()
     private lateinit var observer: Observer<MsgEvent>
@@ -54,30 +55,67 @@ class HomeActivity : BaseMvpActivity<IHomeView, HomePresenter, ActivityHomeBindi
 
     override fun initView() {
         presenter?.registerStatusListener()
+        presenter?.updateKeyData()
         presenter?.getAndSaveCabinetId()
         val userInfo = intent.getSerializableExtra("userInfo")
-        
+
         BusinessManager.isTestMode = false
         if (userInfo != null && (userInfo as UserInfoRespVO).roles != null) {
             if (userInfo.roles?.any { it == USER_ROLE_DRAWER || it == USER_ROLE_LOCKER || it == USER_ROLE_COLOCKER || it == USER_ROLE_GUARD } == true) {
-                mMenuList.addAll(mutableListOf(
-                    Menu(getString(R.string.job_management), R.mipmap.job_management, JobManagementFragment())
-                ))
+                mMenuList.addAll(
+                    mutableListOf(
+                        Menu(
+                            getString(R.string.job_management),
+                            R.mipmap.job_management,
+                            JobManagementFragment()
+                        )
+                    )
+                )
             }
             if (userInfo.roles?.any { it == USER_ROLE_ADMHDWTESTER } == true) {
                 BusinessManager.isTestMode = true
-                mMenuList.add(Menu(getString(R.string.test), R.mipmap.menu_icon_test, DockTestFragment()))
+                mMenuList.add(
+                    Menu(
+                        getString(R.string.test),
+                        R.mipmap.menu_icon_test,
+                        DockTestFragment()
+                    )
+                )
             }
             if (userInfo.roles?.any { it == USER_ROLE_ADMHDWSETTER } == true) {
-                mMenuList.add(Menu(getString(R.string.system_setting), R.mipmap.menu_icon_sys_setting, SystemSettingFragment()))
+                mMenuList.add(
+                    Menu(
+                        getString(R.string.system_setting),
+                        R.mipmap.menu_icon_sys_setting,
+                        SystemSettingFragment()
+                    )
+                )
             }
         }
 //        mMenuList.add(Menu(getString(R.string.test), R.mipmap.menu_icon_test, DockTestFragment()))
 //        mMenuList.add(Menu(getString(R.string.system_setting), R.mipmap.menu_icon_sys_setting, SystemSettingFragment()))
 
-        mMenuList.add(Menu(getString(R.string.device_status), R.mipmap.menu_icon_device_status, DeviceStatusFragment()))
-        mMenuList.add(Menu(getString(R.string.switch_status), R.mipmap.menu_icon_device_status, SwitchStatusFragment()))
-        mMenuList.add(Menu(getString(R.string.exception_report), R.mipmap.exception_handle, ExceptionReportFragment()))
+        mMenuList.add(
+            Menu(
+                getString(R.string.device_status),
+                R.mipmap.menu_icon_device_status,
+                DeviceStatusFragment()
+            )
+        )
+        mMenuList.add(
+            Menu(
+                getString(R.string.switch_status),
+                R.mipmap.menu_icon_device_status,
+                SwitchStatusFragment()
+            )
+        )
+        mMenuList.add(
+            Menu(
+                getString(R.string.exception_report),
+                R.mipmap.exception_handle,
+                ExceptionReportFragment()
+            )
+        )
         mMenuList.add(Menu(getString(R.string.settings), R.mipmap.settings, SettingFragment()))
 
         mBinding?.itemSetting?.ivIcon?.setImageResource(R.mipmap.settings)
@@ -95,22 +133,25 @@ class HomeActivity : BaseMvpActivity<IHomeView, HomePresenter, ActivityHomeBindi
         mBinding?.vp?.offscreenPageLimit = mMenuList.size
         mBinding?.vp?.adapter = MenuAdapter(supportFragmentManager, lifecycle, mMenuList)
 
-        mBinding?.rvMenu?.adapter = object : CommonAdapter<Menu>(this, R.layout.item_rv_menu, mMenuList) {
-            override fun convert(holder: ViewHolder, data: Menu, position: Int) {
-                holder.setVisible(R.id.root, data.title != getString(R.string.settings))
-                holder.setText(R.id.tv_name, data.title)
-                holder.getView<ImageView>(R.id.iv_icon).setImageResource(data.icon!!)
-                holder.setOnClickListener(R.id.root) {
-                    mBinding?.itemSetting?.root?.setBackgroundColor(0)
-                    mBinding?.vp?.currentItem = position
-                    notifyDataSetChanged()
+        mBinding?.rvMenu?.adapter =
+            object : CommonAdapter<Menu>(this, R.layout.item_rv_menu, mMenuList) {
+                override fun convert(holder: ViewHolder, data: Menu, position: Int) {
+                    holder.setVisible(R.id.root, data.title != getString(R.string.settings))
+                    holder.setText(R.id.tv_name, data.title)
+                    holder.getView<ImageView>(R.id.iv_icon).setImageResource(data.icon!!)
+                    holder.setOnClickListener(R.id.root) {
+                        mBinding?.itemSetting?.root?.setBackgroundColor(0)
+                        mBinding?.vp?.currentItem = position
+                        notifyDataSetChanged()
+                    }
+                    holder.setBackgroundColor(
+                        R.id.root,
+                        if (position == mBinding?.vp?.currentItem)
+                            getColor(R.color.common_bg_white_30)
+                        else 0
+                    )
                 }
-                holder.setBackgroundColor(R.id.root,
-                    if (position == mBinding?.vp?.currentItem)
-                        getColor(R.color.common_bg_white_30)
-                    else 0)
             }
-        }
 
         observer = Observer { newData ->
             if (newData.code != MSG_EVENT_DEVICE_EXCEPTION) {
@@ -125,15 +166,23 @@ class HomeActivity : BaseMvpActivity<IHomeView, HomePresenter, ActivityHomeBindi
         }
 
         BusinessManager.mEventBus.observe(this, observer)
-        ModBusController.updateAllBuckleStatus{}
-        ModBusController.updateSwitchStatus{}
+        ModBusController.updateAllBuckleStatus {}
+        ModBusController.updateSwitchStatus {}
     }
 
     override fun dispatchKeyEvent(event: KeyEvent): Boolean {
         if (event.action == KeyEvent.ACTION_UP && event.source == InputDevice.SOURCE_KEYBOARD) {
             // 检测到回车开始处理
             if (event.keyCode == 66) {
-                cardNo = cardNo.toLong().toByteArrays().toHexStrings(false)
+                cardNo = try {
+                    cardNo?.toLong()?.toByteArrays()?.toHexStrings(false)
+                } catch (e: Exception) {
+                    null
+                }
+                if (cardNo == null) {
+                    ToastUtils.tip(R.string.card_invalid)
+                    return  super.dispatchKeyEvent(event)
+                }
                 LogUtil.i("Swipe card home: $cardNo")
                 cardNoLiveData.postValue(cardNo)
                 // 重置cardNo

+ 2 - 2
app/src/main/java/com/grkj/iscs/view/fragment/FaceConfigFragment.kt

@@ -30,7 +30,7 @@ class FaceConfigFragment :
     override fun initView() {
         mBinding?.cbAddFace?.setOnClickListener {
             if (mFaceList.size >= mFaceLimit) {
-                ToastUtils.tip(R.string.face_config_tip, mFaceLimit)
+                ToastUtils.tip(getString(R.string.face_config_tip, mFaceLimit))
                 return@setOnClickListener
             }
             showCaptureDialog()
@@ -56,7 +56,7 @@ class FaceConfigFragment :
         refreshFaceList()
         presenter?.getFaceLimit {
             mFaceLimit = it
-            mBinding?.faceLimitTv?.text = getString(R.string.face_config_tip,mFaceLimit)
+            mBinding?.faceLimitTv?.text = getString(R.string.face_config_tip, mFaceLimit)
         }
     }
 

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

@@ -29,7 +29,7 @@ class FingerprintConfigFragment :
     override fun initView() {
         mBinding?.cbAddFinger?.setOnClickListener {
             if (mFingerList.size >= mFingerprintLimit) {
-                ToastUtils.tip(R.string.fingerprint_config_tip, mFingerprintLimit)
+                ToastUtils.tip(getString(R.string.fingerprint_config_tip, mFingerprintLimit))
                 return@setOnClickListener
             }
             showFingerScanDialog()

+ 36 - 0
app/src/main/java/com/grkj/iscs/view/presenter/HomePresenter.kt

@@ -5,11 +5,14 @@ import com.grkj.iscs.MyApplication
 import com.grkj.iscs.R
 import com.grkj.iscs.ble.BleConnectionManager
 import com.grkj.iscs.extentions.serialNo
+import com.grkj.iscs.modbus.DockBean
 import com.grkj.iscs.modbus.ModBusController
+import com.grkj.iscs.model.DeviceConst
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
 import com.grkj.iscs.util.Executor
 import com.grkj.iscs.util.NetApi
 import com.grkj.iscs.util.SPUtils
+import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BasePresenter
 import com.grkj.iscs.view.iview.IHomeView
@@ -82,4 +85,37 @@ class HomePresenter : BasePresenter<IHomeView>() {
                 ?.let { SPUtils.saveCabinetId(it.cabinetId ?: "") }
         }
     }
+
+    /**
+     * 更新钥匙数据
+     */
+    fun updateKeyData() {
+        ThreadUtils.runOnIO {
+            ModBusController.dockList.filter { it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
+                .forEach { dock ->
+                    dock.deviceList.filterIsInstance<DockBean.KeyBean>().filter { it.isExist }
+                        .forEach { key ->
+                            key.rfid?.let {
+                                NetApi.getKeyInfo(it) {
+                                    if (it != null && !it.macAddress.isNullOrEmpty()) {
+                                        ModBusController.updateKeyMac(
+                                            dock.addr,
+                                            key.isLeft,
+                                            it.macAddress
+                                        )
+                                        ModBusController.updateKeyReadyStatus(
+                                            it.macAddress,
+                                            false,
+                                            5
+                                        )
+                                    } else {
+                                        LogUtil.e("Get key info fail : $it")
+                                        ToastUtils.tip(R.string.get_key_info_fail)
+                                    }
+                                }
+                            }
+                        }
+                }
+        }
+    }
 }

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

@@ -80,7 +80,10 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
             ToastUtils.tip(mContext!!.resources.getString(R.string.ticket_id_is_null))
             return
         }
-        NetApi.getTicketDetail(ticketId) {
+        NetApi.getTicketDetail(ticketId) {it,_->
+            if (it==null){
+                return@getTicketDetail
+            }
             Executor.runOnMain {
                 callBack(it)
             }

+ 4 - 1
app/src/main/java/com/grkj/iscs/view/presenter/StepPresenter.kt

@@ -72,7 +72,10 @@ class StepPresenter : BasePresenter<IStepView>() {
             ToastUtils.tip(mContext!!.resources.getString(R.string.ticket_id_is_null))
             return
         }
-        NetApi.getTicketDetail(ticketId) {
+        NetApi.getTicketDetail(ticketId) {it,_->
+            if (it==null){
+                return@getTicketDetail
+            }
             Executor.runOnMain {
                 callBack.invoke(it)
             }

+ 4 - 1
app/src/main/java/com/grkj/iscs/view/presenter/WorkerPresenter.kt

@@ -30,7 +30,10 @@ class WorkerPresenter : BasePresenter<IWorkerView>() {
             ToastUtils.tip(mContext!!.resources.getString(R.string.ticket_id_is_null))
             return
         }
-        NetApi.getTicketDetail(ticketId) {
+        NetApi.getTicketDetail(ticketId) {it,_->
+            if (it==null){
+                return@getTicketDetail
+            }
             Executor.runOnMain {
                 callBack.invoke(it)
             }

+ 4 - 2
app/src/main/res/values-en/strings.xml

@@ -337,7 +337,7 @@
     <string name="current_user_does_not_have_the_authority_to_unlock_colock">The current user does not have the authority to unlock colock</string>
     <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="ticket_lost">作业票数据丢失啦!</string>
     <string name="current_ticket_report_lock_take_exception_tip">current ticket report lock take exception, please return lock</string>
     <string name="please_input_exception_reason">please input exception reason</string>
     <string name="hardware_info">Hardware Info: %1$s</string>
@@ -354,10 +354,12 @@
     <string name="exception_select_hardware_tip">Please select hardware</string>
     <string name="check_key_and_lock">check key and lock</string>
     <string name="turn_read">read</string>
-    <string name="lock_nfc_lost">{\"msg\":\"挂锁nfc缺失!\",\"code\":500}</string>
+    <string name="lock_nfc_lost">挂锁nfc缺失!</string>
     <string name="key_exception_tag">Key is tag for exception</string>
     <string name="slot_exception_tag">Slot is tag for exception</string>
     <string name="lock_exception_tag">Lock is tag for exception</string>
     <string name="job_already_finished">job already finished</string>
     <string name="ticket_data_error">job ticket data error</string>
+    <string name="card_invalid">This card is invalid</string>
+    <string name="lock_nfc_not_correct">该nfc无对应的挂锁信息</string>
 </resources>

+ 4 - 2
app/src/main/res/values-zh/strings.xml

@@ -337,7 +337,7 @@
     <string name="current_user_does_not_have_the_authority_to_unlock_colock">当前用户无权解除共锁</string>
     <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="ticket_lost">作业票数据丢失啦!</string>
     <string name="current_ticket_report_lock_take_exception_tip">当前作业挂锁上报异常,请归还挂锁</string>
     <string name="please_input_exception_reason">请输入异常原因</string>
     <string name="hardware_info">硬件信息: %1$s</string>
@@ -354,10 +354,12 @@
     <string name="exception_select_hardware_tip">请选择硬件</string>
     <string name="check_key_and_lock">正在检查钥匙和挂锁</string>
     <string name="turn_read">读</string>
-    <string name="lock_nfc_lost">{\"msg\":\"挂锁nfc缺失!\",\"code\":500}</string>
+    <string name="lock_nfc_lost">挂锁nfc缺失!</string>
     <string name="key_exception_tag">该钥匙已被标记异常</string>
     <string name="slot_exception_tag">该锁仓已被标记异常</string>
     <string name="lock_exception_tag">该挂锁已被标记异常</string>
     <string name="job_already_finished">该作业已被结束</string>
     <string name="ticket_data_error">工作票数据损坏</string>
+    <string name="card_invalid">该卡无效</string>
+    <string name="lock_nfc_not_correct">该nfc无对应的挂锁信息</string>
 </resources>

+ 4 - 2
app/src/main/res/values/strings.xml

@@ -337,7 +337,7 @@
     <string name="current_user_does_not_have_the_authority_to_unlock_colock">当前用户无权解除共锁</string>
     <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="ticket_lost">作业票数据丢失啦!</string>
     <string name="current_ticket_report_lock_take_exception_tip">当前作业挂锁上报异常,请归还挂锁</string>
     <string name="please_input_exception_reason">请输入异常原因</string>
     <string name="hardware_info">硬件信息: %1$s</string>
@@ -354,10 +354,12 @@
     <string name="exception_select_hardware_tip">请选择硬件</string>
     <string name="check_key_and_lock">正在检查钥匙和挂锁</string>
     <string name="turn_read">读</string>
-    <string name="lock_nfc_lost">{\"msg\":\"挂锁nfc缺失!\",\"code\":500}</string>
+    <string name="lock_nfc_lost">挂锁nfc缺失!</string>
     <string name="key_exception_tag">该钥匙已被标记异常</string>
     <string name="slot_exception_tag">该锁仓已被标记异常</string>
     <string name="lock_exception_tag">该挂锁已被标记异常</string>
     <string name="job_already_finished">该作业已被结束</string>
     <string name="ticket_data_error">工作票数据损坏</string>
+    <string name="card_invalid">该卡无效</string>
+    <string name="lock_nfc_not_correct">该nfc无对应的挂锁信息</string>
 </resources>