Przeglądaj źródła

优化设备取出上报更新流程

Frankensteinly 8 miesięcy temu
rodzic
commit
6825bfc21f

+ 44 - 0
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -33,12 +33,16 @@ import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_ELEC_LOCK_BOARD
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
+import com.grkj.iscs.model.bo.DeviceTakeUpdateBO
 import com.grkj.iscs.model.bo.WorkTicketGetBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
+import com.grkj.iscs.model.eventmsg.DeviceTakeUpdateMsg
 import com.grkj.iscs.model.eventmsg.LoadingMsg
 import com.grkj.iscs.model.eventmsg.MsgEvent
+import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_TAKE_UPDATE
 import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
+import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
 import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
 import com.grkj.iscs.model.vo.ticket.TicketDetailRespVO
 import com.grkj.iscs.util.ActivityUtils
@@ -89,6 +93,9 @@ object BusinessManager {
             return (NEED_AUTH && loginUser != null) || !NEED_AUTH
         }
 
+    // 设备归还列表(需要报给后台的列表,等实际取完再上报)
+    val mDeviceTakeList = mutableListOf<DeviceTakeUpdateBO>()
+
     /**
      * 初始化消息总线
      */
@@ -101,6 +108,9 @@ object BusinessManager {
                         (ActivityUtils.currentActivity() as BaseActivity<*>).handleLoading(loadingMsg.isShow, loadingMsg.loadingText)
                     }
                 }
+                MSG_EVENT_DEVICE_TAKE_UPDATE -> {
+                    handleDeviceTake(it.data as DeviceTakeUpdateMsg)
+                }
             }
         }
     }
@@ -181,6 +191,7 @@ object BusinessManager {
                                 keyBean.mac?.let {
                                     unregisterConnectListener(it)
                                 }
+                                mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(0, keyBean.rfid)))
                             }
                         }
                     }
@@ -206,6 +217,8 @@ object BusinessManager {
                                         }
                                     }
                                 }
+                            } else {
+                                mEventBus.postValue(MsgEvent(MSG_EVENT_DEVICE_TAKE_UPDATE, DeviceTakeUpdateMsg(1, lockBean.rfid)))
                             }
                         }
                     }
@@ -963,4 +976,35 @@ object BusinessManager {
                 println("getTicketStatus fail")}
         })
     }
+
+    /**
+     * 添加待更新取出状态的设备
+     */
+    fun addDeviceTake(deviceType: Int, ticketId: Long, nfc: String?) {
+        mDeviceTakeList.removeIf { it.deviceType == deviceType && it.nfc == nfc }
+        mDeviceTakeList.add(DeviceTakeUpdateBO(deviceType, ticketId, nfc))
+    }
+
+    private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg) {
+        when (deviceTakeUpdateBO.deviceType) {
+            // 钥匙
+            0 -> {
+                val info = mDeviceTakeList.find { it.deviceType == 0 && it.nfc == deviceTakeUpdateBO.nfc }
+                NetApi.updateKeyTake(info?.ticketId!!, info.nfc!!, MyApplication.instance?.serialNo()!!) { isSuccess ->
+                    if (isSuccess) {
+                        mDeviceTakeList.removeIf { it.deviceType == 0 && it.nfc == info.nfc }
+                    }
+                }
+            }
+            // 挂锁
+            1 -> {
+                val info = mDeviceTakeList.find { it.deviceType == 1 && it.nfc == deviceTakeUpdateBO.nfc }
+                NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info?.ticketId, info?.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
+                    if (isSuccess == true) {
+                        mDeviceTakeList.removeIf { it.deviceType == 1 && it.nfc == info?.nfc }
+                    }
+                }
+            }
+        }
+    }
 }

+ 7 - 0
app/src/main/java/com/grkj/iscs/model/bo/DeviceTakeUpdateBO.kt

@@ -0,0 +1,7 @@
+package com.grkj.iscs.model.bo
+
+data class DeviceTakeUpdateBO(
+    val deviceType: Int,    // 0:钥匙 1:挂锁
+    val ticketId: Long,
+    val nfc: String?
+)

+ 6 - 0
app/src/main/java/com/grkj/iscs/model/eventmsg/DeviceTakeUpdateMsg.kt

@@ -0,0 +1,6 @@
+package com.grkj.iscs.model.eventmsg
+
+data class DeviceTakeUpdateMsg(
+    val deviceType: Int,    // 0:钥匙 1:挂锁
+    val nfc: String?
+)

+ 4 - 0
app/src/main/java/com/grkj/iscs/model/eventmsg/MsgEventConstants.kt

@@ -4,4 +4,8 @@ object MsgEventConstants {
 
     // ------------------------------ 通用 1-001-000 ------------------------------
     const val MSG_EVENT_LOADING = 1_001_000             // loading消息
+
+
+    // ------------------------------ 设备 1-002-000 ------------------------------
+    const val MSG_EVENT_DEVICE_TAKE_UPDATE = 1_002_000
 }

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

@@ -94,33 +94,26 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                         lockMap.forEach { (_, list) ->
                             lockList.addAll(list.map { LockTakeUpdateReqVO(ticketDetail.ticketId, it.rfid, mContext!!.serialNo()) })
                         }
-                        NetApi.updateLockTake(lockList) {
-                            if (it == true) {
-                                lockMap.forEach { (addr, lockList) ->
-                                    // 开锁卡扣
-                                    ModBusController.controlLockBuckle(true, addr, lockList.map { it.idx }.toMutableList())
-                                }
-                            }
-                            // 更新锁具信息后再发,防止后台失败
-                            // null表示锁具数量不够,不给钥匙
-                            if (keyPair != null) {
-                                // 更新钥匙信息
-                                NetApi.updateKeyTake(ticketDetail.ticketId!!, keyPair.second?.rfid!!, mContext!!.serialNo()) {
-                                    LogUtil.i("updateKeyTake : ${keyPair.second?.rfid}")
-                                    if (it) {
-                                        LogUtil.i("工作票挂锁list : $lockList")
-                                        // 下发工作票
-                                        BusinessManager.sendTicketBusiness(
-                                            keyPair.second?.mac!!,
-                                            ticketDetail,
-                                            lockList.map { it.lockNfc }.toMutableList(),
-                                            ActivityUtils.currentActivity() as BaseActivity<*>,
-                                            true
-                                        )
-                                    }
-                                }
+                        lockMap.forEach { (addr, lockList) ->
+                            // 开锁卡扣
+                            ModBusController.controlLockBuckle(true, addr, lockList.map { it.idx }.toMutableList())
+                            lockList.forEach { itLock ->
+                                BusinessManager.addDeviceTake(1, ticketId, itLock.rfid)
                             }
                         }
+                        // null表示锁具数量不够,不给钥匙
+                        if (keyPair != null) {
+                            BusinessManager.addDeviceTake(0, ticketId, keyPair.second?.rfid!!)
+                            LogUtil.i("工作票挂锁list : $lockList")
+                            // 下发工作票
+                            BusinessManager.sendTicketBusiness(
+                                keyPair.second?.mac!!,
+                                ticketDetail,
+                                lockList.map { it.lockNfc }.toMutableList(),
+                                ActivityUtils.currentActivity() as BaseActivity<*>,
+                                true
+                            )
+                        }
                     }
                 }
             }
@@ -140,19 +133,15 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
             BusinessManager.checkEquipCount(0, true) { keyPair, _ ->
                 // null表示锁具数量不够,不给钥匙
                 if (keyPair != null) {
-                    // 更新钥匙信息
-                    NetApi.updateKeyTake(ticketDetail.ticketId!!, keyPair.second?.rfid!!, mContext!!.serialNo()) {
-                        if (it) {
-                            // 下发工作票
-                            BusinessManager.sendTicketBusiness(
-                                keyPair.second?.mac!!,
-                                ticketDetail,
-                                null,
-                                ActivityUtils.currentActivity() as BaseActivity<*>,
-                                true
-                            )
-                        }
-                    }
+                    BusinessManager.addDeviceTake(0, ticketId, keyPair.second?.rfid!!)
+                    // 下发工作票
+                    BusinessManager.sendTicketBusiness(
+                        keyPair.second?.mac!!,
+                        ticketDetail,
+                        null,
+                        ActivityUtils.currentActivity() as BaseActivity<*>,
+                        true
+                    )
                 }
             }
         }