|
|
@@ -73,8 +73,10 @@ import com.grkj.iscs.view.dialog.TipDialog
|
|
|
import com.sik.sikcore.activity.ActivityTracker
|
|
|
import com.sik.sikcore.date.TimeUtils
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.delay
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
import pub.devrel.easypermissions.AfterPermissionGranted
|
|
|
-import java.time.LocalDateTime
|
|
|
|
|
|
/**
|
|
|
* 业务层管理
|
|
|
@@ -223,7 +225,8 @@ object BusinessManager {
|
|
|
val switchListReqVOS = ModBusController.getSwitchData().map {
|
|
|
SwitchListReqVO(
|
|
|
it.idx.toString(),
|
|
|
- if (it.enabled) switchStatus?.find { it.dictLabel == "打开" }?.dictValue else switchStatus?.find { it.dictLabel == "关闭" }?.dictValue
|
|
|
+ if (it.enabled) switchStatus?.find { it.dictLabel == "打开" }?.dictValue else switchStatus?.find { it.dictLabel == "关闭" }?.dictValue,
|
|
|
+ TimeUtils.nowString(TimeUtils.DEFAULT_DATE_HOUR_MIN_SEC_FORMAT)
|
|
|
)
|
|
|
}
|
|
|
NetApi.updateSwitchList(switchListReqVOS) {
|
|
|
@@ -435,15 +438,11 @@ object BusinessManager {
|
|
|
)
|
|
|
NetApi.getKeyInfo(rfid) {
|
|
|
ModBusController.updateKeyNewHardware(
|
|
|
- dockBean.addr,
|
|
|
- true,
|
|
|
- it == null
|
|
|
+ dockBean.addr, true, it == null
|
|
|
)
|
|
|
if (it != null && !it.macAddress.isNullOrEmpty()) {
|
|
|
ModBusController.updateKeyMac(
|
|
|
- dockBean.addr,
|
|
|
- isLeft,
|
|
|
- it.macAddress
|
|
|
+ dockBean.addr, isLeft, it.macAddress
|
|
|
)
|
|
|
// showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr)
|
|
|
} else {
|
|
|
@@ -456,8 +455,7 @@ object BusinessManager {
|
|
|
|
|
|
DEVICE_TYPE_LOCK -> {
|
|
|
ModBusController.readLockRfid(
|
|
|
- dockBean.addr,
|
|
|
- deviceBean.idx
|
|
|
+ dockBean.addr, deviceBean.idx
|
|
|
) { res ->
|
|
|
if (res.size < 11) {
|
|
|
LogUtil.e("Lock rfid error")
|
|
|
@@ -466,23 +464,17 @@ object BusinessManager {
|
|
|
val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
.removeLeadingZeros()
|
|
|
ModBusController.updateLockRfid(
|
|
|
- dockBean.addr,
|
|
|
- deviceBean.idx,
|
|
|
- rfid
|
|
|
+ dockBean.addr, deviceBean.idx, rfid
|
|
|
)
|
|
|
|
|
|
NetApi.getLockInfo(rfid) {
|
|
|
ModBusController.updateLockNewHardware(
|
|
|
- dockBean.addr,
|
|
|
- deviceBean.idx,
|
|
|
- it == null
|
|
|
+ dockBean.addr, deviceBean.idx, it == null
|
|
|
)
|
|
|
if (it != null) {
|
|
|
// TODO 考虑快速拿取
|
|
|
ModBusController.controlLockBuckle(
|
|
|
- false,
|
|
|
- dockBean.addr,
|
|
|
- deviceBean.idx
|
|
|
+ false, dockBean.addr, deviceBean.idx
|
|
|
) { itRst ->
|
|
|
if (itRst.isNotEmpty()) {
|
|
|
// 上报锁具信息
|
|
|
@@ -630,55 +622,61 @@ object BusinessManager {
|
|
|
var lockCount = 0
|
|
|
NetApi.getIsLockCabinetSlotsPage { slots ->
|
|
|
NetApi.getIsLockPage { locks ->
|
|
|
- val lockMap = ModBusController.getLocks(
|
|
|
- needLockCount,
|
|
|
- slots?.records?.filter { it.slotType == "1" && it.status == "1" }
|
|
|
- ?.toMutableList()
|
|
|
- ?: mutableListOf(),
|
|
|
- locks?.records?.filter { it.exStatus == "1" }?.map { it.lockNfc }
|
|
|
- ?.toMutableList()
|
|
|
- ?: mutableListOf()
|
|
|
- )
|
|
|
- lockMap.forEach { (_, rfidList) ->
|
|
|
- lockCount += rfidList.size
|
|
|
- }
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ val lockStatus = NetApi.getDictData(DictConstants.KEY_PAD_LOCK_STATUS)
|
|
|
+ val slotsStatus = NetApi.getDictData(DictConstants.KEY_SLOT_STATUS)
|
|
|
+ val keyStatus = NetApi.getDictData(DictConstants.KEY_KEY_STATUS)
|
|
|
+ val slotsType = NetApi.getDictData(DictConstants.KEY_SLOT_TYPE)
|
|
|
+ val lockMap = ModBusController.getLocks(
|
|
|
+ needLockCount,
|
|
|
+ slots?.records?.filter { it.slotType == slotsType?.find { it.dictLabel == "锁" }?.dictValue && it.status == slotsStatus?.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.toMutableList() ?: mutableListOf(),
|
|
|
+ locks?.records?.filter { it.exStatus == lockStatus?.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.map { it.lockNfc }?.toMutableList() ?: mutableListOf()
|
|
|
+ )
|
|
|
+ lockMap.forEach { (_, rfidList) ->
|
|
|
+ lockCount += rfidList.size
|
|
|
+ }
|
|
|
|
|
|
- var tipStr = ""
|
|
|
- if (lockCount < needLockCount) {
|
|
|
- val msg =
|
|
|
- MyApplication.instance!!.applicationContext.resources.getString(R.string.lock_is_not_enough)
|
|
|
- LogUtil.w(msg)
|
|
|
- lockMap.clear()
|
|
|
- }
|
|
|
+ var tipStr = ""
|
|
|
+ if (lockCount < needLockCount) {
|
|
|
+ val msg =
|
|
|
+ MyApplication.instance!!.applicationContext.resources.getString(R.string.lock_is_not_enough)
|
|
|
+ LogUtil.w(msg)
|
|
|
+ lockMap.clear()
|
|
|
+ }
|
|
|
|
|
|
- var key: Pair<Byte, DockBean.KeyBean?>? = null
|
|
|
- if (isNeedKey && lockCount >= needLockCount) {
|
|
|
- NetApi.getIsKeyPage { keyList ->
|
|
|
- key = ModBusController.getOneKey(
|
|
|
- slots?.records?.filter { it.slotType == "0" && it.status == "1" }
|
|
|
- ?.toMutableList()
|
|
|
- ?: mutableListOf(),
|
|
|
- keyList?.records?.filter { it.exStatus == "1" }?.map { it.keyNfc }
|
|
|
- ?.toMutableList() ?: mutableListOf()
|
|
|
- )
|
|
|
- if (key == null) {
|
|
|
- val msg =
|
|
|
- MyApplication.instance!!.applicationContext.resources.getString(R.string.no_available_key)
|
|
|
- LogUtil.w(msg)
|
|
|
- tipStr = if (tipStr.isEmpty()) {
|
|
|
- msg
|
|
|
- } else {
|
|
|
- tipStr + "\n" + msg
|
|
|
+ var key: Pair<Byte, DockBean.KeyBean?>? = null
|
|
|
+ if (isNeedKey && lockCount >= needLockCount) {
|
|
|
+ NetApi.getIsKeyPage { keyList ->
|
|
|
+ key =
|
|
|
+ ModBusController.getOneKey(slots?.records?.filter { it.slotType == slotsType?.find { it.dictLabel == "钥匙" }?.dictValue && it.status == slotsStatus?.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.toMutableList() ?: mutableListOf(),
|
|
|
+ keyList?.records?.filter { it.exStatus == keyStatus?.find { it.dictLabel == "异常" }?.dictValue }
|
|
|
+ ?.map { it.keyNfc }?.toMutableList() ?: mutableListOf())
|
|
|
+ if (key == null) {
|
|
|
+ val msg =
|
|
|
+ MyApplication.instance!!.applicationContext.resources.getString(
|
|
|
+ R.string.no_available_key
|
|
|
+ )
|
|
|
+ LogUtil.w(msg)
|
|
|
+ tipStr = if (tipStr.isEmpty()) {
|
|
|
+ msg
|
|
|
+ } else {
|
|
|
+ tipStr + "\n" + msg
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- if (tipStr.isNotEmpty()) {
|
|
|
- ToastUtils.tip(tipStr)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ if (tipStr.isNotEmpty()) {
|
|
|
+ ToastUtils.tip(tipStr)
|
|
|
+ }
|
|
|
+ LogUtil.i("checkEquipCount : key = $key, lockMap = $lockMap")
|
|
|
+ callBack.invoke(key, lockMap)
|
|
|
+ }
|
|
|
}
|
|
|
- LogUtil.i("checkEquipCount : key = $key, lockMap = $lockMap")
|
|
|
- callBack.invoke(key, lockMap)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -706,6 +704,7 @@ object BusinessManager {
|
|
|
connectListeners.add(ConnectListener(mac, callBack))
|
|
|
if (connectListeners.size > 0) {
|
|
|
Executor.runOnMain {
|
|
|
+ //todo 连接钥匙
|
|
|
connectKey()
|
|
|
}
|
|
|
}
|
|
|
@@ -715,6 +714,7 @@ object BusinessManager {
|
|
|
connectListeners.add(ConnectListener(mac, callBack))
|
|
|
if (connectListeners.size > 0) {
|
|
|
Executor.runOnMain {
|
|
|
+ //todo 连接钥匙
|
|
|
connectKey()
|
|
|
}
|
|
|
}
|
|
|
@@ -768,9 +768,7 @@ object BusinessManager {
|
|
|
return
|
|
|
}
|
|
|
prepareBle(
|
|
|
- listener.mac,
|
|
|
- ActivityUtils.currentActivity() as BaseActivity<*>,
|
|
|
- false
|
|
|
+ listener.mac, ActivityUtils.currentActivity() as BaseActivity<*>, false
|
|
|
) { isDone, bleBean ->
|
|
|
Executor.runOnMain {
|
|
|
isPreparing = false
|
|
|
@@ -779,7 +777,10 @@ object BusinessManager {
|
|
|
if (checkProcess(listener.mac)) {
|
|
|
unregisterConnectListener(listener.mac)
|
|
|
Executor.delayOnMain(2000) {
|
|
|
- registerConnectListener(listener.mac, listener.callBack)
|
|
|
+ registerConnectListener(
|
|
|
+ listener.mac,
|
|
|
+ listener.callBack
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
return@runOnMain
|
|
|
@@ -812,13 +813,6 @@ object BusinessManager {
|
|
|
return
|
|
|
}
|
|
|
Executor.runOnMain {
|
|
|
- // 如果是已经连上的设备,从indicate开始往下走,不需要再扫描了
|
|
|
-// if (BleManager.getInstance().isConnected(mac)) {
|
|
|
-// deviceList.find { it.bleDevice.mac == mac }?.let { itBleDevice ->
|
|
|
-// indicate(itBleDevice, isNeedLoading, prepareDoneCallBack)
|
|
|
-// return@runOnMain
|
|
|
-// }
|
|
|
-// }
|
|
|
CommonUtils.checkBlePermission(activity) {
|
|
|
doScanBle(mac, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
@@ -838,8 +832,7 @@ object BusinessManager {
|
|
|
}
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(true, "正在扫描设备...", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(true, "正在扫描设备...", null)
|
|
|
)
|
|
|
)
|
|
|
BleUtil.instance?.scan(object : CustomBleScanCallback() {
|
|
|
@@ -854,8 +847,7 @@ object BusinessManager {
|
|
|
if (!success) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
)
|
|
|
)
|
|
|
prepareDoneCallBack?.invoke(false, null)
|
|
|
@@ -865,6 +857,7 @@ object BusinessManager {
|
|
|
override fun onScanning(bleDevice: BleDevice?) {
|
|
|
LogUtil.i("onScanning:${bleDevice?.mac}")
|
|
|
bleDevice?.let {
|
|
|
+ deviceList
|
|
|
doConnect(it, isNeedLoading, prepareDoneCallBack)
|
|
|
}
|
|
|
}
|
|
|
@@ -873,8 +866,7 @@ object BusinessManager {
|
|
|
LogUtil.i("onScanFinished: $mac - ${scanResultList?.none { it.mac == mac }}")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
)
|
|
|
)
|
|
|
// 没有扫描到
|
|
|
@@ -907,13 +899,11 @@ object BusinessManager {
|
|
|
)
|
|
|
BleManager.getInstance().disconnect(bleDevice)
|
|
|
BleUtil.instance?.connectBySelect(
|
|
|
- bleDevice,
|
|
|
- object : CustomBleGattCallback() {
|
|
|
+ bleDevice, object : CustomBleGattCallback() {
|
|
|
override fun onPrompt(promptStr: String?) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, promptStr, null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, promptStr, null)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -932,14 +922,11 @@ object BusinessManager {
|
|
|
}
|
|
|
|
|
|
override fun onConnectSuccess(
|
|
|
- bleDevice: BleDevice?,
|
|
|
- gatt: BluetoothGatt?,
|
|
|
- status: Int
|
|
|
+ bleDevice: BleDevice?, gatt: BluetoothGatt?, status: Int
|
|
|
) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.i("onConnectSuccess : ${bleDevice?.mac}")
|
|
|
@@ -971,8 +958,7 @@ object BusinessManager {
|
|
|
) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, false)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, false)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.i("onDisConnected : ${device?.mac} - $isActiveDisConnected")
|
|
|
@@ -1018,15 +1004,13 @@ object BusinessManager {
|
|
|
}
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(true, "开始监听...", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(true, "开始监听...", null)
|
|
|
)
|
|
|
)
|
|
|
bleBean?.let {
|
|
|
var isIndicateSuccess = false
|
|
|
BleUtil.instance?.indicate(
|
|
|
- it.bleDevice,
|
|
|
- indicateCallback = object : CustomBleIndicateCallback() {
|
|
|
+ it.bleDevice, indicateCallback = object : CustomBleIndicateCallback() {
|
|
|
override fun onPrompt(promptStr: String?) {
|
|
|
LogUtil.i("indicate onPrompt : $promptStr")
|
|
|
}
|
|
|
@@ -1050,8 +1034,7 @@ object BusinessManager {
|
|
|
override fun onIndicateFailure(exception: BleException?) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, false)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, false)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.e("onIndicateFailure : ${bleBean.bleDevice.mac} - ${exception?.description}")
|
|
|
@@ -1087,8 +1070,7 @@ object BusinessManager {
|
|
|
}
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(true, "开始获取token...", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(true, "开始获取token...", null)
|
|
|
)
|
|
|
)
|
|
|
bleBean?.let {
|
|
|
@@ -1096,8 +1078,7 @@ object BusinessManager {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "token获取成功", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "token获取成功", null)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.i("getToken success : ${bleBean.bleDevice.mac}")
|
|
|
@@ -1106,8 +1087,7 @@ object BusinessManager {
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "token获取失败", false)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "token获取失败", false)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.e("getToken fail : ${bleBean.bleDevice.mac}")
|
|
|
@@ -1193,8 +1173,7 @@ object BusinessManager {
|
|
|
* 读取工作票完成情况
|
|
|
*/
|
|
|
private fun getTicketStatusBusiness(
|
|
|
- mac: String,
|
|
|
- isNeedLoading: Boolean = false
|
|
|
+ mac: String, isNeedLoading: Boolean = false
|
|
|
) {
|
|
|
registerConnectListener(mac) { isDone, bleBean ->
|
|
|
if (isDone) {
|
|
|
@@ -1204,8 +1183,7 @@ object BusinessManager {
|
|
|
} else {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, false)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, false)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -1249,9 +1227,7 @@ object BusinessManager {
|
|
|
)
|
|
|
)
|
|
|
BleCmdManager.sendWorkTicket(
|
|
|
- jsonStr,
|
|
|
- bleDevice = bleDevice,
|
|
|
- callback = object : CustomBleWriteCallback() {
|
|
|
+ jsonStr, bleDevice = bleDevice, callback = object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
LogUtil.i("sendTicket success")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
@@ -1281,9 +1257,7 @@ object BusinessManager {
|
|
|
* @param vo 工作票详情
|
|
|
*/
|
|
|
private fun generateTicketSendJson(
|
|
|
- isLock: Boolean,
|
|
|
- vo: TicketDetailRespVO,
|
|
|
- lockList: MutableList<String?>?
|
|
|
+ isLock: Boolean, vo: TicketDetailRespVO, lockList: MutableList<String?>?
|
|
|
): String {
|
|
|
LogUtil.i("generateTicketSendJson : $lockList")
|
|
|
// 用ticketStatus的"待上锁"进行判断
|
|
|
@@ -1303,8 +1277,7 @@ object BusinessManager {
|
|
|
bo.password =
|
|
|
SPUtils.getLoginUser(MyApplication.instance!!.applicationContext)?.keyCode ?: "123456"
|
|
|
val dataBO = WorkTicketSendBO.DataBO(
|
|
|
- taskCode = vo.ticketId.toString(),
|
|
|
- codeId = 1
|
|
|
+ taskCode = vo.ticketId.toString(), codeId = 1
|
|
|
)
|
|
|
val taskList = ArrayList<WorkTicketSendBO.DataBO.DataListBO>()
|
|
|
vo.ticketPointsVOList?.let { itList ->
|
|
|
@@ -1366,8 +1339,7 @@ object BusinessManager {
|
|
|
when {
|
|
|
// 获取令牌
|
|
|
byteArray.startsWith(BleConst.RSP_GET_TOKEN) -> BleCmdManager.handleToken(
|
|
|
- bleBean.bleDevice,
|
|
|
- byteArray
|
|
|
+ bleBean.bleDevice, byteArray
|
|
|
) { isSuccess ->
|
|
|
if (isSuccess) {
|
|
|
prepareDoneCallBack?.invoke(true, bleBean)
|
|
|
@@ -1378,17 +1350,14 @@ object BusinessManager {
|
|
|
handleSwitchModeResult(byteArray, isNeedLoading) { res, job ->
|
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_SWITCH_MODE,
|
|
|
- SwitchModeMsg(job.toInt(), res.toInt(), bleBean)
|
|
|
+ MSG_EVENT_SWITCH_MODE, SwitchModeMsg(job.toInt(), res.toInt(), bleBean)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
}
|
|
|
// 工作票下发
|
|
|
byteArray.startsWith(BleConst.RSP_SEND_WORK_TICKET) -> handleWorkTicketResult(
|
|
|
- bleBean,
|
|
|
- byteArray,
|
|
|
- isNeedLoading
|
|
|
+ bleBean, byteArray, isNeedLoading
|
|
|
)
|
|
|
// 获取设备当前状态
|
|
|
byteArray.startsWith(BleConst.RSP_CURRENT_STATUS) -> BleCmdManager.handleCurrentStatus(
|
|
|
@@ -1397,8 +1366,9 @@ object BusinessManager {
|
|
|
sendEventMsg(MsgEvent(MSG_EVENT_CURRENT_MODE, CurrentModeMsg(bleBean, it)))
|
|
|
}
|
|
|
// 获取设备工作票完成情况
|
|
|
- byteArray.startsWith(BleConst.RSP_WORK_TICKET_RESULT) && byteArray[3] == 0x02.toByte() ->
|
|
|
- handleTicketStatus(bleBean.bleDevice, byteArray, isNeedLoading)
|
|
|
+ byteArray.startsWith(BleConst.RSP_WORK_TICKET_RESULT) && byteArray[3] == 0x02.toByte() -> handleTicketStatus(
|
|
|
+ bleBean.bleDevice, byteArray, isNeedLoading
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1417,24 +1387,21 @@ object BusinessManager {
|
|
|
LogUtil.i("切换工作模式成功")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "切换工作模式成功", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "切换工作模式成功", null)
|
|
|
)
|
|
|
)
|
|
|
} else if (res == 0x01.toByte() && job == 0x02.toByte()) {
|
|
|
LogUtil.i("切换待机模式成功")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "切换待机模式成功", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "切换待机模式成功", null)
|
|
|
)
|
|
|
)
|
|
|
} else {
|
|
|
LogUtil.e("切换模式失败 : ${job.toInt()} - ${res.toInt()}")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -1447,15 +1414,12 @@ object BusinessManager {
|
|
|
* res:0x00:成功 0x01:失败 0x02:传输超时 0x0D:当前IDX超出范围 0x0E:当前数据CRC校验失败 0x14:JSON结构错误 0x63:未知错误
|
|
|
*/
|
|
|
private fun handleWorkTicketResult(
|
|
|
- bleBean: BleBean,
|
|
|
- byteArray: ByteArray,
|
|
|
- isNeedLoading: Boolean = false
|
|
|
+ bleBean: BleBean, byteArray: ByteArray, isNeedLoading: Boolean = false
|
|
|
) {
|
|
|
BleCmdManager.handleWorkTicketResult(bleBean, byteArray) { isSuccess, rst ->
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, null, null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, null, null)
|
|
|
)
|
|
|
)
|
|
|
if (isSuccess) {
|
|
|
@@ -1463,8 +1427,7 @@ object BusinessManager {
|
|
|
LogUtil.i("工作票下发完毕")
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(true, "切换钥匙为工作模式", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(true, "切换钥匙为工作模式", null)
|
|
|
)
|
|
|
)
|
|
|
|
|
|
@@ -1554,9 +1517,7 @@ object BusinessManager {
|
|
|
* 处理工作票完成情况
|
|
|
*/
|
|
|
private fun handleTicketStatus(
|
|
|
- bleDevice: BleDevice,
|
|
|
- byteArray: ByteArray,
|
|
|
- isNeedLoading: Boolean = false
|
|
|
+ bleDevice: BleDevice, byteArray: ByteArray, isNeedLoading: Boolean = false
|
|
|
) {
|
|
|
BleCmdManager.handleTicketStatus(bleDevice, byteArray) { ticketJson ->
|
|
|
if (ticketJson.isNullOrEmpty()) {
|
|
|
@@ -1564,16 +1525,14 @@ object BusinessManager {
|
|
|
}
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "工作票完成状态读取完成", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "工作票完成状态读取完成", null)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.i("Get ticket status complete : ${bleDevice.mac}")
|
|
|
// TD:Ticket Done
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "TD$ticketJson}", true)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "TD$ticketJson}", true)
|
|
|
)
|
|
|
)
|
|
|
|
|
|
@@ -1637,8 +1596,7 @@ object BusinessManager {
|
|
|
data.taskCode?.toLong()?.let {
|
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_UPDATE_TICKET_PROGRESS,
|
|
|
- UpdateTicketProgressMsg(it)
|
|
|
+ MSG_EVENT_UPDATE_TICKET_PROGRESS, UpdateTicketProgressMsg(it)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -1651,9 +1609,7 @@ object BusinessManager {
|
|
|
|
|
|
// 上报钥匙归还
|
|
|
NetApi.updateKeyReturn(
|
|
|
- data.taskCode?.toLong()!!,
|
|
|
- keyNfc!!,
|
|
|
- MyApplication.instance!!.serialNo()
|
|
|
+ data.taskCode?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()
|
|
|
) { isSuccess, msg ->
|
|
|
if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.ticket_lost
|
|
|
@@ -1668,8 +1624,7 @@ object BusinessManager {
|
|
|
} else {
|
|
|
SPUtils.saveUpdateLockPoint(MyApplication.instance!!, updateList)
|
|
|
SPUtils.saveUpdateKeyReturn(
|
|
|
- MyApplication.instance!!,
|
|
|
- UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!)
|
|
|
+ MyApplication.instance!!, UpdateKeyReturnBO(data.taskCode?.toLong()!!, keyNfc!!)
|
|
|
)
|
|
|
// 保存待发数据,切换为待机模式
|
|
|
switchReadyMode(bleDevice)
|
|
|
@@ -1695,24 +1650,20 @@ object BusinessManager {
|
|
|
fun handleVirtualKeyReturn(taskCode: Long, keyNfc: String, done: () -> Unit) {
|
|
|
// 上报钥匙归还
|
|
|
NetApi.updateKeyReturn(
|
|
|
- taskCode,
|
|
|
- keyNfc,
|
|
|
- MyApplication.instance!!.serialNo()
|
|
|
+ taskCode, keyNfc, MyApplication.instance!!.serialNo()
|
|
|
) { isSuccess, msg ->
|
|
|
if (!isSuccess && msg != MyApplication.instance?.applicationContext!!.getString(
|
|
|
R.string.ticket_lost
|
|
|
)
|
|
|
) {
|
|
|
SPUtils.saveUpdateKeyReturn(
|
|
|
- MyApplication.instance!!,
|
|
|
- UpdateKeyReturnBO(taskCode, keyNfc)
|
|
|
+ MyApplication.instance!!, UpdateKeyReturnBO(taskCode, keyNfc)
|
|
|
)
|
|
|
} else {
|
|
|
done()
|
|
|
sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_UPDATE_TICKET_PROGRESS,
|
|
|
- UpdateTicketProgressMsg(taskCode)
|
|
|
+ MSG_EVENT_UPDATE_TICKET_PROGRESS, UpdateTicketProgressMsg(taskCode)
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -1744,16 +1695,14 @@ object BusinessManager {
|
|
|
) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(true, "开始获取工作票", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(true, "开始获取工作票", null)
|
|
|
)
|
|
|
)
|
|
|
BleCmdManager.getTicketStatus(bleDevice, object : CustomBleWriteCallback() {
|
|
|
override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "工作票获取成功", null)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取成功", null)
|
|
|
)
|
|
|
)
|
|
|
LogUtil.i("getTicketStatus success")
|
|
|
@@ -1762,8 +1711,7 @@ object BusinessManager {
|
|
|
override fun onWriteFailure(exception: BleException?) {
|
|
|
if (isNeedLoading) sendEventMsg(
|
|
|
MsgEvent(
|
|
|
- MSG_EVENT_LOADING,
|
|
|
- LoadingMsg(false, "工作票获取失败", false)
|
|
|
+ MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取失败", false)
|
|
|
)
|
|
|
)
|
|
|
processCallback?.invoke(false)
|
|
|
@@ -1796,9 +1744,7 @@ object BusinessManager {
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
SPUtils.takeKey(info.ticketId)
|
|
|
NetApi.updateKeyTake(
|
|
|
- info.ticketId,
|
|
|
- info.nfc,
|
|
|
- MyApplication.instance?.serialNo()!!
|
|
|
+ info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!
|
|
|
) { isSuccess ->
|
|
|
if (isSuccess) {
|
|
|
mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_KEY && it.nfc == info.nfc }
|
|
|
@@ -1819,9 +1765,7 @@ object BusinessManager {
|
|
|
NetApi.updateLockTake(
|
|
|
mutableListOf(
|
|
|
LockTakeUpdateReqVO(
|
|
|
- info.ticketId,
|
|
|
- info.nfc,
|
|
|
- MyApplication.instance?.serialNo()!!
|
|
|
+ info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!
|
|
|
)
|
|
|
)
|
|
|
) { isSuccess ->
|
|
|
@@ -1897,15 +1841,11 @@ object BusinessManager {
|
|
|
tipDialog.show()
|
|
|
} else {
|
|
|
addDeviceTake(
|
|
|
- DEVICE_TYPE_KEY,
|
|
|
- deviceTakeUpdateBO.ticketId,
|
|
|
- keyPair.second?.rfid!!
|
|
|
+ DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!
|
|
|
)
|
|
|
handleGiveKey(
|
|
|
DeviceTakeUpdateBO(
|
|
|
- DEVICE_TYPE_KEY,
|
|
|
- deviceTakeUpdateBO.ticketId,
|
|
|
- keyPair.second?.rfid!!
|
|
|
+ DEVICE_TYPE_KEY, deviceTakeUpdateBO.ticketId, keyPair.second?.rfid!!
|
|
|
)
|
|
|
)
|
|
|
}
|
|
|
@@ -1951,8 +1891,7 @@ object BusinessManager {
|
|
|
currentModeMsg.bleBean.bleDevice.mac,
|
|
|
ticketDetail,
|
|
|
ticketDetail.ticketLockVOList?.filter { it.lockStatus != "2" }
|
|
|
- ?.map { it.lockNfc }
|
|
|
- ?.toMutableList(),
|
|
|
+ ?.map { it.lockNfc }?.toMutableList(),
|
|
|
ActivityUtils.currentActivity() as BaseActivity<*>,
|
|
|
true
|
|
|
)
|
|
|
@@ -1970,13 +1909,10 @@ object BusinessManager {
|
|
|
}
|
|
|
} ?: let {
|
|
|
ModBusController.updateKeyReadyStatus(
|
|
|
- currentModeMsg.bleBean.bleDevice.mac,
|
|
|
- true,
|
|
|
- 4
|
|
|
+ currentModeMsg.bleBean.bleDevice.mac, true, 4
|
|
|
)
|
|
|
ModBusController.controlKeyBuckle(
|
|
|
- false,
|
|
|
- currentModeMsg.bleBean.bleDevice.mac
|
|
|
+ false, currentModeMsg.bleBean.bleDevice.mac
|
|
|
)
|
|
|
sendLoadingEventMsg(null, false)
|
|
|
}
|
|
|
@@ -1986,8 +1922,7 @@ object BusinessManager {
|
|
|
0x03.toByte() -> {
|
|
|
// TODO 上报?
|
|
|
ToastUtils.tip(
|
|
|
- "${currentModeMsg.bleBean.bleDevice.mac} : " +
|
|
|
- "${CommonUtils.getStr(R.string.key_is_in_failure_mode)}"
|
|
|
+ "${currentModeMsg.bleBean.bleDevice.mac} : " + "${CommonUtils.getStr(R.string.key_is_in_failure_mode)}"
|
|
|
)
|
|
|
}
|
|
|
}
|