|
|
@@ -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)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 更新所有锁仓状态
|
|
|
*/
|