Kaynağa Gözat

refactor(更新) :
- 地址修改,代码提取

周文健 4 ay önce
ebeveyn
işleme
19197ba551

+ 2 - 2
app/build.gradle

@@ -42,9 +42,9 @@ android {
             signingConfig signingConfigs.release
         }
         release {
-            minifyEnabled true  // 混淆
+            minifyEnabled false  // 混淆
             zipAlignEnabled true // 进行压缩优化
-            shrinkResources true    // 移除无用的resource文件
+            shrinkResources false    // 移除无用的resource文件
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
             signingConfig signingConfigs.release
         }

+ 183 - 244
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -354,178 +354,13 @@ object BusinessManager {
             when (dockBean.type) {
                 DOCK_TYPE_KEY -> {
                     dockBean.getKeyList().forEach { keyBean ->
-                        if (keyBean.isExist) {
-                            // 放回钥匙,读取rfid
-                            ModBusController.readKeyRfid(
-                                dockBean.addr, if (keyBean.isLeft) 0 else 1
-                            ) { isLeft, res ->
-                                if (!ISCSDomainData.isDeviceRegistration) {
-                                    ModBusController.controlKeyCharge(
-                                        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()
-                                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 keyStatusReq =
-                                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_KEY_STATUS) }
-                                    val keyPageReq = async { getKeyPage() }
-                                    var keyStatus = keyStatusReq.await()
-                                    var keyData = keyPageReq.await()
-                                    val slotsPage = slotsPageReq.await()
-                                    val slotStatusList = slotStatus.await()
-                                    val slotTypeList = slotType.await()
-                                    //锁钥匙未异常正常请求锁数据,关锁
-                                    if (rfid in (keyData?.records?.filter { it.exStatus == keyStatus.find { it.dictLabel == "异常" }?.dictValue }
-                                            ?.map { it.keyNfc }?.toMutableList()
-                                            ?: mutableListOf())
-                                    ) {
-                                        ToastUtils.tip(
-                                            MyApplication.instance?.applicationContext!!.getString(
-                                                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) {
-                                        ToastUtils.tip(
-                                            MyApplication.instance?.applicationContext!!.getString(
-                                                R.string.slot_exception_tag
-                                            )
-                                        )
-                                    } else {
-                                        ModBusController.updateKeyRfid(
-                                            dockBean.addr, keyBean.isLeft, rfid
-                                        )
-                                        // 放回钥匙,上锁
-                                        ModBusController.controlKeyBuckle(
-                                            false, keyBean.isLeft, dockBean.addr
-                                        ) {
-                                            NetApi.getKeyInfo(rfid) {
-                                                ModBusController.updateKeyNewHardware(
-                                                    dockBean.addr, true, it == null
-                                                )
-                                                if (it != null && !it.macAddress.isNullOrEmpty()) {
-                                                    ModBusController.updateKeyMac(
-                                                        dockBean.addr, keyBean.isLeft, it.macAddress
-                                                    )
-                                                    ModBusController.updateKeyReadyStatus(
-                                                        it.macAddress, false, 5
-                                                    )
-                                                } else {
-                                                    LogUtil.e("Get key info fail : $rfid")
-                                                    if (!ISCSDomainData.isDeviceRegistration) {
-                                                        ToastUtils.tip(R.string.get_key_info_fail)
-                                                    }
-                                                    ModBusController.controlKeyBuckle(
-                                                        true, keyBean.isLeft, dockBean.addr
-                                                    )
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        } else if (!keyBean.isCharging) {//增加充电判断,防止无线充电干扰锁仓状态导致判断为取出
-                            // 移出待连监听集合,防止connectKey循环失败
-                            keyBean.mac?.let {
-                                unregisterConnectListener(it)
-                            }
-                            sendEventMsg(
-                                MsgEvent(
-                                    MSG_EVENT_DEVICE_TAKE_UPDATE,
-                                    DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)
-                                )
-                            )
-                        }
+                        deviceKeyHandler(dockBean,keyBean)
                     }
                 }
 
                 DOCK_TYPE_LOCK -> {
                     dockBean.getLockList().forEach { lockBean ->
-                        if (lockBean.isExist) {
-                            ModBusController.readLockRfid(dockBean.addr, lockBean.idx) { res ->
-                                if (res.size < 11) {
-                                    LogUtil.e("Lock rfid error")
-                                    return@readLockRfid
-                                }
-                                val rfid =
-                                    res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
-                                ModBusController.updateLockRfid(
-                                    dockBean.addr, lockBean.idx, rfid
-                                )
-                                ThreadUtils.runOnIO {
-                                    val lockStatusReq =
-                                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_PAD_LOCK_STATUS) }
-                                    val slotStatus =
-                                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
-                                    val slotType =
-                                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
-                                    val slotsPageReq = async { getSlotsPage() }
-                                    var lockStatus = lockStatusReq.await()
-                                    val slotsPage = slotsPageReq.await()
-                                    val slotStatusList = slotStatus.await()
-                                    val slotTypeList = slotType.await()
-                                    NetApi.getIsLockPage { lockData ->
-                                        //锁rfid未异常正常请求锁数据,关锁
-                                        if (rfid in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
-                                                ?.map { it.lockNfc }?.toMutableList()
-                                                ?: mutableListOf())
-                                        ) {
-                                            ToastUtils.tip(
-                                                MyApplication.instance?.applicationContext!!.getString(
-                                                    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) {
-                                            ToastUtils.tip(
-                                                MyApplication.instance?.applicationContext!!.getString(
-                                                    R.string.slot_exception_tag
-                                                )
-                                            )
-                                        } else {
-                                            NetApi.getLockInfo(rfid) {
-                                                if (it != null) {
-                                                    // TODO 考虑快速拿取
-                                                    ModBusController.controlLockBuckle(
-                                                        false, dockBean.addr, lockBean.idx
-                                                    ) { itRst ->
-                                                        if (itRst.isNotEmpty()) {
-                                                            // 上报锁具信息
-                                                            NetApi.updateLockReturn(
-                                                                rfid,
-                                                                MyApplication.instance!!.serialNo()
-                                                            ) {}
-                                                        }
-                                                    }
-                                                }
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        } else {
-                            LogUtil.i("挂锁取出-:${lockBean.rfid}")
-                            sendEventMsg(
-                                MsgEvent(
-                                    MSG_EVENT_DEVICE_TAKE_UPDATE,
-                                    DeviceTakeUpdateMsg(DEVICE_TYPE_LOCK, lockBean.rfid)
-                                )
-                            )
-                        }
+                        deviceLockHandler(dockBean,lockBean)
                     }
                 }
 
@@ -539,86 +374,11 @@ object BusinessManager {
                         if (deviceBean.isExist) {
                             when (deviceBean.type) {
                                 DEVICE_TYPE_KEY -> {
-                                    ModBusController.readKeyRfid(
-                                        dockBean.addr, deviceBean.idx
-                                    ) { isLeft, res ->
-                                        if (res.size < 11) {
-                                            LogUtil.e("Key rfid error")
-                                            return@readKeyRfid
-                                        }
-                                        val rfid = res.copyOfRange(3, 11).toHexStrings(false)
-                                            .removeLeadingZeros()
-                                        ModBusController.updateKeyRfid(
-                                            dockBean.addr, true, rfid
-                                        )
-                                        NetApi.getKeyInfo(rfid) {
-                                            ModBusController.updateKeyNewHardware(
-                                                dockBean.addr, true, it == null
-                                            )
-                                            if (it != null && !it.macAddress.isNullOrEmpty()) {
-                                                ModBusController.updateKeyMac(
-                                                    dockBean.addr, isLeft, it.macAddress
-                                                )
-//                                                    showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr)
-                                            } else {
-                                                ToastUtils.tip(R.string.get_key_info_fail)
-                                            }
-                                        }
-                                        // TODO 蓝牙通信
-                                    }
+                                    deviceKeyHandler(dockBean,deviceBean as DockBean.KeyBean)
                                 }
 
                                 DEVICE_TYPE_LOCK -> {
-                                    ModBusController.readLockRfid(
-                                        dockBean.addr, deviceBean.idx
-                                    ) { res ->
-                                        if (res.size < 11) {
-                                            LogUtil.e("Lock rfid error")
-                                            return@readLockRfid
-                                        }
-                                        val rfid = res.copyOfRange(3, 11).toHexStrings(false)
-                                            .removeLeadingZeros()
-                                        ModBusController.updateLockRfid(
-                                            dockBean.addr, deviceBean.idx, rfid
-                                        )
-                                        ThreadUtils.runOnIO {
-                                            val lockStatusReq = async {
-                                                fetchDict<CommonDictRespVO>(
-                                                    DictAndSystemConstants.KEY_PAD_LOCK_STATUS
-                                                )
-                                            }
-                                            var lockStatus = lockStatusReq.await()
-                                            NetApi.getIsLockPage { lockData ->
-                                                //锁rfid未异常正常请求锁数据,关锁
-                                                if (rfid !in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
-                                                        ?.map { it.lockNfc }?.toMutableList()
-                                                        ?: mutableListOf())
-                                                ) {
-                                                    NetApi.getLockInfo(rfid) {
-                                                        ModBusController.updateLockNewHardware(
-                                                            dockBean.addr,
-                                                            deviceBean.idx,
-                                                            it == null
-                                                        )
-                                                        if (it != null) {
-                                                            // TODO 考虑快速拿取
-                                                            ModBusController.controlLockBuckle(
-                                                                false, dockBean.addr, deviceBean.idx
-                                                            ) { itRst ->
-                                                                if (itRst.isNotEmpty()) {
-                                                                    // 上报锁具信息
-                                                                    NetApi.updateLockReturn(
-                                                                        rfid,
-                                                                        MyApplication.instance!!.serialNo()
-                                                                    ) {}
-                                                                }
-                                                            }
-                                                        }
-                                                    }
-                                                }
-                                            }
-                                        }
-                                    }
+                                    deviceLockHandler(dockBean,deviceBean as DockBean.LockBean)
                                 }
 
                                 DEVICE_TYPE_CARD -> {
@@ -654,6 +414,185 @@ object BusinessManager {
         }
     }
 
+    /**
+     * 挂锁处理
+     */
+    private fun deviceLockHandler(
+        dockBean: DockBean,
+        lockBean: DockBean.LockBean
+    ) {
+        if (lockBean.isExist) {
+            ModBusController.readLockRfid(dockBean.addr, lockBean.idx) { res ->
+                if (res.size < 11) {
+                    LogUtil.e("Lock rfid error")
+                    return@readLockRfid
+                }
+                val rfid =
+                    res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
+                ModBusController.updateLockRfid(
+                    dockBean.addr, lockBean.idx, rfid
+                )
+                ThreadUtils.runOnIO {
+                    val lockStatusReq =
+                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_PAD_LOCK_STATUS) }
+                    val slotStatus =
+                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
+                    val slotType =
+                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
+                    val slotsPageReq = async { getSlotsPage() }
+                    var lockStatus = lockStatusReq.await()
+                    val slotsPage = slotsPageReq.await()
+                    val slotStatusList = slotStatus.await()
+                    val slotTypeList = slotType.await()
+                    NetApi.getIsLockPage { lockData ->
+                        //锁rfid未异常正常请求锁数据,关锁
+                        if (rfid in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
+                                ?.map { it.lockNfc }?.toMutableList()
+                                ?: mutableListOf())
+                        ) {
+                            ToastUtils.tip(
+                                MyApplication.instance?.applicationContext!!.getString(
+                                    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) {
+                            ToastUtils.tip(
+                                MyApplication.instance?.applicationContext!!.getString(
+                                    R.string.slot_exception_tag
+                                )
+                            )
+                        } else {
+                            NetApi.getLockInfo(rfid) {
+                                if (it != null) {
+                                    // TODO 考虑快速拿取
+                                    ModBusController.controlLockBuckle(
+                                        false, dockBean.addr, lockBean.idx
+                                    ) { itRst ->
+                                        if (itRst.isNotEmpty()) {
+                                            // 上报锁具信息
+                                            NetApi.updateLockReturn(
+                                                rfid,
+                                                MyApplication.instance!!.serialNo()
+                                            ) {}
+                                        }
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } else {
+            LogUtil.i("挂锁取出-:${lockBean.rfid}")
+            sendEventMsg(
+                MsgEvent(
+                    MSG_EVENT_DEVICE_TAKE_UPDATE,
+                    DeviceTakeUpdateMsg(DEVICE_TYPE_LOCK, lockBean.rfid)
+                )
+            )
+        }
+    }
+
+    private fun deviceKeyHandler(dockBean: DockBean,keyBean: DockBean.KeyBean) {
+        if (keyBean.isExist) {
+            // 放回钥匙,读取rfid
+            ModBusController.readKeyRfid(
+                dockBean.addr, if (keyBean.isLeft) 0 else 1
+            ) { isLeft, res ->
+                if (!ISCSDomainData.isDeviceRegistration) {
+                    ModBusController.controlKeyCharge(
+                        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()
+                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 keyStatusReq =
+                        async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_KEY_STATUS) }
+                    val keyPageReq = async { getKeyPage() }
+                    var keyStatus = keyStatusReq.await()
+                    var keyData = keyPageReq.await()
+                    val slotsPage = slotsPageReq.await()
+                    val slotStatusList = slotStatus.await()
+                    val slotTypeList = slotType.await()
+                    //锁钥匙未异常正常请求锁数据,关锁
+                    if (rfid in (keyData?.records?.filter { it.exStatus == keyStatus.find { it.dictLabel == "异常" }?.dictValue }
+                            ?.map { it.keyNfc }?.toMutableList()
+                            ?: mutableListOf())
+                    ) {
+                        ToastUtils.tip(
+                            MyApplication.instance?.applicationContext!!.getString(
+                                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) {
+                        ToastUtils.tip(
+                            MyApplication.instance?.applicationContext!!.getString(
+                                R.string.slot_exception_tag
+                            )
+                        )
+                    } else {
+                        ModBusController.updateKeyRfid(
+                            dockBean.addr, keyBean.isLeft, rfid
+                        )
+                        // 放回钥匙,上锁
+                        ModBusController.controlKeyBuckle(
+                            false, keyBean.isLeft, dockBean.addr
+                        ) {
+                            NetApi.getKeyInfo(rfid) {
+                                ModBusController.updateKeyNewHardware(
+                                    dockBean.addr, true, it == null
+                                )
+                                if (it != null && !it.macAddress.isNullOrEmpty()) {
+                                    ModBusController.updateKeyMac(
+                                        dockBean.addr, keyBean.isLeft, it.macAddress
+                                    )
+                                    ModBusController.updateKeyReadyStatus(
+                                        it.macAddress, false, 5
+                                    )
+                                } else {
+                                    LogUtil.e("Get key info fail : $rfid")
+                                    if (!ISCSDomainData.isDeviceRegistration) {
+                                        ToastUtils.tip(R.string.get_key_info_fail)
+                                    }
+                                    ModBusController.controlKeyBuckle(
+                                        true, keyBean.isLeft, dockBean.addr
+                                    )
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        } else if (!keyBean.isCharging) {//增加充电判断,防止无线充电干扰锁仓状态导致判断为取出
+            // 移出待连监听集合,防止connectKey循环失败
+            keyBean.mac?.let {
+                unregisterConnectListener(it)
+            }
+            sendEventMsg(
+                MsgEvent(
+                    MSG_EVENT_DEVICE_TAKE_UPDATE,
+                    DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)
+                )
+            )
+        }
+    }
+
     /**
      * 更新所有锁仓状态
      */

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

@@ -167,7 +167,6 @@ object BleConnectionManager {
                         listener.callBack?.invoke(false, null)
                         unregisterConnectListener(listener.mac)
                     }
-                    ModBusController.controlKeyBuckle(true, listener.mac)
                     LogUtil.i("蓝牙连接-连接钥匙失败")
                     return@runOnMain
                 }

+ 2 - 2
app/src/main/java/com/grkj/iscs/model/UrlConsts.kt

@@ -4,10 +4,10 @@ object UrlConsts {
     //    const val BASE_URL = "http://192.168.28.82:9190"  // 本地
 //    const val BASE_URL = "http://192.168.28.97:9190"    // 车
 //    const val BASE_URL = "http://36.133.174.236:9190"    // 外
-//    const val BASE_URL = "http://192.168.0.10:9190"    // 外
+    const val BASE_URL = "http://192.168.0.10:9190"    // 外
 //    const val BASE_URL = "http://192.168.1.121:9190"    // 外
 
-    const val BASE_URL = "http://120.27.232.27:9190"    // 外
+//    const val BASE_URL = "http://120.27.232.27:9190"    // 外
     const val WEB_SOCKET = "ws://192.168.1.127:9090/websocket/iot/127"
 
     const val AUTOCODE_TICKET_NUMBER = "JOB_TICKET_CODE"