|
|
@@ -38,9 +38,11 @@ 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.DeviceTakeUpdateMsg
|
|
|
+import com.grkj.iscs.model.eventmsg.GetTicketStatusMsg
|
|
|
import com.grkj.iscs.model.eventmsg.LoadingMsg
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEvent
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_TAKE_UPDATE
|
|
|
+import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_GET_TICKET_STATUS
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
|
|
|
import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
|
|
|
import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
|
|
|
@@ -94,7 +96,7 @@ object BusinessManager {
|
|
|
}
|
|
|
|
|
|
// 设备待取列表(需要报给后台的列表,等实际取完再上报)
|
|
|
- private val mDeviceTakeList = mutableListOf<DeviceTakeUpdateBO>()
|
|
|
+ val mDeviceTakeList = mutableListOf<DeviceTakeUpdateBO>()
|
|
|
|
|
|
/**
|
|
|
* 初始化消息总线
|
|
|
@@ -180,6 +182,7 @@ object BusinessManager {
|
|
|
// showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr.toInt())
|
|
|
// registerConnectListener(it.macAddress)
|
|
|
} else {
|
|
|
+ LogUtil.e("Get key info fail : $rfid")
|
|
|
ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
}
|
|
|
}
|
|
|
@@ -372,6 +375,7 @@ object BusinessManager {
|
|
|
fun checkEquipCount(needLockCount: Int, isNeedKey: Boolean, callBack: (Pair<Byte, DockBean.KeyBean?>?, MutableMap<Byte, MutableList<DockBean.LockBean>>) -> Unit) {
|
|
|
var lockCount = 0
|
|
|
val lockMap = ModBusController.getLocks(needLockCount)
|
|
|
+ LogUtil.i("checkEquipCount : $lockMap")
|
|
|
lockMap.forEach { (_, rfidList) ->
|
|
|
lockCount += rfidList.size
|
|
|
}
|
|
|
@@ -734,7 +738,7 @@ object BusinessManager {
|
|
|
registerConnectListener(mac) { isDone, bleBean ->
|
|
|
if (isDone) {
|
|
|
Executor.delayOnMain(500) {
|
|
|
- getTicketStatus(bleBean!!.bleDevice, isNeedLoading)
|
|
|
+ getTicketStatusWithRetry(bleBean!!.bleDevice, isNeedLoading)
|
|
|
}
|
|
|
} else {
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
|
|
|
@@ -742,6 +746,30 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun getTicketStatusWithRetry(
|
|
|
+ bleDevice: BleDevice,
|
|
|
+ isNeedLoading: Boolean = false,
|
|
|
+ maxRetries: Int = 3,
|
|
|
+ delayMillis: Long = 500
|
|
|
+ ) {
|
|
|
+ var retryCount = 0
|
|
|
+
|
|
|
+ fun attemptSend() {
|
|
|
+ getTicketStatus(bleDevice, isNeedLoading) { sendRst ->
|
|
|
+ if (!sendRst && retryCount < maxRetries) {
|
|
|
+ retryCount++
|
|
|
+ // 等待一段时间后再次尝试
|
|
|
+ Executor.delayOnMain(delayMillis) {
|
|
|
+ LogUtil.i("Retry attempt, mac : ${bleDevice.mac}, retryCount : $retryCount")
|
|
|
+ attemptSend()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ attemptSend()
|
|
|
+ }
|
|
|
+
|
|
|
private fun sendTicket(jsonStr: String, bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始下发工作票...", null)))
|
|
|
BleCmdManager.sendWorkTicket(jsonStr, bleDevice = bleDevice, callback = object : CustomBleWriteCallback() {
|
|
|
@@ -953,12 +981,12 @@ object BusinessManager {
|
|
|
}
|
|
|
|
|
|
// 上报点位钥匙绑定
|
|
|
- NetApi.updateLockPointBatch(updateList) { itRst ->
|
|
|
- // TODO 上报结果
|
|
|
+ NetApi.updateLockPointBatch(updateList) { isSuccess ->
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// 上报钥匙归还
|
|
|
- NetApi.updateKeyReturn(data.taskId?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()) {
|
|
|
+ NetApi.updateKeyReturn(data.taskId?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()) { isSuccess ->
|
|
|
|
|
|
}
|
|
|
}
|
|
|
@@ -968,7 +996,7 @@ object BusinessManager {
|
|
|
/**
|
|
|
* 获取工作票完成情况
|
|
|
*/
|
|
|
- private fun getTicketStatus(bleDevice: BleDevice, isNeedLoading: Boolean = false) {
|
|
|
+ private fun getTicketStatus(bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始获取工作票", null)))
|
|
|
BleCmdManager.getTicketStatus(bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
@@ -976,6 +1004,7 @@ object BusinessManager {
|
|
|
println("getTicketStatus success")}
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取失败", false)))
|
|
|
+ processCallback?.invoke(false)
|
|
|
println("getTicketStatus fail")}
|
|
|
})
|
|
|
}
|
|
|
@@ -986,7 +1015,7 @@ object BusinessManager {
|
|
|
fun addDeviceTake(deviceType: Int, ticketId: Long, nfc: String?) {
|
|
|
LogUtil.i("$deviceType - $ticketId - $nfc")
|
|
|
mDeviceTakeList.removeIf { it.deviceType == deviceType && it.nfc == nfc }
|
|
|
- mDeviceTakeList.add(DeviceTakeUpdateBO(deviceType, ticketId, nfc))
|
|
|
+ mDeviceTakeList.add(DeviceTakeUpdateBO(deviceType, ticketId, nfc!!))
|
|
|
}
|
|
|
|
|
|
private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg) {
|
|
|
@@ -994,20 +1023,20 @@ object BusinessManager {
|
|
|
when (deviceTakeUpdateBO.deviceType) {
|
|
|
// 钥匙
|
|
|
0 -> {
|
|
|
- mDeviceTakeList.find { it.deviceType == 0 && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
|
|
|
- NetApi.updateKeyTake(info.ticketId, info.nfc!!, MyApplication.instance?.serialNo()!!) { isSuccess ->
|
|
|
+ mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
|
|
|
+ NetApi.updateKeyTake(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!) { isSuccess ->
|
|
|
if (isSuccess) {
|
|
|
- mDeviceTakeList.removeIf { it.deviceType == 0 && it.nfc == info.nfc }
|
|
|
+ mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_KEY && it.nfc == info.nfc }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 挂锁
|
|
|
1 -> {
|
|
|
- mDeviceTakeList.find { it.deviceType == 1 && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
|
|
|
+ mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_LOCK && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
|
|
|
NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
|
|
|
if (isSuccess == true) {
|
|
|
- mDeviceTakeList.removeIf { it.deviceType == 1 && it.nfc == info.nfc }
|
|
|
+ mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_LOCK && it.nfc == info.nfc }
|
|
|
}
|
|
|
}
|
|
|
}
|