|
|
@@ -1,43 +1,50 @@
|
|
|
package com.grkj.ui_base.business
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import com.grkj.data.config.ISCSConfig
|
|
|
+import com.grkj.data.data.DictConstants
|
|
|
+import com.grkj.data.data.MMKVConstants
|
|
|
+import com.grkj.data.data.MainDomainData
|
|
|
import com.grkj.data.di.LogicManager
|
|
|
+import com.grkj.data.enums.HardwareMode
|
|
|
+import com.grkj.data.hardware.ble.BleConnectionManager
|
|
|
+import com.grkj.data.hardware.ble.BleSendDispatcher
|
|
|
+import com.grkj.data.hardware.can.CanCommands
|
|
|
+import com.grkj.data.hardware.can.CanDeviceConst
|
|
|
+import com.grkj.data.hardware.can.CanHelper
|
|
|
+import com.grkj.data.hardware.can.DeviceModel
|
|
|
+import com.grkj.data.hardware.modbus.DeviceConst
|
|
|
+import com.grkj.data.hardware.modbus.DockBean
|
|
|
+import com.grkj.data.hardware.modbus.ModBusController
|
|
|
import com.grkj.data.model.local.DeviceTakeUpdate
|
|
|
import com.grkj.data.model.req.LockTakeUpdateReq
|
|
|
-import com.grkj.ui_base.R
|
|
|
-import com.grkj.data.data.DictConstants
|
|
|
-import com.grkj.data.data.MainDomainData
|
|
|
-import com.grkj.ui_base.config.ISCSConfig
|
|
|
+import com.grkj.data.utils.event.LoadingEvent
|
|
|
+import com.grkj.shared.utils.extension.removeLeadingZeros
|
|
|
+import com.grkj.shared.utils.extension.toHexStrings
|
|
|
+import com.grkj.shared.utils.i18n.I18nManager
|
|
|
+import com.grkj.ui_base.listeners.CanDeviceListener
|
|
|
import com.grkj.ui_base.listeners.DeviceListener
|
|
|
import com.grkj.ui_base.utils.CommonUtils
|
|
|
import com.grkj.ui_base.utils.Executor
|
|
|
import com.grkj.ui_base.utils.SPUtils
|
|
|
-import com.grkj.ui_base.utils.ble.BleConnectionManager
|
|
|
import com.grkj.ui_base.utils.event.DeviceTakeUpdateEvent
|
|
|
-import com.grkj.data.utils.event.LoadingEvent
|
|
|
import com.grkj.ui_base.utils.event.UpdateTicketProgressEvent
|
|
|
-import com.grkj.shared.utils.extension.removeLeadingZeros
|
|
|
import com.grkj.ui_base.utils.extension.serialNo
|
|
|
-import com.grkj.shared.utils.extension.toHexStrings
|
|
|
-import com.grkj.shared.utils.i18n.I18nManager
|
|
|
-import com.grkj.ui_base.utils.ble.BleSendDispatcher
|
|
|
import com.grkj.ui_base.utils.extension.tip
|
|
|
-import com.grkj.ui_base.utils.modbus.DeviceConst
|
|
|
-import com.grkj.ui_base.utils.modbus.DockBean
|
|
|
-import com.grkj.ui_base.utils.modbus.ModBusController
|
|
|
import com.kongzue.dialogx.dialogs.PopTip
|
|
|
import com.sik.sikcore.SIKCore
|
|
|
+import com.sik.sikcore.extension.getMMKVData
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.async
|
|
|
import kotlinx.coroutines.withContext
|
|
|
import org.slf4j.LoggerFactory
|
|
|
-import kotlin.plus
|
|
|
|
|
|
/**
|
|
|
* 硬件业务管理
|
|
|
*/
|
|
|
-object ModbusBusinessManager {
|
|
|
- private val logger = LoggerFactory.getLogger(ModbusBusinessManager::class.java)
|
|
|
+object HardwareBusinessManager {
|
|
|
+ private val logger = LoggerFactory.getLogger(HardwareBusinessManager::class.java)
|
|
|
|
|
|
// 设备待取列表(需要报给后台的列表,等实际取完再上报)
|
|
|
@JvmStatic
|
|
|
@@ -45,6 +52,8 @@ object ModbusBusinessManager {
|
|
|
|
|
|
private val listeners = ArrayList<DeviceListener>()
|
|
|
|
|
|
+ private val canListeners = ArrayList<CanDeviceListener>()
|
|
|
+
|
|
|
private var initListener: (() -> Unit)? = null
|
|
|
|
|
|
/**
|
|
|
@@ -54,6 +63,13 @@ object ModbusBusinessManager {
|
|
|
listeners.add(DeviceListener(key, listener))
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 注册状态监听
|
|
|
+ */
|
|
|
+ fun registerCanStatusListener(key: Any, listener: (List<DeviceModel>) -> Unit) {
|
|
|
+ canListeners.add(CanDeviceListener(key, listener))
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 取消注册状态监听
|
|
|
*/
|
|
|
@@ -66,6 +82,18 @@ object ModbusBusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 取消注册状态监听
|
|
|
+ */
|
|
|
+ fun unregisterCanListener(key: Any) {
|
|
|
+ val it = canListeners.iterator()
|
|
|
+ while (it.hasNext()) {
|
|
|
+ if (it.next().key == key) {
|
|
|
+ it.remove()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 注册初始化监听
|
|
|
*/
|
|
|
@@ -115,7 +143,7 @@ object ModbusBusinessManager {
|
|
|
* 根据作业票获取是否有指定设备未取
|
|
|
*/
|
|
|
fun hasAnyDeviceWaitTakeByTicketId(deviceType: Int, ticketId: Long?): Boolean {
|
|
|
- return ModbusBusinessManager.mDeviceTakeList.any { it.deviceType == deviceType && it.ticketId == ticketId }
|
|
|
+ return mDeviceTakeList.any { it.deviceType == deviceType && it.ticketId == ticketId }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -144,11 +172,11 @@ object ModbusBusinessManager {
|
|
|
logger.info("钥匙取出,移除设备取出信息:${info.nfc}")
|
|
|
removeDeviceTake(DeviceConst.DEVICE_TYPE_KEY, info.nfc)
|
|
|
logger.info("设备取出信息:${mDeviceTakeList}")
|
|
|
- ModBusController.getKeyByRfid(
|
|
|
- info.nfc
|
|
|
- )?.mac?.let {
|
|
|
- BleConnectionManager.unregisterConnectListener(it)
|
|
|
- }
|
|
|
+ HardwareMode.getCurrentHardwareMode().getKeyMacByRfid(info.nfc)
|
|
|
+ ?.let {
|
|
|
+ BleConnectionManager.unregisterConnectListener(it)
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
logger.info("更新钥匙取出异常")
|
|
|
}
|
|
|
@@ -169,8 +197,7 @@ object ModbusBusinessManager {
|
|
|
Executor.runOnMain {
|
|
|
if (isSuccess == false) {
|
|
|
logger.error("Lock take report fail")
|
|
|
- PopTip.build()
|
|
|
- .tip(CommonUtils.getStr("lock_take_report_fail"))
|
|
|
+ PopTip.build().tip(CommonUtils.getStr("lock_take_report_fail"))
|
|
|
SPUtils.saveTicketTakeLockException(info.ticketId)
|
|
|
mDeviceTakeList.removeIf { it.deviceType == DeviceConst.DEVICE_TYPE_LOCK && it.nfc == info.nfc }
|
|
|
mDeviceTakeList.removeIf { it.deviceType == DeviceConst.DEVICE_TYPE_KEY && it.ticketId == info.ticketId }
|
|
|
@@ -217,11 +244,12 @@ object ModbusBusinessManager {
|
|
|
|
|
|
|
|
|
// 3. 重写 checkEquipCount
|
|
|
+ @SuppressLint("MissingPermission")
|
|
|
fun checkEquipCount(
|
|
|
ticketId: Long,
|
|
|
needLockCount: Int,
|
|
|
isNeedKey: Boolean,
|
|
|
- callBack: (Pair<Byte, DockBean.KeyBean?>?, MutableMap<Byte, MutableList<DockBean.LockBean>>) -> Unit
|
|
|
+ callBack: (Pair<Any, String?>?, MutableMap<Any, MutableList<Pair<Int, String>>>) -> Unit
|
|
|
) {
|
|
|
// 你可以改成接收 CoroutineScope 或者直接在全局 Scope 启动
|
|
|
ThreadUtils.runOnIO {
|
|
|
@@ -232,14 +260,10 @@ object ModbusBusinessManager {
|
|
|
val locksPage = DataBusiness.getLocksPage()
|
|
|
|
|
|
// —— 并行加载字典(或按需串行也行) ——
|
|
|
- val lockStatus =
|
|
|
- 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 keyStatus =
|
|
|
- async { DataBusiness.fetchDict(DictConstants.KEY_KEY_STATUS) }
|
|
|
+ val lockStatus = 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 keyStatus = async { DataBusiness.fetchDict(DictConstants.KEY_KEY_STATUS) }
|
|
|
|
|
|
// 等待字典加载完成
|
|
|
val lockStatusList = lockStatus.await()
|
|
|
@@ -250,27 +274,27 @@ object ModbusBusinessManager {
|
|
|
// —— 在 Default 线程做计算密集操作 ——
|
|
|
val lockMap = withContext(Dispatchers.Default) {
|
|
|
logger.info("获取锁具数量:${needLockCount}")
|
|
|
- ModBusController.getLocks(
|
|
|
- needLockCount,
|
|
|
- slotsPage?.records?.filter {
|
|
|
- it.slotType == slotTypeList.find { d -> I18nManager.t(d.dictLabel) == I18nManager.t("lock") }?.dictValue && it.status == slotStatusList.find { d ->
|
|
|
+ HardwareMode.getCurrentHardwareMode()
|
|
|
+ .getLocks(needLockCount, 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
|
|
|
- }?.toMutableList() ?: mutableListOf(),
|
|
|
- (locksPage?.records?.filter {
|
|
|
+ }?.toMutableList() ?: mutableListOf(), (locksPage?.records?.filter {
|
|
|
it.exStatus == lockStatusList.find { d ->
|
|
|
I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
"abnormal"
|
|
|
)
|
|
|
}?.dictValue
|
|
|
- }
|
|
|
- ?.map { it.lockNfc ?: "" }?.toMutableList() ?: mutableListOf()).apply {
|
|
|
+ }?.map { it.lockNfc ?: "" }?.toMutableList() ?: mutableListOf()).apply {
|
|
|
addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_LOCK && it.ticketId != ticketId }
|
|
|
.map { it.nfc })
|
|
|
- }
|
|
|
- )
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
val actualLockCount = lockMap.values.sumBy { it.size }
|
|
|
@@ -284,35 +308,30 @@ object ModbusBusinessManager {
|
|
|
}
|
|
|
|
|
|
// —— 如果需钥匙,再请求并计算 ——
|
|
|
- var keyPair: Pair<Byte, DockBean.KeyBean?>? = null
|
|
|
+ var keyPair: Pair<Any, String?>? = null
|
|
|
if (isNeedKey) {
|
|
|
val keyPage = DataBusiness.getKeyPage()
|
|
|
keyPair = withContext(Dispatchers.Default) {
|
|
|
- ModBusController.getOneKey(
|
|
|
- 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
|
|
|
- }?.toMutableList() ?: mutableListOf(),
|
|
|
- (keyPage?.records?.filter {
|
|
|
- it.exStatus == keyStatusList.find { d ->
|
|
|
- I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
- "abnormal"
|
|
|
- )
|
|
|
- }?.dictValue
|
|
|
- }
|
|
|
- ?.map { it.keyNfc ?: "" }?.toMutableList()
|
|
|
- ?: mutableListOf()).apply {
|
|
|
- addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_KEY && it.ticketId != ticketId }
|
|
|
- .map { it.nfc })
|
|
|
- }
|
|
|
- )
|
|
|
+ HardwareMode.getCurrentHardwareMode().getOneKey(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
|
|
|
+ }?.toMutableList() ?: mutableListOf(), (keyPage?.records?.filter {
|
|
|
+ it.exStatus == keyStatusList.find { d ->
|
|
|
+ I18nManager.t(d.dictLabel) == I18nManager.t(
|
|
|
+ "abnormal"
|
|
|
+ )
|
|
|
+ }?.dictValue
|
|
|
+ }?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()).apply {
|
|
|
+ addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_KEY && it.ticketId != ticketId }
|
|
|
+ .map { it.nfc })
|
|
|
+ })
|
|
|
}
|
|
|
if (keyPair == null) {
|
|
|
PopTip.build().tip(CommonUtils.getStr("no_available_key"))
|
|
|
@@ -320,7 +339,6 @@ object ModbusBusinessManager {
|
|
|
}
|
|
|
// —— 全部计算完毕,在主线程一次性回调 ——
|
|
|
callBack(keyPair, lockMap)
|
|
|
-
|
|
|
} catch (e: Exception) {
|
|
|
// 根据需求处理异常,或把异常信息也通过 callback 返回
|
|
|
LoadingEvent.sendLoadingEvent()
|
|
|
@@ -338,7 +356,52 @@ object ModbusBusinessManager {
|
|
|
* 4、蓝牙连接
|
|
|
* 5、蓝牙数据通讯
|
|
|
*/
|
|
|
- private fun deviceStatusHandle(res: Any) {
|
|
|
+ private fun canDeviceStatusHandle(res: List<DeviceModel>) {
|
|
|
+ logger.debug("硬件状态:{}", res)
|
|
|
+ if (MainDomainData.userInfo == null || res.isEmpty()) {
|
|
|
+ return@canDeviceStatusHandle
|
|
|
+ }
|
|
|
+ val deviceType = CanHelper.getDeviceTypeByNodeId(res[0].nodeId)
|
|
|
+ when (deviceType) {
|
|
|
+ CanDeviceConst.DEVICE_KEY_DOCK -> {
|
|
|
+ res.filterIsInstance<DeviceModel.DeviceKey>().forEach {
|
|
|
+ canDeviceKeyHandler(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CanDeviceConst.DEVICE_LOCK_DOCK -> {
|
|
|
+ res.filterIsInstance<DeviceModel.CommonDevice>().forEach {
|
|
|
+ canDeviceLockHandler(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CanDeviceConst.DEVICE_KEY_CABINET_CONTROL_BOARD -> {
|
|
|
+ // TODO 钥匙柜主控板
|
|
|
+ }
|
|
|
+
|
|
|
+ CanDeviceConst.DEVICE_MATERIAL_CABINET_CONTROL_BOARD -> {
|
|
|
+ // TODO 物资柜主控板
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ canListeners.forEach { it.callBack(res) }
|
|
|
+ }
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ if (!ISCSConfig.isInit) {
|
|
|
+ initListener?.invoke()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 硬件状态
|
|
|
+ * 1、检测到有钥匙
|
|
|
+ * 2、上锁
|
|
|
+ * 3、开启充电
|
|
|
+ * 4、蓝牙连接
|
|
|
+ * 5、蓝牙数据通讯
|
|
|
+ */
|
|
|
+ private fun modbusDeviceStatusHandle(res: Any) {
|
|
|
logger.debug("硬件状态:${(res as List<ByteArray>).map { it.toHexStrings() }}")
|
|
|
if (res.isEmpty() || res.any { it.isEmpty() }) {
|
|
|
var tipStr = CommonUtils.getStr("no_response_board_exists") + " : "
|
|
|
@@ -426,8 +489,7 @@ object ModbusBusinessManager {
|
|
|
* 设备挂锁处理
|
|
|
*/
|
|
|
private fun deviceLockHandler(
|
|
|
- dockBean: DockBean,
|
|
|
- lockBean: DockBean.LockBean
|
|
|
+ dockBean: DockBean, lockBean: DockBean.LockBean
|
|
|
) {
|
|
|
if (lockBean.isExist) {
|
|
|
ModBusController.readLockRfid(dockBean.addr, lockBean.idx) { res ->
|
|
|
@@ -435,18 +497,15 @@ object ModbusBusinessManager {
|
|
|
logger.error("Lock rfid error")
|
|
|
return@readLockRfid
|
|
|
}
|
|
|
- val rfid =
|
|
|
- res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
ModBusController.updateLockRfid(
|
|
|
dockBean.addr, lockBean.idx, rfid
|
|
|
)
|
|
|
ThreadUtils.runOnIO {
|
|
|
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 slotStatus = async { DataBusiness.fetchDict(DictConstants.KEY_SLOT_STATUS) }
|
|
|
+ val slotType = async { DataBusiness.fetchDict(DictConstants.KEY_SLOT_TYPE) }
|
|
|
val slotsPageReq = async { DataBusiness.getSlotsPage() }
|
|
|
var lockStatus = lockStatusReq.await()
|
|
|
val slotsPage = slotsPageReq.await()
|
|
|
@@ -460,10 +519,7 @@ object ModbusBusinessManager {
|
|
|
"abnormal"
|
|
|
)
|
|
|
}?.dictValue
|
|
|
- }
|
|
|
- ?.map { it.lockNfc }?.toMutableList()
|
|
|
- ?: mutableListOf())
|
|
|
- ) {
|
|
|
+ }?.map { it.lockNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
PopTip.build().tip(CommonUtils.getStr("lock_exception_tag"))
|
|
|
} else if (slotsPage?.records?.filter {
|
|
|
it.slotType == slotTypeList.find { d ->
|
|
|
@@ -490,8 +546,7 @@ object ModbusBusinessManager {
|
|
|
if (itRst.isNotEmpty()) {
|
|
|
// 上报锁具信息
|
|
|
LogicManager.jobTicketLogic.updateLockReturn(
|
|
|
- rfid,
|
|
|
- SIKCore.getApplication().serialNo()
|
|
|
+ rfid, SIKCore.getApplication().serialNo()
|
|
|
) {}
|
|
|
}
|
|
|
}
|
|
|
@@ -507,18 +562,206 @@ object ModbusBusinessManager {
|
|
|
} else {
|
|
|
logger.info("挂锁取出-:${lockBean.rfid}")
|
|
|
handleDeviceTake(
|
|
|
- DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_LOCK, lockBean.rfid),
|
|
|
- lockBean.rfid
|
|
|
+ DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_LOCK, lockBean.rfid), lockBean.rfid
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设备挂锁处理
|
|
|
+ * Can设备
|
|
|
+ */
|
|
|
+ private fun canDeviceLockHandler(lockBean: DeviceModel.CommonDevice) {
|
|
|
+ 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) {
|
|
|
+ logger.error("Lock rfid error")
|
|
|
+ return@readFrom
|
|
|
+ }
|
|
|
+ val rfid = rfidData.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ lockBean.rfid = rfid
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ 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())) {
|
|
|
+ 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) {
|
|
|
+ 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)) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ logger.info("挂锁取出-:${lockBean.rfid}")
|
|
|
+ handleDeviceTake(
|
|
|
+ DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_LOCK, lockBean.rfid), lockBean.rfid
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 钥匙设备处理
|
|
|
+ * Can设备
|
|
|
+ */
|
|
|
+ private fun canDeviceKeyHandler(keyBean: DeviceModel.DeviceKey) {
|
|
|
+ if (!keyBean.deviceChange) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ logger.info("钥匙状态变化DeviceKeyHandler:${keyBean}")
|
|
|
+ if (keyBean.isExist) {
|
|
|
+ // 放回钥匙,读取rfid
|
|
|
+ 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)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ if (rfidData.size < 11) {
|
|
|
+ logger.error("Key rfid error")
|
|
|
+ return@readFrom
|
|
|
+ }
|
|
|
+ val rfid = rfidData.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ logger.info("读取到的rfid:${rfid}")
|
|
|
+ keyBean.rfid = rfid
|
|
|
+ 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 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)) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (!keyBean.isCharging) {//增加充电判断,防止无线充电干扰锁仓状态导致判断为取出
|
|
|
+ handleDeviceTake(
|
|
|
+ DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_KEY, keyBean.rfid), keyBean.rfid
|
|
|
+ )
|
|
|
+ Executor.delayOnMain(200) {
|
|
|
+ canListeners.forEach { it.callBack(listOf(keyBean)) }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 钥匙设备处理
|
|
|
*/
|
|
|
private fun deviceKeyHandler(
|
|
|
- dockBean: DockBean,
|
|
|
- keyBean: DockBean.KeyBean
|
|
|
+ dockBean: DockBean, keyBean: DockBean.KeyBean
|
|
|
) {
|
|
|
logger.info("钥匙状态变化DeviceKeyHandler:${keyBean}")
|
|
|
if (keyBean.isExist) {
|
|
|
@@ -535,18 +778,15 @@ object ModbusBusinessManager {
|
|
|
logger.error("Key rfid error")
|
|
|
return@readKeyRfid
|
|
|
}
|
|
|
- val rfid =
|
|
|
- res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
logger.info("读取到的rfid:${rfid}")
|
|
|
ModBusController.updateKeyRfid(
|
|
|
dockBean.addr, keyBean.idx, rfid
|
|
|
)
|
|
|
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 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) }
|
|
|
@@ -563,15 +803,16 @@ object ModbusBusinessManager {
|
|
|
"abnormal"
|
|
|
)
|
|
|
}?.dictValue
|
|
|
- }
|
|
|
- ?.map { it.keyNfc }?.toMutableList()
|
|
|
- ?: mutableListOf())
|
|
|
- ) {
|
|
|
+ }?.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 ->
|
|
|
+ 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"
|
|
|
)
|
|
|
@@ -590,9 +831,7 @@ object ModbusBusinessManager {
|
|
|
logger.info("钥匙:${rfid},${it}")
|
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
ModBusController.updateKeyMac(
|
|
|
- dockBean.addr,
|
|
|
- keyBean.idx,
|
|
|
- it.macAddress!!
|
|
|
+ dockBean.addr, keyBean.idx, it.macAddress!!
|
|
|
)
|
|
|
ModBusController.updateKeyReadyStatus(
|
|
|
it.macAddress!!, false, 5
|
|
|
@@ -616,8 +855,7 @@ object ModbusBusinessManager {
|
|
|
}
|
|
|
} else if (!keyBean.isCharging) {//增加充电判断,防止无线充电干扰锁仓状态导致判断为取出
|
|
|
handleDeviceTake(
|
|
|
- DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_KEY, keyBean.rfid),
|
|
|
- keyBean.rfid
|
|
|
+ DeviceTakeUpdateEvent(DeviceConst.DEVICE_TYPE_KEY, keyBean.rfid), keyBean.rfid
|
|
|
)
|
|
|
Executor.delayOnMain(200) {
|
|
|
listeners.forEach { it.callBack(dockBean) }
|
|
|
@@ -629,9 +867,16 @@ object ModbusBusinessManager {
|
|
|
* 总的监听,做预处理,其余的所有监听均使用本监听处理后的数据,只允许调用一次
|
|
|
*/
|
|
|
fun registerMainListener() {
|
|
|
- ModBusController.registerStatusListener(this) { res ->
|
|
|
- deviceStatusHandle(res)
|
|
|
+ if (MMKVConstants.KEY_HARDWARE_MODE.getMMKVData(HardwareMode.MODBUS.name) == HardwareMode.MODBUS.name) {
|
|
|
+ ModBusController.registerStatusListener(this) { res ->
|
|
|
+ modbusDeviceStatusHandle(res)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ CanHelper.addDeviceChangeListener(this) { res ->
|
|
|
+ canDeviceStatusHandle(res)
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -639,9 +884,9 @@ object ModbusBusinessManager {
|
|
|
*/
|
|
|
fun checkTicketAndSendTicket(keyMac: String) {
|
|
|
logger.info("开始检查是否存在作业票")
|
|
|
- val keyBean = ModBusController.getKeyByMac(keyMac)
|
|
|
+ val keyRfid = HardwareMode.getCurrentHardwareMode().getRfidByKeyMac(keyMac)
|
|
|
logger.info("待发设备:${mDeviceTakeList}")
|
|
|
- mDeviceTakeList.find { it.nfc == keyBean?.rfid }?.let { itKey ->
|
|
|
+ mDeviceTakeList.find { it.nfc == keyRfid }?.let { itKey ->
|
|
|
logger.info("存在作业票,下发作业票")
|
|
|
BleBusinessManager.handleGiveKey(itKey)
|
|
|
}
|
|
|
@@ -651,35 +896,31 @@ object ModbusBusinessManager {
|
|
|
* 根据rfid获取mac地址
|
|
|
*/
|
|
|
fun getKeyMacByRfid(rfid: String): String {
|
|
|
- return ModBusController.getKeyByRfid(rfid)?.mac ?: ""
|
|
|
+ return HardwareMode.getCurrentHardwareMode().getKeyMacByRfid(rfid) ?: ""
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取钥匙仓位位置
|
|
|
*/
|
|
|
fun getKeySlotPosition(keyNfc: String): String {
|
|
|
- val keyData = ModBusController.getKeyByRfid(keyNfc)
|
|
|
- return if (keyData == null) CommonUtils.getStr("not_in_slot")
|
|
|
- .toString() else "${keyData.row}-${keyData.idx + 1}"
|
|
|
+ val slotPosition = HardwareMode.getCurrentHardwareMode().getSlotPosition(keyNfc)
|
|
|
+ return slotPosition
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取挂锁仓位位置
|
|
|
*/
|
|
|
fun getLockSlotPosition(lockNfc: String): String {
|
|
|
- val lockData = ModBusController.getLockByRfid(lockNfc)
|
|
|
- return if (lockData == null) CommonUtils.getStr("not_in_slot")
|
|
|
- .toString() else "${lockData.row}-${lockData.idx + 1}"
|
|
|
+ val slotPosition = HardwareMode.getCurrentHardwareMode().getLockSlotPosition(lockNfc)
|
|
|
+ return slotPosition
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取存在的钥匙
|
|
|
*/
|
|
|
- fun getExistsKey(): List<DockBean.KeyBean> {
|
|
|
- val dockData =
|
|
|
- ModBusController.dockList.filter { it.type == DeviceConst.DOCK_TYPE_LOCK || it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
|
|
|
- return dockData.filter { it.type == DeviceConst.DOCK_TYPE_KEY }.flatMap { it.deviceList }
|
|
|
- .filterIsInstance<DockBean.KeyBean>()
|
|
|
+ fun getExistsKeyMac(): List<String?> {
|
|
|
+ val macs = HardwareMode.getCurrentHardwareMode().getExistsKeyMac()
|
|
|
+ return macs
|
|
|
}
|
|
|
|
|
|
/**
|