|
|
@@ -81,6 +81,7 @@ import com.sik.sikcore.date.TimeUtils
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.async
|
|
|
+import kotlinx.coroutines.coroutineScope
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
|
import kotlinx.coroutines.withContext
|
|
|
import kotlin.coroutines.resume
|
|
|
@@ -192,6 +193,9 @@ object BusinessManager {
|
|
|
it.data.bleBean.bleDevice.mac, false, 1
|
|
|
)
|
|
|
ToastUtils.tip(R.string.take_out_key)
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ checkMyTodoForHandleKey(it.data.bleBean.bleDevice.mac)
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
LogUtil.e("切换工作模式失败 : ${it.data.bleBean.bleDevice.mac}")
|
|
|
@@ -240,6 +244,38 @@ object BusinessManager {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查我的待办
|
|
|
+ */
|
|
|
+ suspend fun checkMyTodoForHandleKey(mac: String? = null): Boolean {
|
|
|
+ if (!CAN_RETURN) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ val result = suspendCancellableCoroutine<Boolean> { cont ->
|
|
|
+ NetApi.getMySelfState {
|
|
|
+ if (it) {
|
|
|
+ val maxPowerMac = getMaxPowerKey().mac
|
|
|
+ if (maxPowerMac != mac) {
|
|
|
+ connectExistsKey(listOf(mac ?: ""))
|
|
|
+ launchDisconnectJob(mac ?: "")
|
|
|
+ } else {
|
|
|
+ connectExistsKey()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mac?.let {
|
|
|
+ launchDisconnectJob(it)
|
|
|
+ } ?: let {
|
|
|
+ launchDisconnectAllJob()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (cont.isActive) {
|
|
|
+ cont.resume(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 连接一把存在的可连接的钥匙
|
|
|
*/
|
|
|
@@ -447,8 +483,7 @@ object BusinessManager {
|
|
|
* 挂锁处理
|
|
|
*/
|
|
|
private fun deviceLockHandler(
|
|
|
- dockBean: DockBean,
|
|
|
- lockBean: DockBean.LockBean
|
|
|
+ dockBean: DockBean, lockBean: DockBean.LockBean
|
|
|
) {
|
|
|
if (lockBean.isExist) {
|
|
|
ModBusController.readLockRfid(dockBean.addr, lockBean.idx) { res ->
|
|
|
@@ -456,8 +491,7 @@ object BusinessManager {
|
|
|
LogUtil.e("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
|
|
|
)
|
|
|
@@ -476,9 +510,7 @@ object BusinessManager {
|
|
|
NetApi.getIsLockPage { lockData ->
|
|
|
//锁rfid未异常正常请求锁数据,关锁
|
|
|
if (rfid in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
- ?.map { it.lockNfc }?.toMutableList()
|
|
|
- ?: mutableListOf())
|
|
|
- ) {
|
|
|
+ ?.map { it.lockNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
ToastUtils.tip(
|
|
|
MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.lock_exception_tag
|
|
|
@@ -503,8 +535,7 @@ object BusinessManager {
|
|
|
if (itRst.isNotEmpty()) {
|
|
|
// 上报锁具信息
|
|
|
NetApi.updateLockReturn(
|
|
|
- rfid,
|
|
|
- MyApplication.instance!!.serialNo()
|
|
|
+ rfid, MyApplication.instance!!.serialNo()
|
|
|
) {}
|
|
|
}
|
|
|
}
|
|
|
@@ -540,8 +571,7 @@ object BusinessManager {
|
|
|
LogUtil.e("Key rfid error")
|
|
|
return@readKeyRfid
|
|
|
}
|
|
|
- val rfid =
|
|
|
- res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
ThreadUtils.runOnIO {
|
|
|
val slotStatus =
|
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
|
|
|
@@ -558,9 +588,7 @@ object BusinessManager {
|
|
|
val slotTypeList = slotType.await()
|
|
|
//锁钥匙未异常正常请求锁数据,关锁
|
|
|
if (rfid in (keyData?.records?.filter { it.exStatus == keyStatus.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
- ?.map { it.keyNfc }?.toMutableList()
|
|
|
- ?: mutableListOf())
|
|
|
- ) {
|
|
|
+ ?.map { it.keyNfc }?.toMutableList() ?: mutableListOf())) {
|
|
|
ToastUtils.tip(
|
|
|
MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.key_exception_tag
|
|
|
@@ -615,8 +643,7 @@ object BusinessManager {
|
|
|
}
|
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_DEVICE_TAKE_UPDATE,
|
|
|
- DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)
|
|
|
+ MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -1532,8 +1559,7 @@ object BusinessManager {
|
|
|
workTicketGetBO.data?.firstOrNull()?.taskCode?.toLong()
|
|
|
?.let {
|
|
|
checkStepAndTicketDetailThenSendTicket(
|
|
|
- it,
|
|
|
- bleDevice.mac
|
|
|
+ it, bleDevice.mac
|
|
|
)
|
|
|
}
|
|
|
} else {
|
|
|
@@ -1909,20 +1935,8 @@ object BusinessManager {
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
//连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
launchDisconnectJob(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
- NetApi.getMySelfState {
|
|
|
- if (it) {
|
|
|
- val maxPowerMac = getMaxPowerKey().mac
|
|
|
- if (maxPowerMac != currentModeMsg.bleBean.bleDevice.mac) {
|
|
|
- connectExistsKey(
|
|
|
- listOf(
|
|
|
- currentModeMsg.bleBean.bleDevice.mac ?: ""
|
|
|
- )
|
|
|
- )
|
|
|
- launchDisconnectJob(currentModeMsg.bleBean.bleDevice.mac ?: "")
|
|
|
- }
|
|
|
- } else {
|
|
|
- launchDisconnectJob(currentModeMsg.bleBean.bleDevice.mac ?: "")
|
|
|
- }
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ checkMyTodoForHandleKey(currentModeMsg.bleBean.bleDevice.mac)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1943,10 +1957,9 @@ object BusinessManager {
|
|
|
private fun checkStepAndTicketDetailThenSendTicket(ticketId: Long, mac: String) {
|
|
|
NetApi.getStepDetail(ticketId) {
|
|
|
var step = 0
|
|
|
- it?.filter { it.stepStatus == "1" }
|
|
|
- ?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
|
|
|
- step = it
|
|
|
- }
|
|
|
+ it?.filter { it.stepStatus == "1" }?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
|
|
|
+ step = it
|
|
|
+ }
|
|
|
NetApi.getTicketDetail(ticketId) { ticketDetail, _ ->
|
|
|
if (ticketDetail == null) {
|
|
|
return@getTicketDetail
|