Browse Source

补充日志打印;切换工作模式使用蓝牙监听回调后的总线消息,发送指令失败一直重试;初始化和放回钥匙的时候的getCurrentStatus延迟执行;共锁刷卡时检查当前八大步骤进度,防止在其他步骤刷卡导致异常

Frankensteinly 8 tháng trước cách đây
mục cha
commit
776b82e352

+ 32 - 23
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -127,15 +127,39 @@ object BusinessManager {
                     when ((it.data as SwitchModeMsg).job) {
                         // 工作模式
                         1 -> {
-
+                            if (it.data.res == 1) {
+                                // 只能在这里断开,不能全部断开
+                                BleManager.getInstance().disconnect(it.data.bleBean.bleDevice)
+
+                                // 打开钥匙卡扣
+                                val keyBean = ModBusController.getKeyByMac(it.data.bleBean.bleDevice.mac)
+                                if (keyBean == null) {
+                                    mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
+                                    ToastUtils.tip(R.string.key_not_exists)
+                                } else {
+                                    mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
+                                    val dock = ModBusController.getDockByKeyMac(it.data.bleBean.bleDevice.mac)
+                                    ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
+                                }
+                                // 强制结束Loading防止有loading仍在显示
+                                Executor.delayOnMain(500) {
+                                    mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
+                                }
+                            } else {
+                                LogUtil.e("切换工作模式失败 : ${it.data.bleBean.bleDevice.mac}")
+                                // TODO 切换工作模式失败
+                            }
                         }
                         // 待机模式
                         2 -> {
                             if (it.data.res == 1) {
                                 // 延时再次获取当前状态,触发handleCurrentMode里工作票下发状态检查
                                 Executor.delayOnMain(500) {
-                                    getCurrentStatus(it.data.bleBean.bleDevice)
+                                    getCurrentStatus(1, it.data.bleBean.bleDevice)
                                 }
+                            } else {
+                                LogUtil.e("切换待机模式失败 : ${it.data.bleBean.bleDevice.mac}")
+                                // TODO 切换待机模式失败
                             }
                         }
                     }
@@ -221,7 +245,7 @@ object BusinessManager {
                                 keyBean.mac?.let {
                                     unregisterConnectListener(it)
                                 }
-                                mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(0, keyBean.rfid)))
+                                mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_KEY, keyBean.rfid)))
                             }
                         }
                     }
@@ -248,7 +272,7 @@ object BusinessManager {
                                     }
                                 }
                             } else {
-                                mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(1, lockBean.rfid)))
+                                mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(DEVICE_TYPE_LOCK, lockBean.rfid)))
                             }
                         }
                     }
@@ -954,8 +978,8 @@ object BusinessManager {
         }
     }
 
-    fun getCurrentStatus(bleDevice: BleDevice) {
-        LogUtil.i("getCurrentStatus - ${bleDevice.mac}")
+    fun getCurrentStatus(from: Int, bleDevice: BleDevice) {
+        LogUtil.i("getCurrentStatus - ${bleDevice.mac} - from : $from")
         BleCmdManager.getCurrentStatus(bleDevice, object : CustomBleWriteCallback() {
             override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
                 LogUtil.i("getCurrentStatus success : ${bleDevice.mac}")
@@ -964,7 +988,7 @@ object BusinessManager {
             override fun onWriteFailure(exception: BleException?) {
                 LogUtil.i("getCurrentStatus fail : ${bleDevice.mac}")
                 Executor.delayOnMain(500) {
-                    getCurrentStatus(bleDevice)
+                    getCurrentStatus(from, bleDevice)
                 }
             }
         })
@@ -975,21 +999,6 @@ object BusinessManager {
         BleCmdManager.switchMode(STATUS_WORK, bleDevice, object : CustomBleWriteCallback() {
             override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
                 LogUtil.i("switch mode work success : ${bleDevice.mac}")
-                // 只能在这里断开,不能全部断开
-                BleManager.getInstance().disconnect(bleDevice)
-
-                // 打开钥匙卡扣
-                val keyBean = ModBusController.getKeyByMac(bleDevice.mac)
-                if (keyBean == null) {
-                    if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "未找到钥匙信息", false)))
-                    ToastUtils.tip(R.string.key_not_exists)
-                } else {
-                    if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
-                    val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
-                    ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
-                }
-                // 强制结束Loading防止有loading仍在显示
-                mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
             }
             override fun onWriteFailure(exception: BleException?) {
                 LogUtil.e("switch mode work fail : ${exception?.code} - ${exception?.description}")
@@ -1119,7 +1128,7 @@ object BusinessManager {
                             }
                             // 检查有无当前工作票的钥匙
                             mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == info.ticketId }?.let { itKey ->
-                                getCurrentStatus(getBleDeviceByMac(ModBusController.getKeyByRfid(itKey.nfc)?.mac)!!.bleDevice)
+                                getCurrentStatus(2, getBleDeviceByMac(ModBusController.getKeyByRfid(itKey.nfc)?.mac)!!.bleDevice)
                             }
                         }
                     }

+ 3 - 3
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -202,9 +202,9 @@ object ModBusController {
                                 // 更新mac
                                 updateKeyMac(dockBean.addr, key.isLeft, it.macAddress)
                                 BusinessManager.registerConnectListener(it.macAddress) { isDone, bleBean ->
-                                    Executor.delayOnMain(500) {
-                                        bleBean?.let {
-                                            BusinessManager.getCurrentStatus(bleBean.bleDevice)
+                                    bleBean?.bleDevice?.let { itDevice ->
+                                        Executor.delayOnMain(500) {
+                                            BusinessManager.getCurrentStatus(3, itDevice)
                                         }
                                     }
                                 }

+ 2 - 0
app/src/main/java/com/grkj/iscs/view/activity/HomeActivity.kt

@@ -15,6 +15,7 @@ import com.grkj.iscs.model.Constants.USER_ROLE_DRAWER
 import com.grkj.iscs.model.Constants.USER_ROLE_GUARD
 import com.grkj.iscs.model.Constants.USER_ROLE_LOCKER
 import com.grkj.iscs.model.vo.user.UserInfoRespVO
+import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.adapter.MenuAdapter
 import com.grkj.iscs.view.base.BaseFragment
 import com.grkj.iscs.view.base.BaseMvpActivity
@@ -96,6 +97,7 @@ class HomeActivity : BaseMvpActivity<IHomeView, HomePresenter, ActivityHomeBindi
             // 检测到回车开始处理
             if (event.keyCode == 66) {
                 cardNo = cardNo.toLong().toByteArrays().toHexStrings(false)
+                LogUtil.i("Swipe card home: $cardNo")
                 cardNoLiveData.postValue(cardNo)
                 // 重置cardNo
                 cardNo = ""

+ 2 - 0
app/src/main/java/com/grkj/iscs/view/activity/LoginActivity.kt

@@ -7,6 +7,7 @@ import com.grkj.iscs.R
 import com.grkj.iscs.databinding.ActivityLoginBinding
 import com.grkj.iscs.modbus.ModBusController
 import com.grkj.iscs.util.AppUtils
+import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BaseMvpActivity
 import com.grkj.iscs.view.dialog.LoginDialog
 import com.grkj.iscs.view.iview.ILoginView
@@ -57,6 +58,7 @@ class LoginActivity : BaseMvpActivity<ILoginView, LoginPresenter, ActivityLoginB
      */
     private fun showLoginDialog(loginType: Int) {
         cardLoginDialog ?: run {
+            LogUtil.i("创建Swipe dialog : ${presenter == null}")
             cardLoginDialog = LoginDialog(presenter, this) { isSuccess, cardInfoRespVO, userInfoRespVO ->
                 if (isSuccess) {
                     val intent = Intent(this, HomeActivity::class.java)

+ 2 - 0
app/src/main/java/com/grkj/iscs/view/dialog/LoginDialog.kt

@@ -11,6 +11,7 @@ import com.grkj.iscs.extentions.toHexStrings
 import com.grkj.iscs.model.vo.card.CardInfoRespVO
 import com.grkj.iscs.model.vo.user.UserInfoRespVO
 import com.grkj.iscs.util.Executor
+import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BaseDialog
 import com.grkj.iscs.view.presenter.LoginPresenter
 
@@ -77,6 +78,7 @@ class LoginDialog(val presenter: LoginPresenter?, val ctx: Context, private var
             // 检测到回车开始处理
             if (event.keyCode == 66) {
                 cardNo = cardNo.toLong().toByteArrays().toHexStrings(false)
+                LogUtil.i("Swipe card login: $cardNo")
                 presenter?.cardLogin(cardNo) { isSuccess, cardInfoRespVO, userInfoRespVO ->
                     if (isSuccess) {
                         dismiss()

+ 30 - 9
app/src/main/java/com/grkj/iscs/view/fragment/JobProgressFragment.kt

@@ -8,6 +8,7 @@ import com.grkj.iscs.databinding.FragmentJobProgressBinding
 import com.grkj.iscs.extentions.debounce
 import com.grkj.iscs.model.bo.PageChangeBO
 import com.grkj.iscs.model.vo.ticket.TicketDetailMonitorRespVO
+import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.view.base.BaseMvpFragment
 import com.grkj.iscs.view.dialog.TipDialog
 import com.grkj.iscs.view.iview.IJobProgressView
@@ -109,6 +110,21 @@ class JobProgressFragment(val goBack: () -> Unit) :
     }
 
     fun getCardNo(cardNo: String) {
+        presenter?.getStepDetail(mPageChangeBO?.ticketId!!) {
+            it?.filter { it.stepStatus == "1" }?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
+                mStep = it
+            }
+            if (mStep == 4) {
+                mBinding?.cbAction?.visibility = View.VISIBLE
+            } else if (mStep == 7) {
+                mBinding?.cbAction?.visibility = View.VISIBLE
+                mBinding?.cbAction?.setIcon(R.mipmap.ticket_unlocked)
+                mBinding?.cbAction?.setText(getString(R.string.go_unlocking))
+            } else {
+                mBinding?.cbAction?.visibility = View.GONE
+            }
+        }
+
         presenter?.getCardInfoByNfc(cardNo) {
             if (it == null) {
                 return@getCardInfoByNfc
@@ -120,17 +136,22 @@ class JobProgressFragment(val goBack: () -> Unit) :
             if (jobStatus == null || jobStatus >= 5) {
                 return@getCardInfoByNfc
             }
-            if (jobStatus < 4) {
-                mTipDialog?.setTip(getString(R.string.confirm_to_colock, cardNo))
-            } else {
-                mTipDialog?.setTip(getString(R.string.confirm_to_uncolock, cardNo))
-            }
-            mTipDialog?.setConfirmListener {
-                presenter?.updateColockerStatus(mPageChangeBO?.ticketId!!, cardNo, if (jobStatus < 4) "4" else "5") {
-                    refreshPage(mPageChangeBO!!)
+
+            if (mStep == 6) {
+                if (jobStatus < 4) {
+                    mTipDialog?.setTip(getString(R.string.confirm_to_colock, cardNo))
+                } else {
+                    mTipDialog?.setTip(getString(R.string.confirm_to_uncolock, cardNo))
                 }
+                mTipDialog?.setConfirmListener {
+                    presenter?.updateColockerStatus(mPageChangeBO?.ticketId!!, cardNo, if (jobStatus < 4) "4" else "5") {
+                        refreshPage(mPageChangeBO!!)
+                    }
+                }
+                mTipDialog?.showCancelCountdown(10)
+            } else {
+                ToastUtils.tip(R.string.can_not_do_colock_action)
             }
-            mTipDialog?.showCancelCountdown(10)
         }
     }
 

+ 3 - 1
app/src/main/java/com/grkj/iscs/view/presenter/HomePresenter.kt

@@ -18,7 +18,9 @@ class HomePresenter : BasePresenter<IHomeView>() {
                                 keyBean.mac?.let {
                                     BusinessManager.registerConnectListener(it) { isDone, bleBean ->
                                         if (isDone && bleBean != null) {
-                                            BusinessManager.getCurrentStatus(BusinessManager.getBleDeviceByMac(bleBean.bleDevice.mac)?.bleDevice!!)
+                                            Executor.delayOnMain(300) {
+                                                BusinessManager.getCurrentStatus(4, BusinessManager.getBleDeviceByMac(keyBean.mac)?.bleDevice!!)
+                                            }
                                         }
                                     }
                                 }

+ 1 - 1
app/src/main/java/com/grkj/iscs/view/presenter/JobProgressPresenter.kt

@@ -142,7 +142,7 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                 if (keyPair != null) {
                     BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
                     
-                    BusinessManager.getCurrentStatus(BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice)
+                    BusinessManager.getCurrentStatus(5, BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice)
                 }
             }
         }

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -204,6 +204,7 @@
     <string name="system_setting_tip">保存配置后App将自动重启,配置将在重启后生效</string>
     <string name="no_board_responses">没有主板响应</string>
     <string name="please_take_out_ready_device_first">请先取出已开卡扣的设备</string>
+    <string name="can_not_do_colock_action">当前无法进行共锁相关操作</string>
 
     <!-- 物资柜 -->
     <string name="material_management_system">物资管理系统</string>