|
@@ -24,6 +24,7 @@ import com.grkj.iscs_mars.modbus.DockBean
|
|
|
import com.grkj.iscs_mars.modbus.ModBusController
|
|
import com.grkj.iscs_mars.modbus.ModBusController
|
|
|
import com.grkj.iscs_mars.modbus.ModBusController.dockList
|
|
import com.grkj.iscs_mars.modbus.ModBusController.dockList
|
|
|
import com.grkj.iscs_mars.modbus.ModBusController.getOneKey
|
|
import com.grkj.iscs_mars.modbus.ModBusController.getOneKey
|
|
|
|
|
+import com.grkj.iscs_mars.model.Constants
|
|
|
import com.grkj.iscs_mars.model.Constants.USER_TYPE_LOCKER
|
|
import com.grkj.iscs_mars.model.Constants.USER_TYPE_LOCKER
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_CARD
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
import com.grkj.iscs_mars.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
|
|
@@ -63,6 +64,7 @@ import com.grkj.iscs_mars.model.vo.lock.LockPageRespVO
|
|
|
import com.grkj.iscs_mars.model.vo.lock.LockTakeUpdateReqVO
|
|
import com.grkj.iscs_mars.model.vo.lock.LockTakeUpdateReqVO
|
|
|
import com.grkj.iscs_mars.model.vo.ticket.LockPointUpdateReqVO
|
|
import com.grkj.iscs_mars.model.vo.ticket.LockPointUpdateReqVO
|
|
|
import com.grkj.iscs_mars.model.vo.ticket.TicketDetailRespVO
|
|
import com.grkj.iscs_mars.model.vo.ticket.TicketDetailRespVO
|
|
|
|
|
+import com.grkj.iscs_mars.service.CheckKeyInfoTask
|
|
|
import com.grkj.iscs_mars.util.ActivityUtils
|
|
import com.grkj.iscs_mars.util.ActivityUtils
|
|
|
import com.grkj.iscs_mars.util.CommonUtils
|
|
import com.grkj.iscs_mars.util.CommonUtils
|
|
|
import com.grkj.iscs_mars.util.Executor
|
|
import com.grkj.iscs_mars.util.Executor
|
|
@@ -73,6 +75,7 @@ import com.grkj.iscs_mars.util.log.LogUtil
|
|
|
import com.grkj.iscs_mars.view.activity.LoginActivity
|
|
import com.grkj.iscs_mars.view.activity.LoginActivity
|
|
|
import com.grkj.iscs_mars.view.base.BaseActivity
|
|
import com.grkj.iscs_mars.view.base.BaseActivity
|
|
|
import com.grkj.iscs_mars.view.dialog.TipDialog
|
|
import com.grkj.iscs_mars.view.dialog.TipDialog
|
|
|
|
|
+import com.sik.cronjob.managers.CronJobScanner
|
|
|
import com.sik.sikcore.SIKCore
|
|
import com.sik.sikcore.SIKCore
|
|
|
import com.sik.sikcore.date.TimeUtils
|
|
import com.sik.sikcore.date.TimeUtils
|
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
import com.sik.sikcore.thread.ThreadUtils
|
|
@@ -103,6 +106,11 @@ object BusinessManager {
|
|
|
|
|
|
|
|
private var initListener: (() -> Unit)? = null
|
|
private var initListener: (() -> Unit)? = null
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 断开连接任务
|
|
|
|
|
+ */
|
|
|
|
|
+ private val disconnectJob: HashMap<String, String> = hashMapOf()
|
|
|
|
|
+
|
|
|
// 归还设备是否需要登录
|
|
// 归还设备是否需要登录
|
|
|
var NEED_AUTH = true
|
|
var NEED_AUTH = true
|
|
|
|
|
|
|
@@ -143,6 +151,11 @@ object BusinessManager {
|
|
|
MSG_EVENT_DEVICE_TAKE_UPDATE -> {
|
|
MSG_EVENT_DEVICE_TAKE_UPDATE -> {
|
|
|
handleDeviceTake(it.data as DeviceTakeUpdateMsg)
|
|
handleDeviceTake(it.data as DeviceTakeUpdateMsg)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ MsgEventConstants.MSG_EVENT_INIT_KEY_COMPLETE -> {
|
|
|
|
|
+ val job = CronJobScanner.scanJobs(CheckKeyInfoTask())
|
|
|
|
|
+ MyApplication.cronJobManager.registerJobs(job)
|
|
|
|
|
+ }
|
|
|
// 钥匙当前模式
|
|
// 钥匙当前模式
|
|
|
MSG_EVENT_CURRENT_MODE -> {
|
|
MSG_EVENT_CURRENT_MODE -> {
|
|
|
handleCurrentMode(it.data as CurrentModeMsg)
|
|
handleCurrentMode(it.data as CurrentModeMsg)
|
|
@@ -230,8 +243,16 @@ object BusinessManager {
|
|
|
/**
|
|
/**
|
|
|
* 连接一把存在的可连接的钥匙
|
|
* 连接一把存在的可连接的钥匙
|
|
|
*/
|
|
*/
|
|
|
- private fun connectExistsKey(exceptKeyMac: String) {
|
|
|
|
|
|
|
+ fun connectExistsKey(exceptKeyMac: List<String> = listOf()) {
|
|
|
ThreadUtils.runOnIO {
|
|
ThreadUtils.runOnIO {
|
|
|
|
|
+ cancelDisconnectAllJob()
|
|
|
|
|
+ val connectedDevice = BleManager.getInstance().allConnectedDevice
|
|
|
|
|
+ if (connectedDevice.isNotEmpty() && connectedDevice.subtract(exceptKeyMac.toSet())
|
|
|
|
|
+ .isNotEmpty()
|
|
|
|
|
+ ) {
|
|
|
|
|
+ LogUtil.i("已有钥匙连接")
|
|
|
|
|
+ return@runOnIO
|
|
|
|
|
+ }
|
|
|
// —— 串行请求1 & 2 ——
|
|
// —— 串行请求1 & 2 ——
|
|
|
val slotsPage = getSlotsPage()
|
|
val slotsPage = getSlotsPage()
|
|
|
|
|
|
|
@@ -255,7 +276,7 @@ object BusinessManager {
|
|
|
}?.toMutableList() ?: mutableListOf(),
|
|
}?.toMutableList() ?: mutableListOf(),
|
|
|
(keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
(keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
|
|
|
?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()),
|
|
?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()),
|
|
|
- mutableListOf(exceptKeyMac)
|
|
|
|
|
|
|
+ exceptKeyMac
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -324,6 +345,13 @@ object BusinessManager {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取最多电量的钥匙
|
|
|
|
|
+ */
|
|
|
|
|
+ fun getMaxPowerKey(): DockBean.KeyBean {
|
|
|
|
|
+ return ModBusController.getMaxPowerKey()
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 硬件状态
|
|
* 硬件状态
|
|
|
* 1、检测到有钥匙
|
|
* 1、检测到有钥匙
|
|
@@ -838,6 +866,55 @@ object BusinessManager {
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 启动断连任务
|
|
|
|
|
+ */
|
|
|
|
|
+ fun launchDisconnectJob(mac: String) {
|
|
|
|
|
+ val jobId = ThreadUtils.runOnIODelayed(Constants.BLE_DISCONNECT_DELAY_TIME) {
|
|
|
|
|
+ val bleBean = getBleDeviceByMac(mac)
|
|
|
|
|
+ bleBean?.bleDevice?.let {
|
|
|
|
|
+ BleManager.getInstance().disconnect(it)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ disconnectJob[mac] = jobId
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 启动断连所有设备任务
|
|
|
|
|
+ */
|
|
|
|
|
+ fun launchDisconnectAllJob() {
|
|
|
|
|
+ deviceList.forEach { bleBean ->
|
|
|
|
|
+ val jobId = ThreadUtils.runOnIODelayed(Constants.BLE_DISCONNECT_DELAY_TIME) {
|
|
|
|
|
+ val bleBean = getBleDeviceByMac(bleBean.bleDevice.mac)
|
|
|
|
|
+ bleBean?.bleDevice?.let {
|
|
|
|
|
+ BleManager.getInstance().disconnect(it)
|
|
|
|
|
+ deviceList.removeIf { it == bleBean }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ disconnectJob[bleBean.bleDevice.mac] = jobId
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 取消断连所有设备任务
|
|
|
|
|
+ */
|
|
|
|
|
+ fun cancelDisconnectAllJob() {
|
|
|
|
|
+ disconnectJob.forEach {
|
|
|
|
|
+ ThreadUtils.cancel(it.value)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 取消断连任务
|
|
|
|
|
+ */
|
|
|
|
|
+ fun cancelDisconnectJob(mac: String) {
|
|
|
|
|
+ val jobId = disconnectJob[mac]
|
|
|
|
|
+ jobId?.let {
|
|
|
|
|
+ ThreadUtils.cancel(it)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 下发工作票
|
|
* 下发工作票
|
|
|
*/
|
|
*/
|
|
@@ -1118,14 +1195,11 @@ object BusinessManager {
|
|
|
|
|
|
|
|
byteArray.startsWith(BleConst.RSP_POWER_STATUS) -> {
|
|
byteArray.startsWith(BleConst.RSP_POWER_STATUS) -> {
|
|
|
val power = byteArray[4].toInt()
|
|
val power = byteArray[4].toInt()
|
|
|
|
|
+ ModBusController.getKeyByMac(bleBean.bleDevice.mac)?.power = power
|
|
|
if (power < 50) {//如果电量小于50就打开仓位充电
|
|
if (power < 50) {//如果电量小于50就打开仓位充电
|
|
|
ModBusController.controlKeyCharge(true, bleBean.bleDevice.mac) {
|
|
ModBusController.controlKeyCharge(true, bleBean.bleDevice.mac) {
|
|
|
LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 开始充电")
|
|
LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 开始充电")
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- ModBusController.controlKeyCharge(false, bleBean.bleDevice.mac) {
|
|
|
|
|
- LogUtil.i("钥匙: ${bleBean.bleDevice.mac} 关闭充电")
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1630,13 +1704,17 @@ object BusinessManager {
|
|
|
unregisterConnectListener(it)
|
|
unregisterConnectListener(it)
|
|
|
}
|
|
}
|
|
|
//待机数不够就再连一把,但不能是原来那把
|
|
//待机数不够就再连一把,但不能是原来那把
|
|
|
- if (BleManager.getInstance().allConnectedDevice.size < BleConst.MAX_KEY_STAND_BY) {
|
|
|
|
|
- ModBusController.getKeyByRfid(
|
|
|
|
|
- info.nfc
|
|
|
|
|
- )?.mac?.let {
|
|
|
|
|
- connectExistsKey(
|
|
|
|
|
- it
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ NetApi.getMySelfState {
|
|
|
|
|
+ if (it) {
|
|
|
|
|
+ ModBusController.getKeyByRfid(
|
|
|
|
|
+ info.nfc
|
|
|
|
|
+ )?.mac?.let {
|
|
|
|
|
+ val maxPowerMac = getMaxPowerKey().mac
|
|
|
|
|
+ if (maxPowerMac != it) {
|
|
|
|
|
+ connectExistsKey(listOf(it ?: ""))
|
|
|
|
|
+ launchDisconnectJob(it ?: "")
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1830,9 +1908,21 @@ object BusinessManager {
|
|
|
)
|
|
)
|
|
|
sendLoadingEventMsg(null, false)
|
|
sendLoadingEventMsg(null, false)
|
|
|
//连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
//连上之后没有工作票要下发就断开 看是否还有设备等待连接,没有就不断开,有就让路,一般是初始化的时候
|
|
|
- if (BleConnectionManager.hasConnectWait()) {
|
|
|
|
|
- BleManager.getInstance().disconnect(currentModeMsg.bleBean.bleDevice)
|
|
|
|
|
- deviceList.removeIf { device -> device.bleDevice.mac == currentModeMsg.bleBean.bleDevice.mac }
|
|
|
|
|
|
|
+ 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 ?: "")
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1986,8 +2076,11 @@ object BusinessManager {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ launchDisconnectAllJob()
|
|
|
sendLoadingEventMsg(null, false)
|
|
sendLoadingEventMsg(null, false)
|
|
|
- context.startActivity(Intent(context, LoginActivity::class.java))
|
|
|
|
|
|
|
+ context.startActivity(Intent(context, LoginActivity::class.java).apply {
|
|
|
|
|
+ flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|