|
|
@@ -1,6 +1,6 @@
|
|
|
package com.grkj.ui_base.service
|
|
|
|
|
|
-import com.grkj.ui_base.business.DataBusiness
|
|
|
+import android.annotation.SuppressLint
|
|
|
import com.grkj.ui_base.business.ModbusBusinessManager
|
|
|
import com.grkj.ui_base.utils.ble.BleSendDispatcher
|
|
|
import com.sik.cronjob.annotations.CronJob
|
|
|
@@ -15,22 +15,53 @@ import org.slf4j.LoggerFactory
|
|
|
class CheckKeyInfoTask {
|
|
|
private val logger: Logger = LoggerFactory.getLogger(this::class.java)
|
|
|
|
|
|
+ /**
|
|
|
+ * 是否在登录界面
|
|
|
+ */
|
|
|
+ private var isInLogin: Boolean = false
|
|
|
+ set(value) {
|
|
|
+ field = value
|
|
|
+ if (value) {
|
|
|
+ startCheckKeyInfo()
|
|
|
+ } else {
|
|
|
+ ThreadUtils.cancel(startCheckKeyInfoJob)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始检查钥匙信息任务
|
|
|
+ */
|
|
|
+ private var startCheckKeyInfoJob: String = ""
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开始检查钥匙信息延迟60s
|
|
|
+ */
|
|
|
+ private fun startCheckKeyInfo() {
|
|
|
+ startCheckKeyInfoJob = ThreadUtils.runOnIODelayed(60 * 1000L) {
|
|
|
+ checkKeyInfo()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 检查钥匙信息
|
|
|
*/
|
|
|
+ @SuppressLint("MissingPermission")
|
|
|
@CronJob(intervalMillis = 30 * 60_000L, initialDelay = 0, runOnMainThread = false)
|
|
|
fun checkKeyInfo() {
|
|
|
logger.info("开始检查钥匙信息")
|
|
|
-// val existsKey = ModbusBusinessManager.getExistsKey()
|
|
|
-// ThreadUtils.runOnIO {
|
|
|
-// for (bean in existsKey) {
|
|
|
-// bean.mac?.let { mac ->
|
|
|
-// BleSendDispatcher.submit(mac) {
|
|
|
-// logger.info("信息获取完成,检查是否立即断开")
|
|
|
-// DataBusiness.checkMyTodoForHandleKey(mac, 0)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
+ val existsKey = ModbusBusinessManager.getExistsKey()
|
|
|
+ ThreadUtils.runOnIO {
|
|
|
+ for (bean in existsKey) {
|
|
|
+ bean.mac?.let { mac ->
|
|
|
+ if (BleSendDispatcher.canConnect() && isInLogin) {
|
|
|
+ BleSendDispatcher.submit(mac) {
|
|
|
+ if (isInLogin) {
|
|
|
+ BleSendDispatcher.scheduleDisconnect(mac)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|