|
|
@@ -0,0 +1,101 @@
|
|
|
+package com.grkj.iscs.presenter
|
|
|
+
|
|
|
+import android.content.Context
|
|
|
+import android.content.Intent
|
|
|
+import android.view.View
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.grkj.iscs.BusinessManager
|
|
|
+import com.grkj.iscs.R
|
|
|
+import com.grkj.iscs.base.BaseActivity
|
|
|
+import com.grkj.iscs.base.BasePresenter
|
|
|
+import com.grkj.iscs.extentions.removeLeadingZeros
|
|
|
+import com.grkj.iscs.extentions.toHexStrings
|
|
|
+import com.grkj.iscs.iview.ILoginView
|
|
|
+import com.grkj.iscs.modbus.ModBusController
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_LOCK
|
|
|
+import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
|
|
|
+import com.grkj.iscs.model.WorkTicketStatusBean
|
|
|
+import com.grkj.iscs.presentation.LockerActivity
|
|
|
+import com.grkj.iscs.presentation.LockerTogetherActivity
|
|
|
+import com.grkj.iscs.presentation.PresentationManager
|
|
|
+import com.grkj.iscs.util.ActivityUtils
|
|
|
+import com.grkj.iscs.util.Executor
|
|
|
+import com.grkj.iscs.util.NetApi
|
|
|
+import com.grkj.iscs.util.ToastUtils
|
|
|
+
|
|
|
+class LoginPresenter : BasePresenter<ILoginView>() {
|
|
|
+
|
|
|
+ fun login(context: Context, account: String, pwd: String, callBack: (Boolean) -> Unit) {
|
|
|
+ if (account.isEmpty()) {
|
|
|
+ ToastUtils.tip(context.getString(R.string.please_input_account))
|
|
|
+ return
|
|
|
+ } else if (account.isEmpty()) {
|
|
|
+ ToastUtils.tip(context.getString(R.string.please_input_password))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ NetApi.login(account, pwd) {
|
|
|
+ callBack.invoke(it!!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun registerListener() {
|
|
|
+ BusinessManager.registerStatusListener(this) { dockBean ->
|
|
|
+ dockBean.deviceList.forEach { deviceBean ->
|
|
|
+ if (!deviceBean.isExist) {
|
|
|
+ return@forEach
|
|
|
+ }
|
|
|
+ when (deviceBean.type) {
|
|
|
+ DEVICE_TYPE_CARD -> {
|
|
|
+ ModBusController.readPortalCaseCardRfid(dockBean.addr.toInt() - 1) { res ->
|
|
|
+ if (res.size >= 11) {
|
|
|
+ val rfid = res.copyOfRange(3, 11).toHexStrings(false).removeLeadingZeros()
|
|
|
+ println("卡片RFID : $rfid")
|
|
|
+ // TODO 跳转页面处理
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DEVICE_TYPE_KEY -> {
|
|
|
+ // TODO 是否处理工作票
|
|
|
+// Executor.runOnMain {
|
|
|
+// BusinessManager.getTicketStatusBusiness(
|
|
|
+// PresentationManager.keyMac,
|
|
|
+// this
|
|
|
+// ) { b, s ->
|
|
|
+// (mvpView as BaseActivity<*>).handleLoading(b, s)
|
|
|
+// if (!s.isNullOrEmpty() && s.startsWith("工作票完成接收")) {
|
|
|
+// val ticket = s.substring(7)
|
|
|
+// val ticketStatusBean = Gson().fromJson(
|
|
|
+// ticket,
|
|
|
+// WorkTicketStatusBean::class.java
|
|
|
+// )
|
|
|
+// PresentationManager.updateWorkTicket(ticketStatusBean)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ DEVICE_TYPE_LOCK -> {
|
|
|
+ // TODO 是否处理
|
|
|
+// Executor.runOnMain {
|
|
|
+// ModBusController.readLockRfid(
|
|
|
+// dockBean.addr.toInt() - 1,
|
|
|
+// deviceBean.idx
|
|
|
+// ) { res ->
|
|
|
+// val rfid = res.copyOfRange(3, 11).toHexStrings(false)
|
|
|
+// .removeLeadingZeros()
|
|
|
+// PresentationManager.updateLockReturnStatus(rfid)
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fun unregisterListener() {
|
|
|
+ ModBusController.unregisterListener(this)
|
|
|
+ }
|
|
|
+}
|