|
@@ -94,8 +94,7 @@ object BusinessManager {
|
|
|
|
|
|
|
|
// Modbus数据页面监听
|
|
// Modbus数据页面监听
|
|
|
class DeviceListener(
|
|
class DeviceListener(
|
|
|
- val key: Any,
|
|
|
|
|
- val callBack: (DockBean) -> Unit
|
|
|
|
|
|
|
+ val key: Any, val callBack: (DockBean) -> Unit
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
private val listeners = ArrayList<DeviceListener>()
|
|
private val listeners = ArrayList<DeviceListener>()
|
|
@@ -131,8 +130,7 @@ object BusinessManager {
|
|
|
Executor.runOnMain {
|
|
Executor.runOnMain {
|
|
|
val loadingMsg = it.data as LoadingMsg
|
|
val loadingMsg = it.data as LoadingMsg
|
|
|
(ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(
|
|
(ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(
|
|
|
- loadingMsg.isShow,
|
|
|
|
|
- loadingMsg.loadingText
|
|
|
|
|
|
|
+ loadingMsg.isShow, loadingMsg.loadingText
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -170,14 +168,10 @@ object BusinessManager {
|
|
|
ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
|
|
ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
|
|
|
keyBean.isReady = false
|
|
keyBean.isReady = false
|
|
|
ModBusController.controlKeyBuckle(
|
|
ModBusController.controlKeyBuckle(
|
|
|
- true,
|
|
|
|
|
- keyBean.isLeft,
|
|
|
|
|
- dock?.addr
|
|
|
|
|
|
|
+ true, keyBean.isLeft, dock?.addr
|
|
|
)
|
|
)
|
|
|
ModBusController.updateKeyReadyStatus(
|
|
ModBusController.updateKeyReadyStatus(
|
|
|
- it.data.bleBean.bleDevice.mac,
|
|
|
|
|
- false,
|
|
|
|
|
- 1
|
|
|
|
|
|
|
+ it.data.bleBean.bleDevice.mac, false, 1
|
|
|
)
|
|
)
|
|
|
ToastUtils.tip(R.string.take_out_key)
|
|
ToastUtils.tip(R.string.take_out_key)
|
|
|
}
|
|
}
|
|
@@ -192,9 +186,7 @@ object BusinessManager {
|
|
|
2 -> {
|
|
2 -> {
|
|
|
if (it.data.res == 1) {
|
|
if (it.data.res == 1) {
|
|
|
ModBusController.updateKeyReadyStatus(
|
|
ModBusController.updateKeyReadyStatus(
|
|
|
- it.data.bleBean.bleDevice.mac,
|
|
|
|
|
- true,
|
|
|
|
|
- 2
|
|
|
|
|
|
|
+ it.data.bleBean.bleDevice.mac, true, 2
|
|
|
)
|
|
)
|
|
|
// 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
// 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
|
|
|
Executor.delayOnMain(500) {
|
|
Executor.delayOnMain(500) {
|
|
@@ -253,15 +245,11 @@ object BusinessManager {
|
|
|
withContext(Dispatchers.Default) {
|
|
withContext(Dispatchers.Default) {
|
|
|
val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
|
|
val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
|
|
|
getOneKey(
|
|
getOneKey(
|
|
|
- slotsPage?.records
|
|
|
|
|
- ?.filter {
|
|
|
|
|
- it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue &&
|
|
|
|
|
- it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
|
|
- }?.toMutableList() ?: mutableListOf(),
|
|
|
|
|
- (keyPage?.records
|
|
|
|
|
- ?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
|
|
- ?.map { it.keyNfc ?: "" }
|
|
|
|
|
- ?.toMutableList() ?: mutableListOf()),
|
|
|
|
|
|
|
+ slotsPage?.records?.filter {
|
|
|
|
|
+ it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
|
|
+ }?.toMutableList() ?: mutableListOf(),
|
|
|
|
|
+ (keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
|
|
+ ?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()),
|
|
|
mutableListOf(exceptKeyMac)
|
|
mutableListOf(exceptKeyMac)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -351,31 +339,26 @@ object BusinessManager {
|
|
|
if (keyBean.isExist) {
|
|
if (keyBean.isExist) {
|
|
|
// 放回钥匙,读取rfid
|
|
// 放回钥匙,读取rfid
|
|
|
ModBusController.readKeyRfid(
|
|
ModBusController.readKeyRfid(
|
|
|
- dockBean.addr,
|
|
|
|
|
- if (keyBean.isLeft) 0 else 1
|
|
|
|
|
|
|
+ dockBean.addr, if (keyBean.isLeft) 0 else 1
|
|
|
) { isLeft, res ->
|
|
) { isLeft, res ->
|
|
|
ModBusController.controlKeyCharge(
|
|
ModBusController.controlKeyCharge(
|
|
|
- true,
|
|
|
|
|
- keyBean.isLeft,
|
|
|
|
|
- dockBean.addr
|
|
|
|
|
|
|
+ true, keyBean.isLeft, dockBean.addr
|
|
|
)
|
|
)
|
|
|
if (res.size < 11) {
|
|
if (res.size < 11) {
|
|
|
LogUtil.e("Key rfid error")
|
|
LogUtil.e("Key rfid error")
|
|
|
return@readKeyRfid
|
|
return@readKeyRfid
|
|
|
}
|
|
}
|
|
|
- val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
|
|
- .removeLeadingZeros()
|
|
|
|
|
|
|
+ val rfid =
|
|
|
|
|
+ res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
ThreadUtils.runOnIO {
|
|
ThreadUtils.runOnIO {
|
|
|
val slotStatus =
|
|
val slotStatus =
|
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
|
|
|
val slotType =
|
|
val slotType =
|
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
|
|
|
- val slotsPageReq =
|
|
|
|
|
- async { getSlotsPage() }
|
|
|
|
|
|
|
+ val slotsPageReq = async { getSlotsPage() }
|
|
|
val keyStatusReq =
|
|
val keyStatusReq =
|
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_KEY_STATUS) }
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_KEY_STATUS) }
|
|
|
- val keyPageReq =
|
|
|
|
|
- async { getKeyPage() }
|
|
|
|
|
|
|
+ val keyPageReq = async { getKeyPage() }
|
|
|
var keyStatus = keyStatusReq.await()
|
|
var keyStatus = keyStatusReq.await()
|
|
|
var keyData = keyPageReq.await()
|
|
var keyData = keyPageReq.await()
|
|
|
val slotsPage = slotsPageReq.await()
|
|
val slotsPage = slotsPageReq.await()
|
|
@@ -391,13 +374,10 @@ object BusinessManager {
|
|
|
R.string.key_exception_tag
|
|
R.string.key_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 && it.col?.toInt() == (dockBean.col + (if (keyBean.isLeft) 0 else 1) * 2) } != null
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ } 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(
|
|
ToastUtils.tip(
|
|
|
MyApplication.instance?.applicationContext!!.getString(
|
|
MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.slot_exception_tag
|
|
R.string.slot_exception_tag
|
|
@@ -405,27 +385,19 @@ object BusinessManager {
|
|
|
)
|
|
)
|
|
|
} else {
|
|
} else {
|
|
|
ModBusController.updateKeyRfid(
|
|
ModBusController.updateKeyRfid(
|
|
|
- dockBean.addr,
|
|
|
|
|
- keyBean.isLeft,
|
|
|
|
|
- rfid
|
|
|
|
|
|
|
+ dockBean.addr, keyBean.isLeft, rfid
|
|
|
)
|
|
)
|
|
|
// 放回钥匙,上锁
|
|
// 放回钥匙,上锁
|
|
|
ModBusController.controlKeyBuckle(
|
|
ModBusController.controlKeyBuckle(
|
|
|
- false,
|
|
|
|
|
- keyBean.isLeft,
|
|
|
|
|
- dockBean.addr
|
|
|
|
|
|
|
+ false, keyBean.isLeft, dockBean.addr
|
|
|
) {
|
|
) {
|
|
|
NetApi.getKeyInfo(rfid) {
|
|
NetApi.getKeyInfo(rfid) {
|
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
ModBusController.updateKeyMac(
|
|
ModBusController.updateKeyMac(
|
|
|
- dockBean.addr,
|
|
|
|
|
- keyBean.isLeft,
|
|
|
|
|
- it.macAddress
|
|
|
|
|
|
|
+ dockBean.addr, keyBean.isLeft, it.macAddress
|
|
|
)
|
|
)
|
|
|
ModBusController.updateKeyReadyStatus(
|
|
ModBusController.updateKeyReadyStatus(
|
|
|
- it.macAddress,
|
|
|
|
|
- false,
|
|
|
|
|
- 5
|
|
|
|
|
|
|
+ it.macAddress, false, 5
|
|
|
)
|
|
)
|
|
|
} else {
|
|
} else {
|
|
|
LogUtil.e("Get key info fail : $rfid")
|
|
LogUtil.e("Get key info fail : $rfid")
|
|
@@ -459,12 +431,10 @@ object BusinessManager {
|
|
|
LogUtil.e("Lock rfid error")
|
|
LogUtil.e("Lock rfid error")
|
|
|
return@readLockRfid
|
|
return@readLockRfid
|
|
|
}
|
|
}
|
|
|
- val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
|
|
- .removeLeadingZeros()
|
|
|
|
|
|
|
+ val rfid =
|
|
|
|
|
+ res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
ModBusController.updateLockRfid(
|
|
ModBusController.updateLockRfid(
|
|
|
- dockBean.addr,
|
|
|
|
|
- lockBean.idx,
|
|
|
|
|
- rfid
|
|
|
|
|
|
|
+ dockBean.addr, lockBean.idx, rfid
|
|
|
)
|
|
)
|
|
|
ThreadUtils.runOnIO {
|
|
ThreadUtils.runOnIO {
|
|
|
val lockStatusReq =
|
|
val lockStatusReq =
|
|
@@ -473,8 +443,7 @@ object BusinessManager {
|
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_STATUS) }
|
|
|
val slotType =
|
|
val slotType =
|
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
|
|
async { fetchDict<CommonDictRespVO>(DictAndSystemConstants.KEY_SLOT_TYPE) }
|
|
|
- val slotsPageReq =
|
|
|
|
|
- async { getSlotsPage() }
|
|
|
|
|
|
|
+ val slotsPageReq = async { getSlotsPage() }
|
|
|
var lockStatus = lockStatusReq.await()
|
|
var lockStatus = lockStatusReq.await()
|
|
|
val slotsPage = slotsPageReq.await()
|
|
val slotsPage = slotsPageReq.await()
|
|
|
val slotStatusList = slotStatus.await()
|
|
val slotStatusList = slotStatus.await()
|
|
@@ -490,13 +459,10 @@ object BusinessManager {
|
|
|
R.string.lock_exception_tag
|
|
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
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ } 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(
|
|
ToastUtils.tip(
|
|
|
MyApplication.instance?.applicationContext!!.getString(
|
|
MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.slot_exception_tag
|
|
R.string.slot_exception_tag
|
|
@@ -507,9 +473,7 @@ object BusinessManager {
|
|
|
if (it != null) {
|
|
if (it != null) {
|
|
|
// TODO 考虑快速拿取
|
|
// TODO 考虑快速拿取
|
|
|
ModBusController.controlLockBuckle(
|
|
ModBusController.controlLockBuckle(
|
|
|
- false,
|
|
|
|
|
- dockBean.addr,
|
|
|
|
|
- lockBean.idx
|
|
|
|
|
|
|
+ false, dockBean.addr, lockBean.idx
|
|
|
) { itRst ->
|
|
) { itRst ->
|
|
|
if (itRst.isNotEmpty()) {
|
|
if (itRst.isNotEmpty()) {
|
|
|
// 上报锁具信息
|
|
// 上报锁具信息
|
|
@@ -548,8 +512,7 @@ object BusinessManager {
|
|
|
when (deviceBean.type) {
|
|
when (deviceBean.type) {
|
|
|
DEVICE_TYPE_KEY -> {
|
|
DEVICE_TYPE_KEY -> {
|
|
|
ModBusController.readKeyRfid(
|
|
ModBusController.readKeyRfid(
|
|
|
- dockBean.addr,
|
|
|
|
|
- deviceBean.idx
|
|
|
|
|
|
|
+ dockBean.addr, deviceBean.idx
|
|
|
) { isLeft, res ->
|
|
) { isLeft, res ->
|
|
|
if (res.size < 11) {
|
|
if (res.size < 11) {
|
|
|
LogUtil.e("Key rfid error")
|
|
LogUtil.e("Key rfid error")
|
|
@@ -558,9 +521,7 @@ object BusinessManager {
|
|
|
val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
.removeLeadingZeros()
|
|
.removeLeadingZeros()
|
|
|
ModBusController.updateKeyRfid(
|
|
ModBusController.updateKeyRfid(
|
|
|
- dockBean.addr,
|
|
|
|
|
- true,
|
|
|
|
|
- rfid
|
|
|
|
|
|
|
+ dockBean.addr, true, rfid
|
|
|
)
|
|
)
|
|
|
NetApi.getKeyInfo(rfid) {
|
|
NetApi.getKeyInfo(rfid) {
|
|
|
ModBusController.updateKeyNewHardware(
|
|
ModBusController.updateKeyNewHardware(
|
|
@@ -593,12 +554,11 @@ object BusinessManager {
|
|
|
dockBean.addr, deviceBean.idx, rfid
|
|
dockBean.addr, deviceBean.idx, rfid
|
|
|
)
|
|
)
|
|
|
ThreadUtils.runOnIO {
|
|
ThreadUtils.runOnIO {
|
|
|
- val lockStatusReq =
|
|
|
|
|
- async {
|
|
|
|
|
- fetchDict<CommonDictRespVO>(
|
|
|
|
|
- DictAndSystemConstants.KEY_PAD_LOCK_STATUS
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val lockStatusReq = async {
|
|
|
|
|
+ fetchDict<CommonDictRespVO>(
|
|
|
|
|
+ DictAndSystemConstants.KEY_PAD_LOCK_STATUS
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
var lockStatus = lockStatusReq.await()
|
|
var lockStatus = lockStatusReq.await()
|
|
|
NetApi.getIsLockPage { lockData ->
|
|
NetApi.getIsLockPage { lockData ->
|
|
|
//锁rfid未异常正常请求锁数据,关锁
|
|
//锁rfid未异常正常请求锁数据,关锁
|
|
@@ -772,11 +732,9 @@ object BusinessManager {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 2. 把原本同步的字典查询留在 IO 线程
|
|
// 2. 把原本同步的字典查询留在 IO 线程
|
|
|
- private suspend fun <T> fetchDict(key: String): List<T> =
|
|
|
|
|
- withContext(Dispatchers.IO) {
|
|
|
|
|
- @Suppress("UNCHECKED_CAST")
|
|
|
|
|
- NetApi.getDictData(key) as List<T>
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private suspend fun <T> fetchDict(key: String): List<T> = withContext(Dispatchers.IO) {
|
|
|
|
|
+ @Suppress("UNCHECKED_CAST") NetApi.getDictData(key) as List<T>
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// 3. 重写 checkEquipCount
|
|
// 3. 重写 checkEquipCount
|
|
|
fun checkEquipCount(
|
|
fun checkEquipCount(
|
|
@@ -812,15 +770,11 @@ object BusinessManager {
|
|
|
val lockMap = withContext(Dispatchers.Default) {
|
|
val lockMap = withContext(Dispatchers.Default) {
|
|
|
ModBusController.getLocks(
|
|
ModBusController.getLocks(
|
|
|
needLockCount,
|
|
needLockCount,
|
|
|
- slotsPage?.records
|
|
|
|
|
- ?.filter {
|
|
|
|
|
- it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue &&
|
|
|
|
|
- it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
|
|
- }?.toMutableList() ?: mutableListOf(),
|
|
|
|
|
- locksPage?.records
|
|
|
|
|
- ?.filter { it.exStatus == lockStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
|
|
- ?.map { it.lockNfc ?: "" }
|
|
|
|
|
- ?.toMutableList() ?: mutableListOf()
|
|
|
|
|
|
|
+ slotsPage?.records?.filter {
|
|
|
|
|
+ it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
|
|
+ }?.toMutableList() ?: mutableListOf(),
|
|
|
|
|
+ locksPage?.records?.filter { it.exStatus == lockStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
|
|
+ ?.map { it.lockNfc ?: "" }?.toMutableList() ?: mutableListOf()
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -840,15 +794,11 @@ object BusinessManager {
|
|
|
val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
|
|
val keyPage = withContext(Dispatchers.IO) { getKeyPage() }
|
|
|
keyPair = withContext(Dispatchers.Default) {
|
|
keyPair = withContext(Dispatchers.Default) {
|
|
|
getOneKey(
|
|
getOneKey(
|
|
|
- slotsPage?.records
|
|
|
|
|
- ?.filter {
|
|
|
|
|
- it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue &&
|
|
|
|
|
- it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
|
|
- }?.toMutableList() ?: mutableListOf(),
|
|
|
|
|
- keyPage?.records
|
|
|
|
|
- ?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
|
|
- ?.map { it.keyNfc ?: "" }
|
|
|
|
|
- ?.toMutableList() ?: mutableListOf()
|
|
|
|
|
|
|
+ slotsPage?.records?.filter {
|
|
|
|
|
+ it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
|
|
|
|
|
+ }?.toMutableList() ?: mutableListOf(),
|
|
|
|
|
+ keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
|
|
+ ?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
if (keyPair == null) {
|
|
if (keyPair == null) {
|
|
@@ -884,9 +834,7 @@ object BusinessManager {
|
|
|
* 注册连接监听
|
|
* 注册连接监听
|
|
|
*/
|
|
*/
|
|
|
fun registerConnectListener(
|
|
fun registerConnectListener(
|
|
|
- mac: String,
|
|
|
|
|
- connectNow: Boolean = false,
|
|
|
|
|
- callBack: ((
|
|
|
|
|
|
|
+ mac: String, connectNow: Boolean = false, callBack: ((
|
|
|
Boolean, BleBean?
|
|
Boolean, BleBean?
|
|
|
) -> Unit)? = null
|
|
) -> Unit)? = null
|
|
|
) {
|
|
) {
|
|
@@ -1410,9 +1358,7 @@ object BusinessManager {
|
|
|
* ticketFinished主要是后端的作业票是否已经结束,结束了,就直接修改状态就好了
|
|
* ticketFinished主要是后端的作业票是否已经结束,结束了,就直接修改状态就好了
|
|
|
*/
|
|
*/
|
|
|
private fun handleKeyReturn(
|
|
private fun handleKeyReturn(
|
|
|
- bleDevice: BleDevice,
|
|
|
|
|
- workTicketGetBO: WorkTicketGetBO?,
|
|
|
|
|
- ticketFinished: Boolean
|
|
|
|
|
|
|
+ bleDevice: BleDevice, workTicketGetBO: WorkTicketGetBO?, ticketFinished: Boolean
|
|
|
) {
|
|
) {
|
|
|
val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
val keyBean = dock?.getKeyList()?.find { it.mac == bleDevice.mac }
|
|
val keyBean = dock?.getKeyList()?.find { it.mac == bleDevice.mac }
|
|
@@ -1442,14 +1388,40 @@ object BusinessManager {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
sendLoadingEventMsg(null, false)
|
|
sendLoadingEventMsg(null, false)
|
|
|
- ToastUtils.tip(R.string.key_return_success)
|
|
|
|
|
if (CAN_RETURN) {
|
|
if (CAN_RETURN) {
|
|
|
// 上报点位钥匙绑定
|
|
// 上报点位钥匙绑定
|
|
|
- NetApi.updateLockPointBatch(updateList) { isSuccess, msg ->
|
|
|
|
|
- if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
|
|
- R.string.lock_nfc_lost
|
|
|
|
|
- )
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ NetApi.updateLockPointBatch(updateList) { isSuccess, msg, code ->
|
|
|
|
|
+ LogUtil.i("还锁操作:${isSuccess},${msg},${code}")
|
|
|
|
|
+ if (isSuccess) {
|
|
|
|
|
+ // 上报钥匙归还
|
|
|
|
|
+ NetApi.updateKeyReturn(
|
|
|
|
|
+ data.taskCode?.toLong()!!,
|
|
|
|
|
+ keyNfc!!,
|
|
|
|
|
+ MyApplication.instance!!.serialNo()
|
|
|
|
|
+ ) { isSuccess, msg, code ->
|
|
|
|
|
+ if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
|
|
|
|
|
+ R.string.ticket_lost
|
|
|
|
|
+ )
|
|
|
|
|
+ ) {
|
|
|
|
|
+ SPUtils.saveUpdateKeyReturn(
|
|
|
|
|
+ MyApplication.instance!!,
|
|
|
|
|
+ UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!)
|
|
|
|
|
+ )
|
|
|
|
|
+ if (msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
|
|
+ R.string.ticket_lost
|
|
|
|
|
+ )
|
|
|
|
|
+ ) {
|
|
|
|
|
+ sendEventMsg(
|
|
|
|
|
+ MsgEvent(
|
|
|
|
|
+ MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ ToastUtils.tip(R.string.key_return_success)
|
|
|
|
|
+ }else{
|
|
|
|
|
+ ToastUtils.tip(R.string.key_return_success)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
data.taskCode?.toLong()?.let {
|
|
data.taskCode?.toLong()?.let {
|
|
|
sendEventMsg(
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
MsgEvent(
|
|
@@ -1460,34 +1432,26 @@ object BusinessManager {
|
|
|
}
|
|
}
|
|
|
// 确认归还,切换为待机模式
|
|
// 确认归还,切换为待机模式
|
|
|
switchReadyMode(bleDevice)
|
|
switchReadyMode(bleDevice)
|
|
|
- } else if (msg != MyApplication.instance?.applicationContext!!.getString(R.string.lock_nfc_lost)) {
|
|
|
|
|
- SPUtils.saveUpdateLockPoint(MyApplication.instance!!, updateList)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 上报钥匙归还
|
|
|
|
|
- NetApi.updateKeyReturn(
|
|
|
|
|
- data.taskCode?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()
|
|
|
|
|
- ) { isSuccess, msg ->
|
|
|
|
|
- if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
|
|
|
|
|
- R.string.ticket_lost
|
|
|
|
|
- )
|
|
|
|
|
- ) {
|
|
|
|
|
- SPUtils.saveUpdateKeyReturn(
|
|
|
|
|
- MyApplication.instance!!,
|
|
|
|
|
- UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!)
|
|
|
|
|
- )
|
|
|
|
|
- if (msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
|
|
- R.string.ticket_lost
|
|
|
|
|
- )
|
|
|
|
|
- ) {
|
|
|
|
|
- sendEventMsg(
|
|
|
|
|
- MsgEvent(
|
|
|
|
|
- MsgEventConstants.MSG_EVENT_TICKET_FINISHED,
|
|
|
|
|
- null
|
|
|
|
|
- )
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ThreadUtils.runOnMain {
|
|
|
|
|
+ // 当前策略:作业票未完成禁止归还钥匙
|
|
|
|
|
+ showKeyReturnDialog {
|
|
|
|
|
+ sendLoadingEventMsg(null, false)
|
|
|
|
|
+ ToastUtils.tip(R.string.continue_the_ticket)
|
|
|
|
|
+ BleManager.getInstance().disconnect(bleDevice)
|
|
|
|
|
+ // 打开卡扣,防止初始化的时候选择不处理钥匙导致无法使用
|
|
|
|
|
+ val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
|
|
|
|
|
+ val keyBean =
|
|
|
|
|
+ dock?.getKeyList()?.find { it.mac == bleDevice.mac }
|
|
|
|
|
+ keyBean?.let {
|
|
|
|
|
+ ModBusController.controlKeyBuckle(
|
|
|
|
|
+ true, keyBean.isLeft, dock.addr
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ SPUtils.clearUpdateKeyReturn(MyApplication.instance!!)
|
|
|
|
|
+ SPUtils.clearUpdateLockPoint(MyApplication.instance!!)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -1522,7 +1486,7 @@ object BusinessManager {
|
|
|
// 上报钥匙归还
|
|
// 上报钥匙归还
|
|
|
NetApi.updateKeyReturn(
|
|
NetApi.updateKeyReturn(
|
|
|
taskCode, keyNfc, MyApplication.instance!!.serialNo()
|
|
taskCode, keyNfc, MyApplication.instance!!.serialNo()
|
|
|
- ) { isSuccess, msg ->
|
|
|
|
|
|
|
+ ) { isSuccess, msg, code ->
|
|
|
if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
|
|
if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.ticket_lost
|
|
R.string.ticket_lost
|
|
|
)
|
|
)
|
|
@@ -1536,8 +1500,7 @@ object BusinessManager {
|
|
|
) {
|
|
) {
|
|
|
sendEventMsg(
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
MsgEvent(
|
|
|
- MsgEventConstants.MSG_EVENT_TICKET_FINISHED,
|
|
|
|
|
- null
|
|
|
|
|
|
|
+ MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -1800,7 +1763,10 @@ object BusinessManager {
|
|
|
?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
|
|
?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
|
|
|
step = it
|
|
step = it
|
|
|
}
|
|
}
|
|
|
- NetApi.getTicketDetail(itBO.ticketId) { ticketDetail ->
|
|
|
|
|
|
|
+ NetApi.getTicketDetail(itBO.ticketId) { ticketDetail, _ ->
|
|
|
|
|
+ if (ticketDetail == null) {
|
|
|
|
|
+ return@getTicketDetail
|
|
|
|
|
+ }
|
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
it.userId == SPUtils.getLoginUser(MyApplication.instance?.applicationContext!!)?.userId && it.userType == USER_TYPE_LOCKER
|
|
it.userId == SPUtils.getLoginUser(MyApplication.instance?.applicationContext!!)?.userId && it.userType == USER_TYPE_LOCKER
|
|
|
}
|
|
}
|
|
@@ -1857,12 +1823,11 @@ object BusinessManager {
|
|
|
if (!CAN_RETURN) return
|
|
if (!CAN_RETURN) return
|
|
|
val updateList = SPUtils.getUpdateLockPoint(context)
|
|
val updateList = SPUtils.getUpdateLockPoint(context)
|
|
|
if (updateList.isNotEmpty()) {
|
|
if (updateList.isNotEmpty()) {
|
|
|
- NetApi.updateLockPointBatch(updateList) { isSuccess, msg ->
|
|
|
|
|
- if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
|
|
- R.string.lock_nfc_lost
|
|
|
|
|
- )
|
|
|
|
|
- ) {
|
|
|
|
|
|
|
+ NetApi.updateLockPointBatch(updateList) { isSuccess, msg, code ->
|
|
|
|
|
+ LogUtil.i("submitKeyData还锁操作:${isSuccess},${msg},${code}")
|
|
|
|
|
+ if (isSuccess || code == 500) {
|
|
|
SPUtils.clearUpdateLockPoint(context)
|
|
SPUtils.clearUpdateLockPoint(context)
|
|
|
|
|
+ SPUtils.clearUpdateKeyReturn(context)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1877,7 +1842,7 @@ object BusinessManager {
|
|
|
itemsToRemove.forEach { itData ->
|
|
itemsToRemove.forEach { itData ->
|
|
|
NetApi.updateKeyReturn(
|
|
NetApi.updateKeyReturn(
|
|
|
itData.ticketId, itData.keyNfc, context.serialNo()
|
|
itData.ticketId, itData.keyNfc, context.serialNo()
|
|
|
- ) { isSuccess, msg ->
|
|
|
|
|
|
|
+ ) { isSuccess, msg, code ->
|
|
|
count++
|
|
count++
|
|
|
if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
|
|
if (isSuccess || msg == MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.ticket_lost
|
|
R.string.ticket_lost
|
|
@@ -1893,8 +1858,7 @@ object BusinessManager {
|
|
|
) {
|
|
) {
|
|
|
sendEventMsg(
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
MsgEvent(
|
|
|
- MsgEventConstants.MSG_EVENT_TICKET_FINISHED,
|
|
|
|
|
- null
|
|
|
|
|
|
|
+ MsgEventConstants.MSG_EVENT_TICKET_FINISHED, null
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|