|
|
@@ -42,10 +42,12 @@ 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.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_MODE
|
|
|
@@ -1109,7 +1111,7 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun getCurrentStatus(from: Int, bleDevice: BleDevice, retryCount: Int = 3) {
|
|
|
+ fun getCurrentStatus(from: Int, bleDevice: BleDevice, retryCount: Int = 3, timeoutCallBack: ((Boolean) -> Unit)? = null) {
|
|
|
LogUtil.i("getCurrentStatus - ${bleDevice.mac} - from : $from")
|
|
|
var isTimeout = true
|
|
|
// 加1秒防止早于onWriteFailure开始处理导致多次处理
|
|
|
@@ -1118,10 +1120,13 @@ object BusinessManager {
|
|
|
LogUtil.e("getCurrentStatus timeout : mac = ${bleDevice.mac}, retryCount = $retryCount")
|
|
|
if (retryCount > 0) {
|
|
|
Executor.delayOnMain(1000) {
|
|
|
- getCurrentStatus(from, bleDevice, retryCount - 1)
|
|
|
+ getCurrentStatus(from, bleDevice, retryCount - 1, timeoutCallBack)
|
|
|
}
|
|
|
} else {
|
|
|
- addExceptionKey(bleDevice.mac)
|
|
|
+ ModBusController.getKeyByMac(bleDevice.mac)?.rfid?.let {
|
|
|
+ addExceptionKey(it)
|
|
|
+ timeoutCallBack?.invoke(true)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1129,13 +1134,14 @@ object BusinessManager {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
LogUtil.i("getCurrentStatus success : ${bleDevice.mac}")
|
|
|
isTimeout = false
|
|
|
+ timeoutCallBack?.invoke(false)
|
|
|
}
|
|
|
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
LogUtil.i("getCurrentStatus fail : ${bleDevice.mac}")
|
|
|
isTimeout = false
|
|
|
Executor.delayOnMain(1000) {
|
|
|
- getCurrentStatus(from, bleDevice)
|
|
|
+ getCurrentStatus(from, bleDevice, timeoutCallBack = timeoutCallBack)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
@@ -1283,12 +1289,17 @@ object BusinessManager {
|
|
|
* 添加待更新取出状态的设备
|
|
|
*/
|
|
|
fun addDeviceTake(deviceType: Int, ticketId: Long, nfc: String?) {
|
|
|
- LogUtil.i("$deviceType - $ticketId - $nfc")
|
|
|
+ LogUtil.i("addDeviceTake : $deviceType - $ticketId - $nfc")
|
|
|
mDeviceTakeList.removeIf { it.deviceType == deviceType && it.nfc == nfc }
|
|
|
mDeviceTakeList.add(DeviceTakeUpdateBO(deviceType, ticketId, nfc!!))
|
|
|
}
|
|
|
|
|
|
- private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg) {
|
|
|
+ fun removeDeviceTake(deviceType: Int, nfc: String?) {
|
|
|
+ LogUtil.i("removeDeviceTake : $deviceType - $nfc")
|
|
|
+ mDeviceTakeList.removeIf { it.deviceType == deviceType && it.nfc == nfc }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg, rfid: String? = null) {
|
|
|
LogUtil.i("$deviceTakeUpdateBO")
|
|
|
when (deviceTakeUpdateBO.deviceType) {
|
|
|
// 钥匙
|
|
|
@@ -1338,7 +1349,7 @@ object BusinessManager {
|
|
|
}
|
|
|
// 检查有无当前工作票的钥匙
|
|
|
mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == info.ticketId }?.let { itKey ->
|
|
|
- getCurrentStatus(2, getBleDeviceByMac(ModBusController.getKeyByRfid(itKey.nfc)?.mac)!!.bleDevice)
|
|
|
+ handleGiveKey(itKey)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1347,6 +1358,31 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun handleGiveKey(deviceTakeUpdateBO: DeviceTakeUpdateBO) {
|
|
|
+ getCurrentStatus(2, getBleDeviceByMac(ModBusController.getKeyByRfid(deviceTakeUpdateBO.nfc)?.mac)!!.bleDevice) {
|
|
|
+ if (!it) {
|
|
|
+ return@getCurrentStatus
|
|
|
+ }
|
|
|
+ LogUtil.w("handleGiveKey timeout")
|
|
|
+ removeDeviceTake(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)
|
|
|
+ checkEquipCount(0, true) { keyPair, lockMap ->
|
|
|
+ if (keyPair == null) {
|
|
|
+ val ctx = MyApplication.instance?.applicationContext!!
|
|
|
+ val tipDialog = TipDialog(ctx)
|
|
|
+ tipDialog.setTip(ctx.getString(R.string.key_take_error_tip))
|
|
|
+ tipDialog.setConfirmListener {
|
|
|
+ tipDialog.dismiss()
|
|
|
+ sendEventMsg(MsgEvent(MSG_EVENT_DEVICE_EXCEPTION, DeviceExceptionMsg(DEVICE_TYPE_KEY, deviceTakeUpdateBO.nfc)))
|
|
|
+ }
|
|
|
+ tipDialog.show()
|
|
|
+ } else {
|
|
|
+ addDeviceTake(DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!)
|
|
|
+ handleGiveKey(DeviceTakeUpdateBO(DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private fun handleCurrentMode(currentModeMsg: CurrentModeMsg) {
|
|
|
when (currentModeMsg.mode) {
|
|
|
// 工作模式
|
|
|
@@ -1518,12 +1554,12 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun addExceptionKey(key: String) {
|
|
|
- LogUtil.w("addExceptionKey: $key")
|
|
|
- if (mExceptionKeyList.contains(key)) {
|
|
|
+ fun addExceptionKey(rfid: String) {
|
|
|
+ LogUtil.w("addExceptionKey: $rfid")
|
|
|
+ if (mExceptionKeyList.contains(rfid)) {
|
|
|
return
|
|
|
}
|
|
|
- mExceptionKeyList.add(key)
|
|
|
+ mExceptionKeyList.add(rfid)
|
|
|
}
|
|
|
|
|
|
fun removeExceptionKey(key: String) {
|