|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.grkj.iscs
|
|
|
+package com.grkj.iscs_mars
|
|
|
//todo 所有蓝牙包替换com.clj. -> com.clj.
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
@@ -8,71 +8,72 @@ import com.clj.fastble.BleManager
|
|
|
import com.clj.fastble.data.BleDevice
|
|
|
import com.clj.fastble.exception.BleException
|
|
|
import com.google.gson.Gson
|
|
|
-import com.grkj.iscs.ble.BleBean
|
|
|
-import com.grkj.iscs.ble.BleCmdManager
|
|
|
-import com.grkj.iscs.ble.BleConnectionManager
|
|
|
-import com.grkj.iscs.ble.BleConst
|
|
|
-import com.grkj.iscs.ble.BleConst.STATUS_READY
|
|
|
-import com.grkj.iscs.ble.BleConst.STATUS_WORK
|
|
|
-import com.grkj.iscs.ble.BleUtil
|
|
|
-import com.grkj.iscs.ble.CustomBleWriteCallback
|
|
|
-import com.grkj.iscs.extentions.removeLeadingZeros
|
|
|
-import com.grkj.iscs.extentions.serialNo
|
|
|
-import com.grkj.iscs.extentions.startsWith
|
|
|
-import com.grkj.iscs.extentions.toHexStrings
|
|
|
-import com.grkj.iscs.modbus.DockBean
|
|
|
-import com.grkj.iscs.modbus.ModBusController
|
|
|
-import com.grkj.iscs.modbus.ModBusController.dockList
|
|
|
-import com.grkj.iscs.modbus.ModBusController.getOneKey
|
|
|
-import com.grkj.iscs.model.Constants.USER_TYPE_LOCKER
|
|
|
-import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
-import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
|
-import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
-import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_LOCK
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_ELEC_LOCK_BOARD
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
|
|
|
-import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
-import com.grkj.iscs.model.DictAndSystemConstants
|
|
|
-import com.grkj.iscs.model.ISCSDomainData
|
|
|
-import com.grkj.iscs.model.bo.DeviceTakeUpdateBO
|
|
|
-import com.grkj.iscs.model.bo.UpdateKeyReturnBO
|
|
|
-import com.grkj.iscs.model.bo.WorkTicketGetBO
|
|
|
-import com.grkj.iscs.model.bo.WorkTicketSendBO
|
|
|
-import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
|
|
|
-import com.grkj.iscs.model.eventmsg.CurrentModeMsg
|
|
|
-import com.grkj.iscs.model.eventmsg.DeviceExceptionMsg
|
|
|
-import com.grkj.iscs.model.eventmsg.DeviceTakeUpdateMsg
|
|
|
-import com.grkj.iscs.model.eventmsg.LoadingMsg
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEvent
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_CURRENT_MODE
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_EXCEPTION
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_TAKE_UPDATE
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_SWITCH_COLLECTION_UPDATE
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_SWITCH_MODE
|
|
|
-import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_UPDATE_TICKET_PROGRESS
|
|
|
-import com.grkj.iscs.model.eventmsg.SwitchModeMsg
|
|
|
-import com.grkj.iscs.model.eventmsg.UpdateTicketProgressMsg
|
|
|
-import com.grkj.iscs.model.vo.dict.CommonDictRespVO
|
|
|
-import com.grkj.iscs.model.vo.hardware.CabinetSlotsRespVo
|
|
|
-import com.grkj.iscs.model.vo.hardware.SwitchListReqVO
|
|
|
-import com.grkj.iscs.model.vo.key.KeyPageRespVO
|
|
|
-import com.grkj.iscs.model.vo.lock.LockPageRespVO
|
|
|
-import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
|
|
|
-import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
|
|
|
-import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
|
|
|
-import com.grkj.iscs.util.ActivityUtils
|
|
|
-import com.grkj.iscs.util.CommonUtils
|
|
|
-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.activity.LoginActivity
|
|
|
-import com.grkj.iscs.view.base.BaseActivity
|
|
|
-import com.grkj.iscs.view.dialog.TipDialog
|
|
|
+import com.grkj.iscs_mars.ble.BleBean
|
|
|
+import com.grkj.iscs_mars.ble.BleCmdManager
|
|
|
+import com.grkj.iscs_mars.ble.BleConnectionManager
|
|
|
+import com.grkj.iscs_mars.ble.BleConst
|
|
|
+import com.grkj.iscs_mars.ble.BleConst.STATUS_READY
|
|
|
+import com.grkj.iscs_mars.ble.BleConst.STATUS_WORK
|
|
|
+import com.grkj.iscs_mars.ble.BleUtil
|
|
|
+import com.grkj.iscs_mars.ble.CustomBleWriteCallback
|
|
|
+import com.grkj.iscs_mars.extentions.removeLeadingZeros
|
|
|
+import com.grkj.iscs_mars.extentions.serialNo
|
|
|
+import com.grkj.iscs_mars.extentions.startsWith
|
|
|
+import com.grkj.iscs_mars.extentions.toHexStrings
|
|
|
+import com.grkj.iscs_mars.modbus.DockBean
|
|
|
+import com.grkj.iscs_mars.modbus.ModBusController
|
|
|
+import com.grkj.iscs_mars.modbus.ModBusController.dockList
|
|
|
+import com.grkj.iscs_mars.modbus.ModBusController.getOneKey
|
|
|
+import com.grkj.iscs_mars.model.Constants.USER_TYPE_LOCKER
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_LOCK
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_ELEC_LOCK_BOARD
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_LOCK
|
|
|
+import com.grkj.iscs_mars.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
+import com.grkj.iscs_mars.model.DictAndSystemConstants
|
|
|
+import com.grkj.iscs_mars.model.ISCSDomainData
|
|
|
+import com.grkj.iscs_mars.model.bo.DeviceTakeUpdateBO
|
|
|
+import com.grkj.iscs_mars.model.bo.UpdateKeyReturnBO
|
|
|
+import com.grkj.iscs_mars.model.bo.WorkTicketGetBO
|
|
|
+import com.grkj.iscs_mars.model.bo.WorkTicketSendBO
|
|
|
+import com.grkj.iscs_mars.model.bo.WorkTicketSendBO.LockListBO
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.CurrentModeMsg
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.DeviceExceptionMsg
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.DeviceTakeUpdateMsg
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.LoadingMsg
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEvent
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_CURRENT_MODE
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_EXCEPTION
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_TAKE_UPDATE
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_SWITCH_COLLECTION_UPDATE
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_SWITCH_MODE
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.MsgEventConstants.MSG_EVENT_UPDATE_TICKET_PROGRESS
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.SwitchModeMsg
|
|
|
+import com.grkj.iscs_mars.model.eventmsg.UpdateTicketProgressMsg
|
|
|
+import com.grkj.iscs_mars.model.vo.dict.CommonDictRespVO
|
|
|
+import com.grkj.iscs_mars.model.vo.hardware.CabinetSlotsRespVo
|
|
|
+import com.grkj.iscs_mars.model.vo.hardware.SwitchListReqVO
|
|
|
+import com.grkj.iscs_mars.model.vo.key.KeyPageRespVO
|
|
|
+import com.grkj.iscs_mars.model.vo.lock.LockPageRespVO
|
|
|
+import com.grkj.iscs_mars.model.vo.lock.LockTakeUpdateReqVO
|
|
|
+import com.grkj.iscs_mars.model.vo.ticket.LockPointUpdateReqVO
|
|
|
+import com.grkj.iscs_mars.model.vo.ticket.TicketDetailRespVO
|
|
|
+import com.grkj.iscs_mars.util.ActivityUtils
|
|
|
+import com.grkj.iscs_mars.util.CommonUtils
|
|
|
+import com.grkj.iscs_mars.util.Executor
|
|
|
+import com.grkj.iscs_mars.util.NetApi
|
|
|
+import com.grkj.iscs_mars.util.SPUtils
|
|
|
+import com.grkj.iscs_mars.util.ToastUtils
|
|
|
+import com.grkj.iscs_mars.util.log.LogUtil
|
|
|
+import com.grkj.iscs_mars.view.activity.LoginActivity
|
|
|
+import com.grkj.iscs_mars.view.base.BaseActivity
|
|
|
+import com.grkj.iscs_mars.view.dialog.TipDialog
|
|
|
+import com.sik.sikcore.SIKCore
|
|
|
import com.sik.sikcore.date.TimeUtils
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
@@ -354,178 +355,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 +375,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 +415,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)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新所有锁仓状态
|
|
|
*/
|
|
|
@@ -763,6 +703,7 @@ object BusinessManager {
|
|
|
private suspend fun getKeyPage(): KeyPageRespVO? = suspendCancellableCoroutine { cont ->
|
|
|
NetApi.getIsKeyPage { keys ->
|
|
|
cont.resume(keys)
|
|
|
+ cont.cancel()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1277,7 +1218,7 @@ object BusinessManager {
|
|
|
fun getCurrentStatus(
|
|
|
from: Int,
|
|
|
bleDevice: BleDevice,
|
|
|
- retryCount: Int = 3,
|
|
|
+ retryCount: Int = 0,
|
|
|
timeoutCallBack: ((Boolean) -> Unit)? = null
|
|
|
) {
|
|
|
LogUtil.i("getCurrentStatus - ${bleDevice.mac} - from : $from")
|
|
|
@@ -1392,6 +1333,17 @@ object BusinessManager {
|
|
|
if (finishedStatus.first) {
|
|
|
Executor.delayOnMain(500) {
|
|
|
handleKeyReturn(bleDevice, workTicketGetBO, finishedStatus.second)
|
|
|
+ //检查钥匙是否代取,如果是的话给钥匙
|
|
|
+ val keyBean = ModBusController.getKeyByMac(bleDevice.mac)
|
|
|
+ mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == keyBean?.rfid }
|
|
|
+ ?.let { itKey ->
|
|
|
+ sendLoadingEventMsg(
|
|
|
+ MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.ble_connecting
|
|
|
+ )
|
|
|
+ )
|
|
|
+ handleGiveKey(itKey)
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
// 当前策略:作业票未完成禁止归还钥匙
|
|
|
@@ -1425,10 +1377,11 @@ object BusinessManager {
|
|
|
ModBusController.controlKeyBuckle(false, keyBean.isLeft, dock.addr)
|
|
|
}
|
|
|
if (ticketFinished) {
|
|
|
+ mDeviceTakeList.removeIf { it.nfc == keyBean?.rfid }
|
|
|
switchReadyMode(bleDevice)
|
|
|
} else {
|
|
|
// 上报隔离点状态
|
|
|
- val keyNfc = ModBusController.getKeyByMac(bleDevice.mac)?.rfid?:"key rfid lost"
|
|
|
+ val keyNfc = ModBusController.getKeyByMac(bleDevice.mac)?.rfid ?: "key rfid lost"
|
|
|
workTicketGetBO?.data?.forEach { data ->
|
|
|
val updateList = mutableListOf<LockPointUpdateReqVO>()
|
|
|
data.dataList?.forEach { dataListDTO ->
|
|
|
@@ -1763,10 +1716,10 @@ object BusinessManager {
|
|
|
checkEquipCount(0, true) { keyPair, lockMap ->
|
|
|
if (keyPair == null) {
|
|
|
ThreadUtils.runOnMain {
|
|
|
-
|
|
|
- val ctx = MyApplication.instance?.applicationContext!!
|
|
|
- val tipDialog = TipDialog(ctx)
|
|
|
- tipDialog.setTip(ctx.getString(R.string.key_take_error_tip))
|
|
|
+ val tipDialog = TipDialog(SIKCore.getApplication())
|
|
|
+ tipDialog.setTip(
|
|
|
+ SIKCore.getApplication().getString(R.string.key_take_error_tip)
|
|
|
+ )
|
|
|
tipDialog.setConfirmListener {
|
|
|
tipDialog.dismiss()
|
|
|
sendEventMsg(
|
|
|
@@ -1792,9 +1745,8 @@ object BusinessManager {
|
|
|
}
|
|
|
} ?: run {
|
|
|
ThreadUtils.runOnMain {
|
|
|
- val ctx = MyApplication.instance?.applicationContext!!
|
|
|
- val tipDialog = TipDialog(ctx)
|
|
|
- tipDialog.setTip(ctx.getString(R.string.key_take_error_tip))
|
|
|
+ val tipDialog = TipDialog(SIKCore.getApplication())
|
|
|
+ tipDialog.setTip(SIKCore.getApplication().getString(R.string.key_take_error_tip))
|
|
|
tipDialog.setConfirmListener {
|
|
|
tipDialog.dismiss()
|
|
|
sendEventMsg(
|
|
|
@@ -1875,7 +1827,10 @@ object BusinessManager {
|
|
|
currentModeMsg.bleBean.bleDevice.mac, true, 4
|
|
|
)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
- //连上之后没有工作票要下发就断开 todo不断开,还钥匙的时候有可能断开全部,原本要锁定仓位,但是会出现快速取出钥匙锁定
|
|
|
+ //连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
+ if (BleConnectionManager.hasConnectWait()) {
|
|
|
+ BleManager.getInstance().disconnect(currentModeMsg.bleBean.bleDevice)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1996,6 +1951,7 @@ object BusinessManager {
|
|
|
}
|
|
|
|
|
|
fun logout(context: Context) {
|
|
|
+ reConnectKey()
|
|
|
NetApi.logout()
|
|
|
// 关所有有设备的卡扣
|
|
|
dockList.filter { it.type == DOCK_TYPE_LOCK || it.type == DOCK_TYPE_PORTABLE }
|
|
|
@@ -2027,7 +1983,6 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- reConnectKey()
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
context.startActivity(Intent(context, LoginActivity::class.java))
|
|
|
}
|