|
|
@@ -340,11 +340,11 @@ object BusinessManager {
|
|
|
tipStr += addressList
|
|
|
ToastUtils.tip(tipStr)
|
|
|
}
|
|
|
- res.forEach { bytes ->
|
|
|
- val dockBean = ModBusController.updateStatus(bytes) ?: return@forEach
|
|
|
+ res.forEachIndexed { index, bytes ->
|
|
|
+ val dockBean = ModBusController.updateStatus(bytes) ?: return@forEachIndexed
|
|
|
ModBusController.isInitReady = true
|
|
|
if (!CAN_RETURN) {
|
|
|
- return@forEach
|
|
|
+ return@forEachIndexed
|
|
|
}
|
|
|
when (dockBean.type) {
|
|
|
DOCK_TYPE_KEY -> {
|
|
|
@@ -361,32 +361,73 @@ object BusinessManager {
|
|
|
}
|
|
|
val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
.removeLeadingZeros()
|
|
|
- ModBusController.updateKeyRfid(
|
|
|
- dockBean.addr,
|
|
|
- keyBean.isLeft,
|
|
|
- rfid
|
|
|
- )
|
|
|
- // 放回钥匙,上锁
|
|
|
- ModBusController.controlKeyBuckle(
|
|
|
- false,
|
|
|
- keyBean.isLeft,
|
|
|
- dockBean.addr
|
|
|
- ) {
|
|
|
- NetApi.getKeyInfo(rfid) {
|
|
|
- if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
- ModBusController.updateKeyMac(
|
|
|
- dockBean.addr,
|
|
|
- keyBean.isLeft,
|
|
|
- it.macAddress
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ val slotStatus =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_SLOT_STATUS) }
|
|
|
+ val slotType =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_SLOT_TYPE) }
|
|
|
+ val slotsPageReq =
|
|
|
+ async { getSlotsPage() }
|
|
|
+ val keyStatusReq =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_KEY_STATUS) }
|
|
|
+ val keyPageReq =
|
|
|
+ async { getKeyPage() }
|
|
|
+ var keyStatus = keyStatusReq.await()
|
|
|
+ var 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 { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.map { it.keyNfc }?.toMutableList()
|
|
|
+ ?: mutableListOf())
|
|
|
+ ) {
|
|
|
+ ToastUtils.tip(
|
|
|
+ MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.key_exception_tag
|
|
|
)
|
|
|
- ModBusController.updateKeyReadyStatus(
|
|
|
- it.macAddress,
|
|
|
- false,
|
|
|
- 5
|
|
|
+ )
|
|
|
+ } else if (slotsPage?.records
|
|
|
+ ?.filter {
|
|
|
+ it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue &&
|
|
|
+ it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
+ }
|
|
|
+ ?.find { it.row?.toInt() == dockBean.row && it.col?.toInt() == (dockBean.col + (if (keyBean.isLeft) 0 else 1) * 2) } != null
|
|
|
+ ) {
|
|
|
+ ToastUtils.tip(
|
|
|
+ MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.slot_exception_tag
|
|
|
)
|
|
|
- } else {
|
|
|
- LogUtil.e("Get key info fail : $rfid")
|
|
|
- ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ ModBusController.updateKeyRfid(
|
|
|
+ dockBean.addr,
|
|
|
+ keyBean.isLeft,
|
|
|
+ rfid
|
|
|
+ )
|
|
|
+ // 放回钥匙,上锁
|
|
|
+ ModBusController.controlKeyBuckle(
|
|
|
+ false,
|
|
|
+ keyBean.isLeft,
|
|
|
+ dockBean.addr
|
|
|
+ ) {
|
|
|
+ NetApi.getKeyInfo(rfid) {
|
|
|
+ if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
+ ModBusController.updateKeyMac(
|
|
|
+ dockBean.addr,
|
|
|
+ keyBean.isLeft,
|
|
|
+ it.macAddress
|
|
|
+ )
|
|
|
+ ModBusController.updateKeyReadyStatus(
|
|
|
+ it.macAddress,
|
|
|
+ false,
|
|
|
+ 5
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ LogUtil.e("Get key info fail : $rfid")
|
|
|
+ ToastUtils.tip(R.string.get_key_info_fail)
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -421,20 +462,60 @@ object BusinessManager {
|
|
|
lockBean.idx,
|
|
|
rfid
|
|
|
)
|
|
|
- NetApi.getLockInfo(rfid) {
|
|
|
- if (it != null) {
|
|
|
- // TODO 考虑快速拿取
|
|
|
- ModBusController.controlLockBuckle(
|
|
|
- false,
|
|
|
- dockBean.addr,
|
|
|
- lockBean.idx
|
|
|
- ) { itRst ->
|
|
|
- if (itRst.isNotEmpty()) {
|
|
|
- // 上报锁具信息
|
|
|
- NetApi.updateLockReturn(
|
|
|
- rfid,
|
|
|
- MyApplication.instance!!.serialNo()
|
|
|
- ) {}
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ val lockStatusReq =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_PAD_LOCK_STATUS) }
|
|
|
+ val slotStatus =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_SLOT_STATUS) }
|
|
|
+ val slotType =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_SLOT_TYPE) }
|
|
|
+ val slotsPageReq =
|
|
|
+ async { getSlotsPage() }
|
|
|
+ var lockStatus = lockStatusReq.await()
|
|
|
+ val slotsPage = slotsPageReq.await()
|
|
|
+ val slotStatusList = slotStatus.await()
|
|
|
+ val slotTypeList = slotType.await()
|
|
|
+ NetApi.getIsLockPage { lockData ->
|
|
|
+ //锁rfid未异常正常请求锁数据,关锁
|
|
|
+ if (rfid in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.map { it.lockNfc }?.toMutableList()
|
|
|
+ ?: mutableListOf())
|
|
|
+ ) {
|
|
|
+ ToastUtils.tip(
|
|
|
+ MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.lock_exception_tag
|
|
|
+ )
|
|
|
+ )
|
|
|
+ } else if (slotsPage?.records
|
|
|
+ ?.filter {
|
|
|
+ it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue &&
|
|
|
+ it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
+ }
|
|
|
+ ?.find { it.row?.toInt() == dockBean.row &&(lockBean.idx+1) == it.col?.toInt() } != null
|
|
|
+ ) {
|
|
|
+ ToastUtils.tip(
|
|
|
+ MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.slot_exception_tag
|
|
|
+ )
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ NetApi.getLockInfo(rfid) {
|
|
|
+ if (it != null) {
|
|
|
+ // TODO 考虑快速拿取
|
|
|
+ ModBusController.controlLockBuckle(
|
|
|
+ false,
|
|
|
+ dockBean.addr,
|
|
|
+ lockBean.idx
|
|
|
+ ) { itRst ->
|
|
|
+ if (itRst.isNotEmpty()) {
|
|
|
+ // 上报锁具信息
|
|
|
+ NetApi.updateLockReturn(
|
|
|
+ rfid,
|
|
|
+ MyApplication.instance!!.serialNo()
|
|
|
+ ) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -506,22 +587,36 @@ object BusinessManager {
|
|
|
ModBusController.updateLockRfid(
|
|
|
dockBean.addr, deviceBean.idx, rfid
|
|
|
)
|
|
|
-
|
|
|
- NetApi.getLockInfo(rfid) {
|
|
|
- ModBusController.updateLockNewHardware(
|
|
|
- dockBean.addr, deviceBean.idx, it == null
|
|
|
- )
|
|
|
- if (it != null) {
|
|
|
- // TODO 考虑快速拿取
|
|
|
- ModBusController.controlLockBuckle(
|
|
|
- false, dockBean.addr, deviceBean.idx
|
|
|
- ) { itRst ->
|
|
|
- if (itRst.isNotEmpty()) {
|
|
|
- // 上报锁具信息
|
|
|
- NetApi.updateLockReturn(
|
|
|
- rfid,
|
|
|
- MyApplication.instance!!.serialNo()
|
|
|
- ) {}
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ val lockStatusReq =
|
|
|
+ async { fetchDict<CommonDictRespVO>(DictConstants.KEY_PAD_LOCK_STATUS) }
|
|
|
+ var lockStatus = lockStatusReq.await()
|
|
|
+ NetApi.getIsLockPage { lockData ->
|
|
|
+ //锁rfid未异常正常请求锁数据,关锁
|
|
|
+ if (rfid !in (lockData?.records?.filter { it.exStatus == lockStatus.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.map { it.lockNfc }?.toMutableList()
|
|
|
+ ?: mutableListOf())
|
|
|
+ ) {
|
|
|
+ NetApi.getLockInfo(rfid) {
|
|
|
+ ModBusController.updateLockNewHardware(
|
|
|
+ dockBean.addr,
|
|
|
+ deviceBean.idx,
|
|
|
+ it == null
|
|
|
+ )
|
|
|
+ if (it != null) {
|
|
|
+ // TODO 考虑快速拿取
|
|
|
+ ModBusController.controlLockBuckle(
|
|
|
+ false, dockBean.addr, deviceBean.idx
|
|
|
+ ) { itRst ->
|
|
|
+ if (itRst.isNotEmpty()) {
|
|
|
+ // 上报锁具信息
|
|
|
+ NetApi.updateLockReturn(
|
|
|
+ rfid,
|
|
|
+ MyApplication.instance!!.serialNo()
|
|
|
+ ) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -693,14 +788,14 @@ object BusinessManager {
|
|
|
async { fetchDict<CommonDictRespVO>(DictConstants.KEY_PAD_LOCK_STATUS) }
|
|
|
val slotStatus =
|
|
|
async { fetchDict<CommonDictRespVO>(DictConstants.KEY_SLOT_STATUS) }
|
|
|
- val keyStatus = async { fetchDict<CommonDictRespVO>(DictConstants.KEY_KEY_STATUS) }
|
|
|
val slotType = async { fetchDict<CommonDictRespVO>(DictConstants.KEY_SLOT_TYPE) }
|
|
|
+ val keyStatus = async { fetchDict<CommonDictRespVO>(DictConstants.KEY_KEY_STATUS) }
|
|
|
|
|
|
// 等待字典加载完成
|
|
|
val lockStatusList = lockStatus.await()
|
|
|
val slotStatusList = slotStatus.await()
|
|
|
- val keyStatusList = keyStatus.await()
|
|
|
val slotTypeList = slotType.await()
|
|
|
+ val keyStatusList = keyStatus.await()
|
|
|
|
|
|
// —— 在 Default 线程做计算密集操作 ——
|
|
|
val lockMap = withContext(Dispatchers.Default) {
|
|
|
@@ -1264,7 +1359,6 @@ object BusinessManager {
|
|
|
} else {
|
|
|
// 当前策略:作业票未完成禁止归还钥匙
|
|
|
showKeyReturnDialog {
|
|
|
-// handleKeyReturn(bleDevice, workTicketGetBO)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
ToastUtils.tip(R.string.continue_the_ticket)
|
|
|
BleManager.getInstance().disconnect(bleDevice)
|
|
|
@@ -1285,7 +1379,6 @@ object BusinessManager {
|
|
|
keyBean?.let {
|
|
|
ModBusController.controlKeyBuckle(false, keyBean.isLeft, dock.addr)
|
|
|
}
|
|
|
-
|
|
|
// 上报隔离点状态
|
|
|
val keyNfc = ModBusController.getKeyByMac(bleDevice.mac)?.rfid
|
|
|
workTicketGetBO?.data?.forEach { data ->
|
|
|
@@ -1309,8 +1402,11 @@ object BusinessManager {
|
|
|
ToastUtils.tip(R.string.key_return_success)
|
|
|
if (CAN_RETURN) {
|
|
|
// 上报点位钥匙绑定
|
|
|
- NetApi.updateLockPointBatch(updateList) { isSuccess ->
|
|
|
- if (isSuccess) {
|
|
|
+ NetApi.updateLockPointBatch(updateList) { isSuccess, msg ->
|
|
|
+ if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.ticket_lost
|
|
|
+ )
|
|
|
+ ) {
|
|
|
data.taskCode?.toLong()?.let {
|
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
|
@@ -1320,7 +1416,7 @@ object BusinessManager {
|
|
|
}
|
|
|
// 确认归还,切换为待机模式
|
|
|
switchReadyMode(bleDevice)
|
|
|
- } else {
|
|
|
+ } else if (msg != MyApplication.instance?.applicationContext!!.getString(R.string.lock_nfc_lost)) {
|
|
|
SPUtils.saveUpdateLockPoint(MyApplication.instance!!, updateList)
|
|
|
}
|
|
|
}
|
|
|
@@ -1689,8 +1785,11 @@ object BusinessManager {
|
|
|
if (!CAN_RETURN) return
|
|
|
val updateList = SPUtils.getUpdateLockPoint(context)
|
|
|
if (updateList.isNotEmpty()) {
|
|
|
- NetApi.updateLockPointBatch(updateList) { isSuccess ->
|
|
|
- if (isSuccess) {
|
|
|
+ NetApi.updateLockPointBatch(updateList) { isSuccess, msg ->
|
|
|
+ if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
+ R.string.ticket_lost
|
|
|
+ )
|
|
|
+ ) {
|
|
|
SPUtils.clearUpdateLockPoint(context)
|
|
|
}
|
|
|
}
|