|
|
@@ -1,7 +1,62 @@
|
|
|
package com.grkj.iscs.view.presenter
|
|
|
|
|
|
+import com.grkj.iscs.BusinessManager
|
|
|
+import com.grkj.iscs.extentions.removeLeadingZeros
|
|
|
+import com.grkj.iscs.extentions.toHexStrings
|
|
|
+import com.grkj.iscs.modbus.DockBean
|
|
|
+import com.grkj.iscs.modbus.ModBusController
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
|
|
|
+import com.grkj.iscs.util.Executor
|
|
|
+import com.grkj.iscs.view.activity.HomeActivity
|
|
|
import com.grkj.iscs.view.base.BasePresenter
|
|
|
import com.grkj.iscs.view.iview.IHomeView
|
|
|
|
|
|
class HomePresenter : BasePresenter<IHomeView>() {
|
|
|
+
|
|
|
+ fun registerStatusListener() {
|
|
|
+ BusinessManager.registerStatusListener(this) { dockBean ->
|
|
|
+ when (dockBean.type) {
|
|
|
+ DOCK_TYPE_KEY -> {
|
|
|
+ dockBean.deviceList.forEach { deviceBean ->
|
|
|
+ if (deviceBean.isExist) {
|
|
|
+ when (deviceBean.type) {
|
|
|
+ DEVICE_TYPE_KEY -> {
|
|
|
+ // 延迟1s防止mac未赋值
|
|
|
+ Executor.delayOnMain(1000) {
|
|
|
+ getTicket(dockBean, (deviceBean as DockBean.KeyBean).isLeft, 3)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getTicket(dockBean: DockBean, isLeft: Boolean, retryCount: Int) {
|
|
|
+ if (retryCount == 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ ModBusController.readKeyRfid(dockBean.addr.toInt() - 1, if (isLeft) 0 else 1) { isLeft, res ->
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ val keyBean = ModBusController.getKeyByRfid(rfid)
|
|
|
+ if (keyBean?.mac == null) {
|
|
|
+ Executor.delayOnMain(1000) {
|
|
|
+ getTicket(dockBean, isLeft, retryCount - 1)
|
|
|
+ }
|
|
|
+ return@readKeyRfid
|
|
|
+ }
|
|
|
+ BusinessManager.getTicketStatusBusiness(keyBean.mac!!, mvpView as HomeActivity) { b, s, rst ->
|
|
|
+ Executor.runOnMain {
|
|
|
+ (mvpView as HomeActivity).handleLoading(b, s)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun unregisterListener() {
|
|
|
+ BusinessManager.unregisterListener(this)
|
|
|
+ }
|
|
|
}
|