Эх сурвалжийг харах

refactor(CAN):
- 调整CAN节点扫描方式为线性扫描,并增加结束节点参数
- `CanReadyPlugin`在扫描完成后初始化锁和钥匙状态
- `CanCommand`增加读取超时配置
- `NodeIdHelper`调整为线性扫描和按位扫描两种模式

feat(系统):
- `ISCSApplication`在启动时根据硬件模式连接硬件
- `BootReceiver`重命名为`BootAndUnlockReceiver`,并在接收到开机广播后启动App

fix(UI):
- 统一部分弹窗样式,增加倒计时或取消按钮
- `SlotsManageFragment`修复CAN模式下布局显示问题
- `HomeFragment`在`onResume`时刷新首页数据
- 移除新增用户和管理员时的用户名正则校验

refactor(蓝牙):
- 优化`CheckKeyInfoTask`逻辑,确保在非登录态下执行,并增加超时和重试机制
- 优化`BleUtil`中蓝牙扫描逻辑,确保单实例扫描,并统一扫描参数设置

refactor(硬件):
- `HardwareBusinessManager`在处理CAN设备状态时,未登录情况下不做处理
- 增加`IHardwareHelper`中更新钥匙、锁RFID和新硬件状态等接口,并在`CanHardwareHelper`和`ModbusHardwareHelper`中实现
- `ModbusController`初始化时关闭所有钥匙仓位

周文健 1 сар өмнө
parent
commit
e8ef6ae1c1

+ 12 - 0
app/build.gradle.kts

@@ -68,6 +68,16 @@ android {
             pickFirsts += "META-INF/io.netty.versions.properties"
         }
     }
+    // 为每个 ABI 生成独立 APK
+    splits {
+        abi {
+            isEnable = true
+            reset()
+            include("armeabi-v7a", "arm64-v8a")
+            // 是否同时生成一个“全量 APK”
+            isUniversalApk = false
+        }
+    }
 }
 
 dependencies {
@@ -98,4 +108,6 @@ dependencies {
     testImplementation(libs.junit)
     androidTestImplementation(libs.androidx.junit)
     androidTestImplementation(libs.androidx.espresso.core)
+
+
 }

+ 3 - 4
app/src/main/java/com/grkj/iscs/features/init/fragment/InitSetAdminAccountFragment.kt

@@ -13,8 +13,6 @@ import com.grkj.shared.utils.KeyboardUtils
 import com.grkj.ui_base.base.BaseFragment
 import com.grkj.ui_base.skin.loadSkinIcon
 import com.grkj.ui_base.utils.CommonUtils
-import com.huyuhui.fastble.BleManager
-import com.kongzue.dialogx.dialogs.PopTip
 import com.sik.sikcore.extension.setDebouncedClickListener
 import com.sik.sikcore.string.RegexUtils
 import dagger.hilt.android.AndroidEntryPoint
@@ -58,7 +56,8 @@ class InitSetAdminAccountFragment : BaseFragment<FragmentInitSetAdminAccountBind
         fun apply() {
             val tf = et.typeface
             if (visible) {
-                et.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
+                et.inputType =
+                    InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                 et.transformationMethod = null
                 iv.loadSkinIcon("icon_show.png")
             } else {
@@ -92,7 +91,7 @@ class InitSetAdminAccountFragment : BaseFragment<FragmentInitSetAdminAccountBind
             return false
         }
         val password = binding.passwordEt.text.toString()
-        if (!RegexUtils.isMatch(password, CommonConstants.REGEX_PASSWORD)){
+        if (!RegexUtils.isMatch(password, CommonConstants.REGEX_PASSWORD)) {
             showToast(CommonUtils.getStr("password_regex_tip"))
             return false
         }

+ 1 - 0
app/src/main/java/com/grkj/iscs/features/main/activity/MainActivity.kt

@@ -147,6 +147,7 @@ class MainActivity() : BaseActivity<ActivityMainBinding>() {
             }
             binding.navBar.isVisible = bottomNavDestinations.contains(destination.id)
         }
+        viewModel.checkReturnKey().observe(this){}
     }
 
     override fun onEvent(event: EventBean<Any>) {

+ 50 - 0
app/src/main/java/com/grkj/iscs/features/main/viewmodel/MainViewModel.kt

@@ -188,6 +188,7 @@ class MainViewModel @Inject constructor(
                                                             }
                                                         }
                                                     } else {
+                                                        hideLoading()
                                                         val req =
                                                             CanCommands.forDevice(deviceModel.nodeId)
                                                                 .controlLatch(deviceModel.id, 0)
@@ -212,4 +213,53 @@ class MainViewModel @Inject constructor(
             }
         }
     }
+
+    /**
+     * 检查归还的钥匙
+     */
+    @SuppressLint("MissingPermission")
+    fun checkReturnKey(): LiveData<Boolean> {
+        return liveData(Dispatchers.IO) {
+            fun readJobTicket(mac: String) {
+                ThreadUtils.runOnIO {
+                    BleReturnDispatcher.submit(mac) { isConnect ->
+                        MainDomainData.returnKeyList.removeIf { it == mac }
+                        if (isConnect) {
+                            logger.info("钥匙连接成功")
+                            val bleBean =
+                                BleConnectionManager.getBleDeviceByMac(
+                                    mac
+                                )
+                            Executor.delayOnMain(300) {
+                                bleBean?.let {
+                                    LoadingEvent.sendLoadingEvent(
+                                        CommonUtils.getStr("loading_msg_get_ticket_status_start"),
+                                        true
+                                    )
+                                    BleConnectionManager.getCurrentStatus(
+                                        4,
+                                        it.bleDevice
+                                    )
+                                }
+                            }
+                        } else {
+                            hideLoading()
+                            logger.info("钥匙连接失败")
+                            HardwareMode.getCurrentHardwareMode()
+                                .controlKeyBuckle(true, mac) {
+                                    showTip(CommonUtils.getStr("ticket_get_failed"))
+                                }
+                        }
+                    }
+                }
+            }
+            if (!ISCSConfig.isDeviceRegistration) {
+                MainDomainData.returnKeyList.forEach {
+                    readJobTicket(it)
+                }
+            }
+            emit(true)
+        }
+
+    }
 }

+ 6 - 0
data/src/main/java/com/grkj/data/data/MainDomainData.kt

@@ -50,6 +50,12 @@ object MainDomainData {
     @Volatile
     var fromQuickEntry: Boolean = false
 
+    /**
+     * 返回的key
+     */
+    @Volatile
+    var returnKeyList: MutableList<String> = mutableListOf()
+
     /**
      * 默认区域
      */

+ 2 - 4
data/src/main/java/com/grkj/data/hardware/ble/BleConnectionManager.kt

@@ -302,11 +302,10 @@ object BleConnectionManager {
             @RequiresPermission(Manifest.permission.BLUETOOTH_SCAN)
             override fun onScanStarted(success: Boolean) {
                 logger.info("蓝牙连接-onScanStarted:${success}")
-                if (!success && retryTimes == 0) {
+                if (!success && retryTimes <= 0) {
                     if (isNeedLoading) LoadingEvent.Companion.sendLoadingEvent(null, false)
                     prepareDoneCallBack?.invoke(false, null)
                 } else if (!success && retryTimes > 0) {
-                    BleUtil.instance?.stopScan()
                     ThreadUtils.runOnMainDelayed(3000) {
                         doScanBle(mac, isNeedLoading, retryTimes - 1, isSend, prepareDoneCallBack)
                     }
@@ -324,7 +323,6 @@ object BleConnectionManager {
                 if (scanMac.equals(mac, ignoreCase = true)) {
                     // 找到目标设备,马上停止扫描
                     logger.info("找到目标设备 $mac,停止扫描并尝试连接")
-                    BleUtil.instance?.stopScan()
                     // 立刻调用 doConnect,下一步进入连接流程
                     doConnect(
                         newDevice,
@@ -733,7 +731,7 @@ object BleConnectionManager {
             } else {
                 BleReturnDispatcher.isConnected(mac)
             }
-            if (!isConnect){
+            if (!isConnect) {
                 suspendCoroutine<Unit> { unitCont ->
                     HardwareMode.getCurrentHardwareMode().controlKeyCharge(false, mac) {
                         logger.info("接收到消息,关闭充电")

+ 11 - 3
data/src/main/java/com/grkj/data/hardware/ble/BleUtil.kt

@@ -54,13 +54,14 @@ class BleUtil private constructor() {
         }
     }
 
+    @Synchronized
     @RequiresPermission(Manifest.permission.BLUETOOTH_SCAN)
     fun scan(cb: CustomBleScanCallback) {
         val ctx = SIKCore.getApplication()
 
         // 0) 前置检查(权限/蓝牙开关/定位开关)
         if (!BleManager.isSupportBle(ctx)) return cb.onPrompt("设备不支持 BLE")
-        if (!BleManager.isBleEnable(ctx))  return cb.onPrompt("请先打开蓝牙")
+        if (!BleManager.isBleEnable(ctx)) return cb.onPrompt("请先打开蓝牙")
         // Android 6–11:需要位置权限 + 开位置开关;12+ 视 ROM
         // 这里建议把你项目里的权限/定位检查封装下,失败就 return
 
@@ -90,19 +91,26 @@ class BleUtil private constructor() {
             override fun onScanStarted(ok: Boolean) {
                 inScan = ok
                 cb.onScanStarted(ok)
-                if (!ok) cb.onPrompt("启动扫描失败,请检查权限/系统设置")
+                if (!ok) {
+                    stopScan()
+                    cb.onPrompt("启动扫描失败,请检查权限/系统设置")
+                }
             }
+
             override fun onFilter(d: BleDevice): Boolean {
                 // 放宽一点,避免漏掉只在 SR 里带名的设备
                 return !ISCSConfig.needDeviceName ||
                         (d.name ?: "").equals(BleConst.BLE_LOCAL_NAME, ignoreCase = true)
             }
+
             override fun onLeScan(old: BleDevice, new: BleDevice, scannedBefore: Boolean) =
                 cb.onLeScan(old, new, scannedBefore)
+
             override fun onScanFinished(list: List<BleDevice>) {
-                inScan = false
+                stopScan()
                 cb.onScanFinished(list)
             }
+
             override fun onPrompt(p: String?) = cb.onPrompt(p)
         })
     }

+ 117 - 148
ui-base/src/main/java/com/grkj/ui_base/business/BleBusinessManager.kt

@@ -6,6 +6,7 @@ import com.google.gson.Gson
 import com.grkj.data.data.DictConstants
 import com.grkj.data.data.MainDomainData
 import com.grkj.data.di.LogicManager
+import com.grkj.data.di.LogicModule
 import com.grkj.data.enums.HardwareMode
 import com.grkj.data.enums.JobTicketStatusEnum
 import com.grkj.data.enums.RoleEnum
@@ -376,44 +377,45 @@ object BleBusinessManager {
                 // 根据情况看是否需要下发工作票
                 HardwareMode.getCurrentHardwareMode()
                     .getRfidByKeyMac(currentModeEvent.bleBean.bleDevice.mac)?.let { rfid ->
-                    // 判断是否有待取的钥匙
-                    val updateBo = HardwareBusinessManager.getWaitTakeDeviceByRfid(
-                        DeviceConst.DEVICE_TYPE_KEY, rfid
-                    )
-                    if (HardwareBusinessManager.hasAnyDeviceWaitTakeByTicketId(
-                            DeviceConst.DEVICE_TYPE_LOCK, updateBo?.ticketId
+                        // 判断是否有待取的钥匙
+                        val updateBo = HardwareBusinessManager.getWaitTakeDeviceByRfid(
+                            DeviceConst.DEVICE_TYPE_KEY, rfid
                         )
-                    ) {
-                        logger.info("有钥匙待取但是对应的作业票的锁还有")
-                        //todo 如果有钥匙待取但是对应的作业票的锁还有的,就不发
-                        return
-                    }
-                    updateBo?.let { itBO ->
-                        if (BleReturnDispatcher.isConnected(currentModeEvent.bleBean.bleDevice.mac)) {
-                            logger.info("当前钥匙在归还队列,断开连接")
-                            BleReturnDispatcher.scheduleDisconnect(currentModeEvent.bleBean.bleDevice.mac)
+                        if (HardwareBusinessManager.hasAnyDeviceWaitTakeByTicketId(
+                                DeviceConst.DEVICE_TYPE_LOCK, updateBo?.ticketId
+                            )
+                        ) {
+                            logger.info("有钥匙待取但是对应的作业票的锁还有")
+                            //todo 如果有钥匙待取但是对应的作业票的锁还有的,就不发
+                            return
                         }
-                        if (BleSendDispatcher.isConnected(currentModeEvent.bleBean.bleDevice.mac)) {
-                            logger.info("当前钥匙已在发送队列连接")
-                            checkAndSendTicket(currentModeEvent, itBO)
-                        } else {
-                            logger.info("当前钥匙未加入发送队列,连接后发送")
-                            BleSendDispatcher.submit(currentModeEvent.bleBean.bleDevice.mac) {
+                        updateBo?.let { itBO ->
+                            if (BleReturnDispatcher.isConnected(currentModeEvent.bleBean.bleDevice.mac)) {
+                                logger.info("当前钥匙在归还队列,断开连接")
+                                BleReturnDispatcher.scheduleDisconnect(currentModeEvent.bleBean.bleDevice.mac)
+                            }
+                            if (BleSendDispatcher.isConnected(currentModeEvent.bleBean.bleDevice.mac)) {
+                                logger.info("当前钥匙已在发送队列连接")
                                 checkAndSendTicket(currentModeEvent, itBO)
+                            } else {
+                                logger.info("当前钥匙未加入发送队列,连接后发送")
+                                BleSendDispatcher.submit(currentModeEvent.bleBean.bleDevice.mac) {
+                                    checkAndSendTicket(currentModeEvent, itBO)
+                                }
+                            }
+                        } ?: let {
+                            HardwareMode.getCurrentHardwareMode().updateKeyReadyStatus(
+                                currentModeEvent.bleBean.bleDevice.mac, true, 4
+                            )
+                            HardwareMode.getCurrentHardwareMode()
+                                .controlKeyBuckle(false, currentModeEvent.bleBean.bleDevice.mac)
+                            LoadingEvent.sendLoadingEvent()
+                            ThreadUtils.runOnIO {
+                                BleReturnDispatcher.scheduleDisconnect(currentModeEvent.bleBean.bleDevice.mac)
+                                DataBusiness.checkMyTodoForHandleKey(currentModeEvent.bleBean.bleDevice.mac)
                             }
                         }
                     } ?: let {
-                        HardwareMode.getCurrentHardwareMode()
-                            .updateKeyReadyStatus(currentModeEvent.bleBean.bleDevice.mac, true, 4)
-                        HardwareMode.getCurrentHardwareMode()
-                            .controlKeyBuckle(false, currentModeEvent.bleBean.bleDevice.mac)
-                        LoadingEvent.sendLoadingEvent()
-                        ThreadUtils.runOnIO {
-                            BleReturnDispatcher.scheduleDisconnect(currentModeEvent.bleBean.bleDevice.mac)
-                            DataBusiness.checkMyTodoForHandleKey(currentModeEvent.bleBean.bleDevice.mac)
-                        }
-                    }
-                } ?: let {
                     HardwareMode.getCurrentHardwareMode()
                         .updateKeyReadyStatus(currentModeEvent.bleBean.bleDevice.mac, true, 4)
                     HardwareMode.getCurrentHardwareMode()
@@ -464,8 +466,7 @@ object BleBusinessManager {
                             }
                     if (role == null) {
                         ThreadUtils.runOnMain {
-                            PopTip.build()
-                                .tip(CommonUtils.getStr("you_are_not_locker_tip"))
+                            PopTip.build().tip(CommonUtils.getStr("you_are_not_locker_tip"))
                         }
                         return@getTicketDetail
                     }
@@ -475,21 +476,14 @@ object BleBusinessManager {
                             currentModeEvent.bleBean.bleDevice.mac,
                             ticketDetail,
                             ticketDetail.ticketLockVOList?.filter {
-                                it.groupId == MainDomainData.deviceTakeTicketGroupBound[itBO.ticketId] &&
-                                        ticketDetail.ticketPointsVOList?.filter { it.groupId == MainDomainData.deviceTakeTicketGroupBound[itBO.ticketId] }
-                                            ?.mapNotNull { it.lockId }
-                                            ?.contains(it.lockId) != true
-                            }
-                                ?.map { it.lockNfc }?.toMutableList(),
+                                it.groupId == MainDomainData.deviceTakeTicketGroupBound[itBO.ticketId] && ticketDetail.ticketPointsVOList?.filter { it.groupId == MainDomainData.deviceTakeTicketGroupBound[itBO.ticketId] }
+                                    ?.mapNotNull { it.lockId }?.contains(it.lockId) != true
+                            }?.map { it.lockNfc }?.toMutableList(),
                             true
                         )
                     } else if (step?.enableUnlock == true) { // 解锁工作票
                         sendTicketBusiness(
-                            false,
-                            currentModeEvent.bleBean.bleDevice.mac,
-                            ticketDetail,
-                            null,
-                            true
+                            false, currentModeEvent.bleBean.bleDevice.mac, ticketDetail, null, true
                         )
                     }
                 }
@@ -659,9 +653,7 @@ object BleBusinessManager {
         SPUtils.returnKey(ticketId)
         // 上报钥匙归还
         LogicManager.jobTicketLogic.updateKeyTake(
-            ticketId,
-            "virtualKey",
-            SIKCore.getApplication().serialNo(), true
+            ticketId, "virtualKey", SIKCore.getApplication().serialNo(), true
         ) {
             logger.info("虚拟钥匙取出:${it}")
             LogicManager.jobTicketLogic.updateKeyReturn(
@@ -669,27 +661,22 @@ object BleBusinessManager {
             ) { isSuccess, msg, code ->
                 logger.info("虚拟钥匙归还:${isSuccess},${msg},${code}")
                 //更新作业票的状态
-                val jobTicketData =
-                    LogicManager.jobTicketLogic.getTicketDataByTicketId(ticketId)
+                val jobTicketData = LogicManager.jobTicketLogic.getTicketDataByTicketId(ticketId)
                 if (jobTicketData == null) {
                     TicketFinishedEvent.sendTicketFinishedEvent(ticketId)
                     PopTip.build().tip(CommonUtils.getStr("key_return_success"))
                     return@updateKeyReturn
                 }
-                val ticketStepDataVo =
-                    LogicManager.jobTicketLogic.getJobTicketStepDataByTicketId(
-                        jobTicketData.ticketId
-                    ).firstOrNull { it.stepStatus == "0" }
-                val workflowSteps =
-                    LogicManager.workflowLogic.getStepsByMode(
-                        jobTicketData.modeId!!
-                    )
+                val ticketStepDataVo = LogicManager.jobTicketLogic.getJobTicketStepDataByTicketId(
+                    jobTicketData.ticketId
+                ).firstOrNull { it.stepStatus == "0" }
+                val workflowSteps = LogicManager.workflowLogic.getStepsByMode(
+                    jobTicketData.modeId!!
+                )
                 var currentWorkflowStep = ticketStepDataVo
                 val ticketPoints =
                     LogicManager.jobTicketLogic.getTicketDetail(jobTicketData.ticketId)?.ticketPointsVOList
-                if (currentWorkflowStep?.enableReleaseColock == true && currentWorkflowStep.enableUnlock ||
-                    ticketPoints?.all { it.pointStatus == ticketPoints.firstOrNull()?.pointStatus } == false
-                ) {
+                if (currentWorkflowStep?.enableReleaseColock == true && currentWorkflowStep.enableUnlock || ticketPoints?.all { it.pointStatus == ticketPoints.firstOrNull()?.pointStatus } == false) {
                     logger.info("当前解锁和解除共锁在同一步骤或者没有全部点位解锁,不更新步骤状态")
                 } else {
                     ticketStepDataVo?.stepStatus = "1"
@@ -702,10 +689,9 @@ object BleBusinessManager {
                         logger.info("更新步骤:${it}")
                         LogicManager.jobTicketLogic.updateTicketStepData(it)
                     }
-                    val ticketStep =
-                        LogicManager.jobTicketLogic.getJobTicketStepDataByTicketId(
-                            jobTicketData.ticketId
-                        )
+                    val ticketStep = LogicManager.jobTicketLogic.getJobTicketStepDataByTicketId(
+                        jobTicketData.ticketId
+                    )
                     currentWorkflowStep = ticketStep.firstOrNull { it.stepStatus == "0" }
                     LogicManager.jobTicketLogic.updateTicketDataStatus(
                         ticketId,
@@ -756,16 +742,12 @@ object BleBusinessManager {
                 val ticketId = data.taskCode?.toLong()
                 val pointId =
                     LogicManager.hardwareLogic.getPointIdByPointNfc(data.dataList?.first()?.equipRfidNo)
-                val groupId =
-                    LogicManager.jobTicketLogic.getGroupIdByPointIdAndTicketId(
-                        pointId,
-                        data.taskCode?.toLong()!!
-                    )
+                val groupId = LogicManager.jobTicketLogic.getGroupIdByPointIdAndTicketId(
+                    pointId, data.taskCode?.toLong()!!
+                )
                 // 上报点位钥匙绑定
                 LogicManager.jobTicketLogic.updateLockPointBatch(
-                    updateList,
-                    ticketId,
-                    groupId
+                    updateList, ticketId, groupId
                 ) { isSuccess, msg, code ->
                     logger.info("还锁操作:${isSuccess},${msg},${code}")
                     if (isSuccess) {
@@ -806,15 +788,13 @@ object BleBusinessManager {
                                     LogicManager.jobTicketLogic.getJobTicketStepDataByTicketId(
                                         jobTicketData.ticketId
                                     ).firstOrNull { it.stepStatus == "0" }
-                                val workflowSteps =
-                                    LogicManager.workflowLogic.getStepsByMode(
-                                        jobTicketData.modeId!!
-                                    )
+                                val workflowSteps = LogicManager.workflowLogic.getStepsByMode(
+                                    jobTicketData.modeId!!
+                                )
                                 val ticketPoints =
                                     LogicManager.jobTicketLogic.getTicketDetail(data.taskCode?.toLong()!!)?.ticketPointsVOList
                                 var currentWorkflowStep = ticketStepDataVo
-                                if ((currentWorkflowStep?.enableLock == true && currentWorkflowStep.enableColock) || (currentWorkflowStep?.enableReleaseColock == true && currentWorkflowStep.enableUnlock || ticketPoints?.all { it.pointStatus == ticketPoints.firstOrNull()?.pointStatus } == false)
-                                ) {
+                                if ((currentWorkflowStep?.enableLock == true && currentWorkflowStep.enableColock) || (currentWorkflowStep?.enableReleaseColock == true && currentWorkflowStep.enableUnlock || ticketPoints?.all { it.pointStatus == ticketPoints.firstOrNull()?.pointStatus } == false)) {
                                     logger.info("当前上锁和共锁或者解锁和解除共锁在同一步骤,或者所有点位的状态不统一,不更新步骤状态")
                                 } else {
                                     ticketStepDataVo?.stepStatus = "1"
@@ -915,12 +895,9 @@ object BleBusinessManager {
                         mac,
                         ticketDetail,
                         ticketDetail.ticketLockVOList?.filter {
-                            it.groupId == MainDomainData.deviceTakeTicketGroupBound[it.ticketId] &&
-                                    ticketDetail.ticketPointsVOList?.filter { it.groupId == MainDomainData.deviceTakeTicketGroupBound[it.ticketId] }
-                                        ?.mapNotNull { it.lockId }
-                                        ?.contains(it.lockId) != true
-                        }
-                            ?.map { it.lockNfc }?.toMutableList(),
+                            it.groupId == MainDomainData.deviceTakeTicketGroupBound[it.ticketId] && ticketDetail.ticketPointsVOList?.filter { it.groupId == MainDomainData.deviceTakeTicketGroupBound[it.ticketId] }
+                                ?.mapNotNull { it.lockId }?.contains(it.lockId) != true
+                        }?.map { it.lockNfc }?.toMutableList(),
                         true
                     )
                 } else if (step?.enableUnlock == true) { // 解锁工作票
@@ -938,69 +915,64 @@ object BleBusinessManager {
     @SuppressLint("MissingPermission")
     fun handleGiveKey(deviceTakeUpdateBO: DeviceTakeUpdate) {
         val mac = HardwareMode.getCurrentHardwareMode().getKeyMacByRfid(deviceTakeUpdateBO.nfc)
-        logger.info("取完锁开始发钥匙2:${BleConnectionManager.deviceList.toJson()}")
+            ?: LogicManager.hardwareLogic.getKeyInfo(deviceTakeUpdateBO.nfc)?.macAddress
+        logger.info("取完锁开始发钥匙2:${BleConnectionManager.deviceList.toJson()},${mac}")
         mac?.let {
-            if (BleSendDispatcher.isConnected(it)) {
-                BleSendDispatcher.submit(it) {
-                    BleConnectionManager.getBleDeviceByMac(
-                        HardwareMode.getCurrentHardwareMode()
-                            .getKeyMacByRfid(deviceTakeUpdateBO.nfc)
-                    )
-                        ?.let {
-                            BleConnectionManager.getCurrentStatus(
-                                2, BleConnectionManager.getBleDeviceByMac(
-                                    HardwareMode.getCurrentHardwareMode()
-                                        .getKeyMacByRfid(deviceTakeUpdateBO.nfc)
-                                )!!.bleDevice
-                            ) {
-                                if (!it) {
-                                    return@getCurrentStatus
-                                }
-                                logger.warn("handleGiveKey timeout")
-                                HardwareBusinessManager.removeDeviceTake(
-                                    DeviceConst.DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc
-                                )
-                                HardwareBusinessManager.checkEquipCount(
-                                    deviceTakeUpdateBO.ticketId,
-                                    0,
-                                    true
-                                ) { keyPair, lockMap ->
-                                    if (keyPair == null) {
-                                        TipDialog.show(
-                                            msg = CommonUtils.getStr("key_take_error_tip")
-                                                .toString(),
-                                            onConfirmClick = {
-                                                DeviceExceptionEvent.sendDeviceExceptionEvent(
-                                                    DeviceConst.DEVICE_TYPE_KEY,
-                                                    deviceTakeUpdateBO.nfc
-                                                )
-                                            })
-                                    } else {
-                                        HardwareBusinessManager.addDeviceTake(
+            BleSendDispatcher.submit(it) {
+                BleConnectionManager.getBleDeviceByMac(
+                    HardwareMode.getCurrentHardwareMode()
+                        .getKeyMacByRfid(deviceTakeUpdateBO.nfc)
+                )?.let {
+                    BleConnectionManager.getCurrentStatus(
+                        2, BleConnectionManager.getBleDeviceByMac(
+                            HardwareMode.getCurrentHardwareMode()
+                                .getKeyMacByRfid(deviceTakeUpdateBO.nfc)
+                        )!!.bleDevice
+                    ) {
+                        if (!it) {
+                            return@getCurrentStatus
+                        }
+                        logger.warn("handleGiveKey timeout")
+                        HardwareBusinessManager.removeDeviceTake(
+                            DeviceConst.DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc
+                        )
+                        HardwareBusinessManager.checkEquipCount(
+                            deviceTakeUpdateBO.ticketId, 0, true
+                        ) { keyPair, lockMap ->
+                            if (keyPair == null) {
+                                TipDialog.show(
+                                    msg = CommonUtils.getStr("key_take_error_tip")
+                                        .toString(), onConfirmClick = {
+                                        DeviceExceptionEvent.sendDeviceExceptionEvent(
                                             DeviceConst.DEVICE_TYPE_KEY,
-                                            deviceTakeUpdateBO.ticketId,
-                                            keyPair.second
-                                        )
-                                        handleGiveKey(
-                                            DeviceTakeUpdate(
-                                                DeviceConst.DEVICE_TYPE_KEY,
-                                                deviceTakeUpdateBO.ticketId,
-                                                keyPair.second ?: ""
-                                            )
+                                            deviceTakeUpdateBO.nfc
                                         )
-                                    }
-                                }
-                            }
-                        } ?: run {
-                        logger.info("根据钥匙的rfid没找到钥匙")
-                        TipDialog.show(
-                            msg = CommonUtils.getStr("key_take_error_tip").toString(),
-                            onConfirmClick = {
-                                DeviceExceptionEvent.sendDeviceExceptionEvent(
-                                    DeviceConst.DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc
+                                    })
+                            } else {
+                                HardwareBusinessManager.addDeviceTake(
+                                    DeviceConst.DEVICE_TYPE_KEY,
+                                    deviceTakeUpdateBO.ticketId,
+                                    keyPair.second
+                                )
+                                handleGiveKey(
+                                    DeviceTakeUpdate(
+                                        DeviceConst.DEVICE_TYPE_KEY,
+                                        deviceTakeUpdateBO.ticketId,
+                                        keyPair.second ?: ""
+                                    )
                                 )
-                            })
+                            }
+                        }
                     }
+                } ?: run {
+                    logger.info("根据钥匙的rfid没找到钥匙")
+                    TipDialog.show(
+                        msg = CommonUtils.getStr("key_take_error_tip").toString(),
+                        onConfirmClick = {
+                            DeviceExceptionEvent.sendDeviceExceptionEvent(
+                                DeviceConst.DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc
+                            )
+                        })
                 }
             }
         }
@@ -1035,16 +1007,13 @@ object BleBusinessManager {
                                 "abnormal"
                             )
                         }?.dictValue
-                    }?.toMutableList() ?: mutableListOf(),
-                    (keyPage?.records?.filter {
+                    }?.toMutableList() ?: mutableListOf(), (keyPage?.records?.filter {
                         it.exStatus == keyStatusList.find { d ->
                             I18nManager.t(
                                 d.dictLabel
                             ) == I18nManager.t("abnormal")
                         }?.dictValue
-                    }
-                        ?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()),
-                    exceptKeyMac
+                    }?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()), exceptKeyMac
                 )
             }
         }

+ 3 - 1
ui-base/src/main/java/com/grkj/ui_base/business/DataBusiness.kt

@@ -78,7 +78,9 @@ object DataBusiness {
             if (BleSendDispatcher.canConnect()) {
                 logger.info("蓝牙连接-发送队列可以连接")
                 mac?.let {
-                    connectExistsKey(listOf(it))
+//                    if (MainDomainData.returnKeyList.isEmpty()) {
+//                        connectExistsKey(listOf(it))
+//                    }
                 }
             }
         } else {

+ 6 - 6
ui-base/src/main/java/com/grkj/ui_base/business/HardwareBusinessManager.kt

@@ -158,7 +158,7 @@ object HardwareBusinessManager {
                     ?.let { info ->
                         logger.info("钥匙设备数据:${info}")
                         if (mDeviceTakeList.any { it.deviceType == DeviceConst.DEVICE_TYPE_LOCK && it.ticketId == info.ticketId }) {
-                            BleSendDispatcher.scheduleDisconnect(getKeyMacByRfid(info.nfc), 60_000)
+                            BleSendDispatcher.scheduleDisconnect(getKeyMacByRfid(info.nfc))
                             logger.info("存在未取出的挂锁,不继续操作")
                             return
                         }
@@ -366,7 +366,7 @@ object HardwareBusinessManager {
         val deviceType = CanHelper.getDeviceTypeByNodeId(res[0].nodeId)
         when (deviceType) {
             CanDeviceConst.DEVICE_KEY_DOCK -> {
-                if (MainDomainData.userInfo==null){
+                if (MainDomainData.userInfo == null) {
                     return
                 }
                 res.filterIsInstance<DeviceModel.DeviceKey>().forEach {
@@ -375,7 +375,7 @@ object HardwareBusinessManager {
             }
 
             CanDeviceConst.DEVICE_LOCK_DOCK -> {
-                if (MainDomainData.userInfo==null){
+                if (MainDomainData.userInfo == null) {
                     return
                 }
                 res.filterIsInstance<DeviceModel.CommonDevice>().forEach {
@@ -425,9 +425,6 @@ object HardwareBusinessManager {
         }
         res.forEachIndexed { index, bytes ->
             val dockBean = ModBusController.updateStatus(bytes) ?: return@forEachIndexed
-            if (MainDomainData.userInfo == null) {
-                return@forEachIndexed
-            }
             when (dockBean.type) {
                 DeviceConst.DOCK_TYPE_KEY -> {
                     dockBean.getKeyList().forEach { keyBean ->
@@ -841,6 +838,9 @@ object HardwareBusinessManager {
                                     ModBusController.updateKeyMac(
                                         dockBean.addr, keyBean.idx, it.macAddress!!
                                     )
+                                    it.macAddress?.let {
+                                        MainDomainData.returnKeyList.add(it)
+                                    }
                                     ModBusController.updateKeyReadyStatus(
                                         it.macAddress!!, false, 5
                                     )