|
|
@@ -2,6 +2,7 @@ package com.grkj.iscs
|
|
|
|
|
|
import android.bluetooth.BluetoothGatt
|
|
|
import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
import androidx.lifecycle.MutableLiveData
|
|
|
import com.clj.fastble.BleManager
|
|
|
@@ -24,8 +25,12 @@ import com.grkj.iscs.extentions.startsWith
|
|
|
import com.grkj.iscs.extentions.toHexStrings
|
|
|
import com.grkj.iscs.modbus.DockBean
|
|
|
import com.grkj.iscs.modbus.ModBusController
|
|
|
+import com.grkj.iscs.modbus.ModBusController.controlKeyBuckle
|
|
|
+import com.grkj.iscs.modbus.ModBusController.controlLockBuckle
|
|
|
+import com.grkj.iscs.modbus.ModBusController.dockList
|
|
|
import com.grkj.iscs.model.Constants.PERMISSION_REQUEST_CODE
|
|
|
import com.grkj.iscs.model.Constants.USER_TYPE_LOCKER
|
|
|
+import com.grkj.iscs.model.DeviceConst
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
@@ -60,6 +65,7 @@ import com.grkj.iscs.util.NetApi
|
|
|
import com.grkj.iscs.util.SPUtils
|
|
|
import com.grkj.iscs.util.ToastUtils
|
|
|
import com.grkj.iscs.util.log.LogUtil
|
|
|
+import com.grkj.iscs.view.activity.LoginActivity
|
|
|
import com.grkj.iscs.view.base.BaseActivity
|
|
|
import com.grkj.iscs.view.dialog.TipDialog
|
|
|
import pub.devrel.easypermissions.AfterPermissionGranted
|
|
|
@@ -1373,4 +1379,54 @@ object BusinessManager {
|
|
|
fun sendLoadingEventMsg(str: String?, isShow: Boolean = true) {
|
|
|
mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(isShow, str, false)))
|
|
|
}
|
|
|
+
|
|
|
+ fun logout(context: Context) {
|
|
|
+ NetApi.logout()
|
|
|
+ // 关所有有设备的卡扣
|
|
|
+ dockList.filter { it.type == DOCK_TYPE_LOCK || it.type == DOCK_TYPE_PORTABLE }.forEach { dockBean ->
|
|
|
+ val hasLockIdxList = dockBean.getLockList().filter { it.isExist }.map { it.idx } as MutableList<Int>
|
|
|
+ controlLockBuckle(false, dockBean.addr, hasLockIdxList)
|
|
|
+ }
|
|
|
+ dockList.filter { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }.forEach { dockBean ->
|
|
|
+ dockBean.getKeyList().forEach { key ->
|
|
|
+ if (key.isExist) {
|
|
|
+ controlKeyBuckle(false, key.isLeft, dockBean.addr)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reConnectKey()
|
|
|
+ sendLoadingEventMsg(null, false)
|
|
|
+ context.startActivity(Intent(context, LoginActivity::class.java))
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 钥匙重新连接,清除内部作业票,清除所有代取设备重新分配
|
|
|
+ */
|
|
|
+ private fun reConnectKey() {
|
|
|
+ val keyList = mDeviceTakeList.filter { it.deviceType == DEVICE_TYPE_KEY }
|
|
|
+ // 不拿的设备不归你,下次登录重新按需分配
|
|
|
+ // 尽早clear,防止触发handleCurrentMode导致重新下发作业票
|
|
|
+ mDeviceTakeList.clear()
|
|
|
+ // 连接后直接切换待机模式,让钥匙作业票失效并且重新准备完毕
|
|
|
+ keyList.forEach {
|
|
|
+ val mac = ModBusController.getKeyByRfid(it.nfc)?.mac
|
|
|
+ if (mac == null) {
|
|
|
+ NetApi.getKeyInfo(it.nfc) { keyInfo ->
|
|
|
+ keyInfo?.macAddress?.let { itMac ->
|
|
|
+ registerConnectListener(itMac) { isDone, bleBean ->
|
|
|
+ if (isDone && bleBean != null) {
|
|
|
+ switchReadyMode(bleBean.bleDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ registerConnectListener(mac) { isDone, bleBean ->
|
|
|
+ if (isDone && bleBean != null) {
|
|
|
+ switchReadyMode(bleBean.bleDevice)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|