|
|
@@ -19,6 +19,7 @@ import com.grkj.data.entity.local.DeviceTakeUpdate
|
|
|
import com.grkj.data.net.req.LockTakeUpdateReq
|
|
|
import com.grkj.data.utils.event.LoadingEvent
|
|
|
import com.grkj.shared.utils.extension.removeLeadingZeros
|
|
|
+import com.grkj.shared.utils.extension.toHexFromLe
|
|
|
import com.grkj.shared.utils.extension.toHexStrings
|
|
|
import com.grkj.shared.utils.i18n.I18nManager
|
|
|
import com.grkj.ui_base.listeners.CanDeviceListener
|
|
|
@@ -573,81 +574,75 @@ object HardwareBusinessManager {
|
|
|
* Can设备
|
|
|
*/
|
|
|
private fun canDeviceLockHandler(lockBean: DeviceModel.CommonDevice) {
|
|
|
- if (!lockBean.deviceChange) {
|
|
|
- return
|
|
|
- }
|
|
|
- lockBean.deviceChange = false
|
|
|
+ if (!lockBean.deviceChange) return
|
|
|
+
|
|
|
if (lockBean.isExist) {
|
|
|
val req = CanCommands.forDevice(lockBean.nodeId).getSlotRfid_1to5(lockBean.id)
|
|
|
CanHelper.readFrom(req) { res ->
|
|
|
val rfidData = res?.payload ?: byteArrayOf()
|
|
|
- if (rfidData.size < 11) {
|
|
|
+ if (rfidData.size < 4) {
|
|
|
logger.error("Lock rfid error")
|
|
|
+ lockBean.deviceChange = false
|
|
|
return@readFrom
|
|
|
}
|
|
|
- val rfid = rfidData.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ val rfid = rfidData.toHexFromLe()
|
|
|
lockBean.rfid = rfid
|
|
|
ThreadUtils.runOnIO {
|
|
|
- val lockStatusReq =
|
|
|
- async { DataBusiness.fetchDict(DictConstants.KEY_PAD_LOCK_STATUS) }
|
|
|
+ val lockStatusReq = async { DataBusiness.fetchDict(DictConstants.KEY_PAD_LOCK_STATUS) }
|
|
|
val slotStatus = async { DataBusiness.fetchDict(DictConstants.KEY_SLOT_STATUS) }
|
|
|
val slotType = async { DataBusiness.fetchDict(DictConstants.KEY_SLOT_TYPE) }
|
|
|
val slotsPageReq = async { DataBusiness.getSlotsPage() }
|
|
|
+
|
|
|
val lockStatus = lockStatusReq.await()
|
|
|
val slotsPage = slotsPageReq.await()
|
|
|
val slotStatusList = slotStatus.await()
|
|
|
val slotTypeList = slotType.await()
|
|
|
+
|
|
|
LogicManager.hardwareLogic.getIsLockPage { lockData ->
|
|
|
- //锁rfid未异常正常请求锁数据,关锁
|
|
|
- if (rfid in (lockData?.records?.filter {
|
|
|
- it.exStatus == lockStatus.find {
|
|
|
- I18nManager.t(it.dictLabel) == I18nManager.t(
|
|
|
- "abnormal"
|
|
|
- )
|
|
|
- }?.dictValue
|
|
|
- }?.map { it.lockNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
+ val isLockAbnormal = rfid in (lockData?.records?.filter {
|
|
|
+ it.exStatus == lockStatus.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("abnormal") }?.dictValue
|
|
|
+ }?.map { it.lockNfc } ?: emptyList())
|
|
|
+
|
|
|
+ val isSlotAbnormal = slotsPage?.records?.any {
|
|
|
+ it.slotType == slotTypeList.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("lock") }?.dictValue &&
|
|
|
+ it.status == slotStatusList.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("abnormal") }?.dictValue &&
|
|
|
+ it.row?.toInt() == lockBean.nodeId && lockBean.id == it.col?.toInt()
|
|
|
+ } == true
|
|
|
+
|
|
|
+ if (isLockAbnormal) {
|
|
|
PopTip.build().tip(CommonUtils.getStr("lock_exception_tag"))
|
|
|
- } else if (slotsPage?.records?.filter {
|
|
|
- it.slotType == slotTypeList.find { d ->
|
|
|
- I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
- "lock"
|
|
|
- )
|
|
|
- }?.dictValue && it.status == slotStatusList.find { d ->
|
|
|
- I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
- "abnormal"
|
|
|
- )
|
|
|
- }?.dictValue
|
|
|
- }
|
|
|
- ?.find { it.row?.toInt() == lockBean.nodeId && lockBean.id == it.col?.toInt() } != null) {
|
|
|
+ lockBean.deviceChange = false
|
|
|
+ return@getIsLockPage
|
|
|
+ }
|
|
|
+ if (isSlotAbnormal) {
|
|
|
PopTip.build().tip(CommonUtils.getStr("slot_exception_tag"))
|
|
|
- } else {
|
|
|
- logger.info("挂锁归还:${lockBean.rfid}")
|
|
|
- LogicManager.hardwareLogic.getLockInfo(rfid) {
|
|
|
- logger.info("挂锁信息:${it}")
|
|
|
- if (it != null && it.lockNfc?.isNotEmpty() == true) {
|
|
|
- // TODO 考虑快速拿取
|
|
|
- val req = CanCommands.forDevice(lockBean.nodeId)
|
|
|
- .controlOne_1to5(lockBean.id, true)
|
|
|
- CanHelper.writeTo(req) { itRst ->
|
|
|
- // 上报锁具信息
|
|
|
- LogicManager.jobTicketLogic.updateLockReturn(
|
|
|
- rfid, SIKCore.getApplication().serialNo()
|
|
|
- ) {}
|
|
|
- }
|
|
|
- }
|
|
|
- Executor.delayOnMain(200) {
|
|
|
- canListeners.forEach { it.callBack(listOf(lockBean)) }
|
|
|
+ lockBean.deviceChange = false
|
|
|
+ return@getIsLockPage
|
|
|
+ }
|
|
|
+
|
|
|
+ logger.info("挂锁归还:${lockBean.rfid}")
|
|
|
+ LogicManager.hardwareLogic.getLockInfo(rfid) {
|
|
|
+ logger.info("挂锁信息:${it}")
|
|
|
+ if (it != null && it.lockNfc?.isNotEmpty() == true) {
|
|
|
+ val ctrl = CanCommands.forDevice(lockBean.nodeId).controlOne_1to5(lockBean.id, true)
|
|
|
+ CanHelper.writeTo(ctrl) {
|
|
|
+ LogicManager.jobTicketLogic.updateLockReturn(
|
|
|
+ rfid, SIKCore.getApplication().serialNo()
|
|
|
+ ) {}
|
|
|
}
|
|
|
}
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ try { canListeners.forEach { it.callBack(listOf(lockBean)) } }
|
|
|
+ finally { lockBean.deviceChange = false } // ✅ 最后归零
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
logger.info("挂锁取出-:${lockBean.rfid}")
|
|
|
- handleDeviceTake(
|
|
|
- DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_LOCK, lockBean.rfid), lockBean.rfid
|
|
|
- )
|
|
|
+ handleDeviceTake(DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_LOCK, lockBean.rfid), lockBean.rfid)
|
|
|
+ lockBean.deviceChange = false // 取出分支可在同步处理后立即归零
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -656,107 +651,92 @@ object HardwareBusinessManager {
|
|
|
* Can设备
|
|
|
*/
|
|
|
private fun canDeviceKeyHandler(keyBean: DeviceModel.DeviceKey) {
|
|
|
- if (!keyBean.deviceChange) {
|
|
|
- return
|
|
|
- }
|
|
|
- keyBean.deviceChange = false
|
|
|
- logger.info("钥匙状态变化DeviceKeyHandler:${keyBean}")
|
|
|
+ if (!keyBean.deviceChange) return
|
|
|
+
|
|
|
+ logger.info("钥匙状态变化canDeviceKeyHandler:$keyBean")
|
|
|
+
|
|
|
if (keyBean.isExist) {
|
|
|
- // 放回钥匙,读取rfid
|
|
|
- val req = CanCommands.forDevice(keyBean.nodeId).let {
|
|
|
- if (keyBean.id == 0) {
|
|
|
- it.getLeftRfid()
|
|
|
- } else {
|
|
|
- it.getRightRfid()
|
|
|
- }
|
|
|
- }
|
|
|
+ val req = CanCommands.forDevice(keyBean.nodeId).let { if (keyBean.id == 0) it.getLeftRfid() else it.getRightRfid() }
|
|
|
CanHelper.readFrom(req) { res ->
|
|
|
val rfidData = res?.payload ?: byteArrayOf()
|
|
|
if (ISCSConfig.isInit) {
|
|
|
- CanHelper.writeTo(
|
|
|
- CanCommands.forDevice(keyBean.nodeId)
|
|
|
- .setCharge(keyBean.id == 0, keyBean.id == 1)
|
|
|
- ){}
|
|
|
+ CanHelper.writeTo(CanCommands.forDevice(keyBean.nodeId).setCharge(keyBean.id == 0, keyBean.id == 1)){}
|
|
|
}
|
|
|
- if (rfidData.size < 11) {
|
|
|
+ if (rfidData.size < 4) {
|
|
|
logger.error("Key rfid error")
|
|
|
+ keyBean.deviceChange = false
|
|
|
return@readFrom
|
|
|
}
|
|
|
- val rfid = rfidData.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
- logger.info("读取到的rfid:${rfid}")
|
|
|
+ val rfid = rfidData.toHexFromLe()
|
|
|
+ logger.info("读取到的rfid:$rfid")
|
|
|
keyBean.rfid = rfid
|
|
|
- logger.info("更新rfid完成:${keyBean}")
|
|
|
+ logger.info("更新rfid完成:$keyBean")
|
|
|
+
|
|
|
ThreadUtils.runOnIO {
|
|
|
val slotStatus = async { DataBusiness.fetchDict(DictConstants.KEY_SLOT_STATUS) }
|
|
|
val slotType = async { DataBusiness.fetchDict(DictConstants.KEY_SLOT_TYPE) }
|
|
|
val slotsPageReq = async { DataBusiness.getSlotsPage() }
|
|
|
- val keyStatusReq =
|
|
|
- async { DataBusiness.fetchDict(DictConstants.KEY_KEY_STATUS) }
|
|
|
+ val keyStatusReq = async { DataBusiness.fetchDict(DictConstants.KEY_KEY_STATUS) }
|
|
|
val keyPageReq = async { DataBusiness.getKeyPage() }
|
|
|
+
|
|
|
val keyStatus = keyStatusReq.await()
|
|
|
val 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 {
|
|
|
- I18nManager.t(it.dictLabel) == I18nManager.t(
|
|
|
- "abnormal"
|
|
|
- )
|
|
|
- }?.dictValue
|
|
|
- }?.map { it.keyNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
- PopTip.build().tip(
|
|
|
- CommonUtils.getStr("key_exception_tag")
|
|
|
- )
|
|
|
- } else if (slotsPage?.records?.filter {
|
|
|
- it.slotType == slotTypeList.find { d ->
|
|
|
- I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
- "key"
|
|
|
- )
|
|
|
- }?.dictValue && it.status == slotStatusList.find { d ->
|
|
|
- I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
- "abnormal"
|
|
|
- )
|
|
|
- }?.dictValue
|
|
|
- }
|
|
|
- ?.find { it.row?.toInt() == keyBean.nodeId && it.col?.toInt() == (keyBean.nodeId + (keyBean.id) * 2 + 1) } != null) {
|
|
|
- PopTip.build().tip(
|
|
|
- CommonUtils.getStr("slot_exception_tag")
|
|
|
- )
|
|
|
- } else {
|
|
|
- // 放回钥匙,上锁
|
|
|
- val req = CanCommands.forDevice(keyBean.nodeId).controlLatch(keyBean.id, 1)
|
|
|
- CanHelper.writeTo(req) {
|
|
|
- LogicManager.hardwareLogic.getKeyInfo(rfid) {
|
|
|
- logger.info("钥匙:${rfid},${it}")
|
|
|
- if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
- keyBean.mac = it.macAddress!!
|
|
|
- } else {
|
|
|
- logger.error("Get key info fail : $rfid")
|
|
|
- if (ISCSConfig.isInit) {
|
|
|
- PopTip.build().tip(CommonUtils.getStr("get_key_info_fail"))
|
|
|
- }
|
|
|
|
|
|
- val req = CanCommands.forDevice(keyBean.nodeId)
|
|
|
- .controlLatch(keyBean.id, 0)
|
|
|
- CanHelper.writeTo(req){}
|
|
|
- }
|
|
|
- Executor.delayOnMain(200) {
|
|
|
- canListeners.forEach { it.callBack(listOf(keyBean)) }
|
|
|
+ val isKeyAbnormal = rfid in (keyData?.records?.filter {
|
|
|
+ it.exStatus == keyStatus.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("abnormal") }?.dictValue
|
|
|
+ }?.map { it.keyNfc } ?: emptyList())
|
|
|
+
|
|
|
+ val isSlotAbnormal = slotsPage?.records?.any {
|
|
|
+ it.slotType == slotTypeList.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("key") }?.dictValue &&
|
|
|
+ it.status == slotStatusList.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("abnormal") }?.dictValue &&
|
|
|
+ it.row?.toInt() == keyBean.nodeId &&
|
|
|
+ it.col?.toInt() == (keyBean.nodeId + (keyBean.id) * 2 + 1)
|
|
|
+ } == true
|
|
|
+
|
|
|
+ if (isKeyAbnormal) {
|
|
|
+ PopTip.build().tip(CommonUtils.getStr("key_exception_tag"))
|
|
|
+ keyBean.deviceChange = false
|
|
|
+ return@runOnIO
|
|
|
+ }
|
|
|
+ if (isSlotAbnormal) {
|
|
|
+ PopTip.build().tip(CommonUtils.getStr("slot_exception_tag"))
|
|
|
+ keyBean.deviceChange = false
|
|
|
+ return@runOnIO
|
|
|
+ }
|
|
|
+
|
|
|
+ val ctrl = CanCommands.forDevice(keyBean.nodeId).controlLatch(keyBean.id, 1)
|
|
|
+ CanHelper.writeTo(ctrl) {
|
|
|
+ LogicManager.hardwareLogic.getKeyInfo(rfid) {
|
|
|
+ logger.info("钥匙:$rfid,$it")
|
|
|
+ if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
+ keyBean.mac = it.macAddress!!
|
|
|
+ } else {
|
|
|
+ logger.error("Get key info fail : $rfid")
|
|
|
+ if (ISCSConfig.isInit) {
|
|
|
+ PopTip.build().tip(CommonUtils.getStr("get_key_info_fail"))
|
|
|
}
|
|
|
+ val unlock = CanCommands.forDevice(keyBean.nodeId).controlLatch(keyBean.id, 0)
|
|
|
+ CanHelper.writeTo(unlock){}
|
|
|
+ }
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ try { canListeners.forEach { l -> l.callBack(listOf(keyBean)) } }
|
|
|
+ finally { keyBean.deviceChange = false } // ✅ 放最后
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- } else if (!keyBean.isCharging) {//增加充电判断,防止无线充电干扰锁仓状态导致判断为取出
|
|
|
- handleDeviceTake(
|
|
|
- DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_KEY, keyBean.rfid), keyBean.rfid
|
|
|
- )
|
|
|
+ } else if (!keyBean.isCharging) {
|
|
|
+ handleDeviceTake(DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_KEY, keyBean.rfid), keyBean.rfid)
|
|
|
Executor.delayOnMain(200) {
|
|
|
- canListeners.forEach { it.callBack(listOf(keyBean)) }
|
|
|
+ try { canListeners.forEach { it.callBack(listOf(keyBean)) } }
|
|
|
+ finally { keyBean.deviceChange = false } // ✅ 已有
|
|
|
}
|
|
|
+ } else {
|
|
|
+ keyBean.deviceChange = false
|
|
|
}
|
|
|
}
|
|
|
|