Browse Source

临时提交

Frankensteinly 8 months ago
parent
commit
b5eef73339

+ 41 - 12
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -38,9 +38,11 @@ import com.grkj.iscs.model.bo.WorkTicketGetBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
 import com.grkj.iscs.model.eventmsg.DeviceTakeUpdateMsg
 import com.grkj.iscs.model.eventmsg.DeviceTakeUpdateMsg
+import com.grkj.iscs.model.eventmsg.GetTicketStatusMsg
 import com.grkj.iscs.model.eventmsg.LoadingMsg
 import com.grkj.iscs.model.eventmsg.LoadingMsg
 import com.grkj.iscs.model.eventmsg.MsgEvent
 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_DEVICE_TAKE_UPDATE
+import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_GET_TICKET_STATUS
 import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
 import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_LOADING
 import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
 import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
 import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
 import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
@@ -94,7 +96,7 @@ object BusinessManager {
         }
         }
 
 
     // 设备待取列表(需要报给后台的列表,等实际取完再上报)
     // 设备待取列表(需要报给后台的列表,等实际取完再上报)
-    private val mDeviceTakeList = mutableListOf<DeviceTakeUpdateBO>()
+    val mDeviceTakeList = mutableListOf<DeviceTakeUpdateBO>()
 
 
     /**
     /**
      * 初始化消息总线
      * 初始化消息总线
@@ -180,6 +182,7 @@ object BusinessManager {
 //                                            showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr.toInt())
 //                                            showKeyReturnDialog(it.macAddress, isLeft, dockBean.addr.toInt())
 //                                            registerConnectListener(it.macAddress)
 //                                            registerConnectListener(it.macAddress)
                                         } else {
                                         } else {
+                                            LogUtil.e("Get key info fail : $rfid")
                                             ToastUtils.tip(R.string.get_key_info_fail)
                                             ToastUtils.tip(R.string.get_key_info_fail)
                                         }
                                         }
                                     }
                                     }
@@ -372,6 +375,7 @@ object BusinessManager {
     fun checkEquipCount(needLockCount: Int, isNeedKey: Boolean, callBack: (Pair<Byte, DockBean.KeyBean?>?, MutableMap<Byte, MutableList<DockBean.LockBean>>) -> Unit) {
     fun checkEquipCount(needLockCount: Int, isNeedKey: Boolean, callBack: (Pair<Byte, DockBean.KeyBean?>?, MutableMap<Byte, MutableList<DockBean.LockBean>>) -> Unit) {
         var lockCount = 0
         var lockCount = 0
         val lockMap = ModBusController.getLocks(needLockCount)
         val lockMap = ModBusController.getLocks(needLockCount)
+        LogUtil.i("checkEquipCount : $lockMap")
         lockMap.forEach { (_, rfidList) ->
         lockMap.forEach { (_, rfidList) ->
             lockCount += rfidList.size
             lockCount += rfidList.size
         }
         }
@@ -734,7 +738,7 @@ object BusinessManager {
         registerConnectListener(mac) { isDone, bleBean ->
         registerConnectListener(mac) { isDone, bleBean ->
             if (isDone) {
             if (isDone) {
                 Executor.delayOnMain(500) {
                 Executor.delayOnMain(500) {
-                    getTicketStatus(bleBean!!.bleDevice, isNeedLoading)
+                    getTicketStatusWithRetry(bleBean!!.bleDevice, isNeedLoading)
                 }
                 }
             } else {
             } else {
                 if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
                 if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, false)))
@@ -742,6 +746,30 @@ object BusinessManager {
         }
         }
     }
     }
 
 
+    private fun getTicketStatusWithRetry(
+        bleDevice: BleDevice,
+        isNeedLoading: Boolean = false,
+        maxRetries: Int = 3,
+        delayMillis: Long = 500
+    ) {
+        var retryCount = 0
+
+        fun attemptSend() {
+            getTicketStatus(bleDevice, isNeedLoading) { sendRst ->
+                if (!sendRst && retryCount < maxRetries) {
+                    retryCount++
+                    // 等待一段时间后再次尝试
+                    Executor.delayOnMain(delayMillis) {
+                        LogUtil.i("Retry attempt, mac : ${bleDevice.mac}, retryCount : $retryCount")
+                        attemptSend()
+                    }
+                }
+            }
+        }
+
+        attemptSend()
+    }
+
     private fun sendTicket(jsonStr: String, bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
     private fun sendTicket(jsonStr: String, bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
         if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始下发工作票...", null)))
         if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始下发工作票...", null)))
         BleCmdManager.sendWorkTicket(jsonStr, bleDevice = bleDevice, callback = object : CustomBleWriteCallback() {
         BleCmdManager.sendWorkTicket(jsonStr, bleDevice = bleDevice, callback = object : CustomBleWriteCallback() {
@@ -953,12 +981,12 @@ object BusinessManager {
                 }
                 }
 
 
                 // 上报点位钥匙绑定
                 // 上报点位钥匙绑定
-                NetApi.updateLockPointBatch(updateList) { itRst ->
-                    // TODO 上报结果
+                NetApi.updateLockPointBatch(updateList) { isSuccess ->
+
                 }
                 }
 
 
                 // 上报钥匙归还
                 // 上报钥匙归还
-                NetApi.updateKeyReturn(data.taskId?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()) {
+                NetApi.updateKeyReturn(data.taskId?.toLong()!!, keyNfc!!, MyApplication.instance!!.serialNo()) { isSuccess ->
 
 
                 }
                 }
             }
             }
@@ -968,7 +996,7 @@ object BusinessManager {
     /**
     /**
      * 获取工作票完成情况
      * 获取工作票完成情况
      */
      */
-    private fun getTicketStatus(bleDevice: BleDevice, isNeedLoading: Boolean = false) {
+    private fun getTicketStatus(bleDevice: BleDevice, isNeedLoading: Boolean = false, processCallback: ((Boolean) -> Unit)? = null) {
         if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始获取工作票", null)))
         if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(true, "开始获取工作票", null)))
         BleCmdManager.getTicketStatus(bleDevice, object : CustomBleWriteCallback() {
         BleCmdManager.getTicketStatus(bleDevice, object : CustomBleWriteCallback() {
             override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
             override fun onWriteSuccess(current: Int, total: Int, justWrite: ByteArray?) {
@@ -976,6 +1004,7 @@ object BusinessManager {
                 println("getTicketStatus success")}
                 println("getTicketStatus success")}
             override fun onWriteFailure(exception: BleException?) {
             override fun onWriteFailure(exception: BleException?) {
                 if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取失败", false)))
                 if (isNeedLoading) mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, "工作票获取失败", false)))
+                processCallback?.invoke(false)
                 println("getTicketStatus fail")}
                 println("getTicketStatus fail")}
         })
         })
     }
     }
@@ -986,7 +1015,7 @@ object BusinessManager {
     fun addDeviceTake(deviceType: Int, ticketId: Long, nfc: String?) {
     fun addDeviceTake(deviceType: Int, ticketId: Long, nfc: String?) {
         LogUtil.i("$deviceType - $ticketId - $nfc")
         LogUtil.i("$deviceType - $ticketId - $nfc")
         mDeviceTakeList.removeIf { it.deviceType == deviceType && it.nfc == nfc }
         mDeviceTakeList.removeIf { it.deviceType == deviceType && it.nfc == nfc }
-        mDeviceTakeList.add(DeviceTakeUpdateBO(deviceType, ticketId, nfc))
+        mDeviceTakeList.add(DeviceTakeUpdateBO(deviceType, ticketId, nfc!!))
     }
     }
 
 
     private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg) {
     private fun handleDeviceTake(deviceTakeUpdateBO: DeviceTakeUpdateMsg) {
@@ -994,20 +1023,20 @@ object BusinessManager {
         when (deviceTakeUpdateBO.deviceType) {
         when (deviceTakeUpdateBO.deviceType) {
             // 钥匙
             // 钥匙
             0 -> {
             0 -> {
-                mDeviceTakeList.find { it.deviceType == 0 && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
-                    NetApi.updateKeyTake(info.ticketId, info.nfc!!, MyApplication.instance?.serialNo()!!) { isSuccess ->
+                mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
+                    NetApi.updateKeyTake(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!) { isSuccess ->
                         if (isSuccess) {
                         if (isSuccess) {
-                            mDeviceTakeList.removeIf { it.deviceType == 0 && it.nfc == info.nfc }
+                            mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_KEY && it.nfc == info.nfc }
                         }
                         }
                     }
                     }
                 }
                 }
             }
             }
             // 挂锁
             // 挂锁
             1 -> {
             1 -> {
-                mDeviceTakeList.find { it.deviceType == 1 && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
+                mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_LOCK && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
                     NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
                     NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
                         if (isSuccess == true) {
                         if (isSuccess == true) {
-                            mDeviceTakeList.removeIf { it.deviceType == 1 && it.nfc == info.nfc }
+                            mDeviceTakeList.removeIf { it.deviceType == DEVICE_TYPE_LOCK && it.nfc == info.nfc }
                         }
                         }
                     }
                     }
                 }
                 }

+ 6 - 0
app/src/main/java/com/grkj/iscs/ble/BleCmdManager.kt

@@ -3,6 +3,7 @@ package com.grkj.iscs.ble
 import com.clj.fastble.data.BleDevice
 import com.clj.fastble.data.BleDevice
 import com.clj.fastble.exception.BleException
 import com.clj.fastble.exception.BleException
 import com.grkj.iscs.BusinessManager
 import com.grkj.iscs.BusinessManager
+import com.grkj.iscs.BusinessManager.mEventBus
 import com.grkj.iscs.ble.BleConst.REQ_CURRENT_STATUS
 import com.grkj.iscs.ble.BleConst.REQ_CURRENT_STATUS
 import com.grkj.iscs.ble.BleConst.REQ_GET_TOKEN
 import com.grkj.iscs.ble.BleConst.REQ_GET_TOKEN
 import com.grkj.iscs.ble.BleConst.REQ_GET_VERSION
 import com.grkj.iscs.ble.BleConst.REQ_GET_VERSION
@@ -17,6 +18,9 @@ import com.grkj.iscs.extentions.crc16
 import com.grkj.iscs.extentions.startsWith
 import com.grkj.iscs.extentions.startsWith
 import com.grkj.iscs.extentions.toByteArray
 import com.grkj.iscs.extentions.toByteArray
 import com.grkj.iscs.extentions.toHexStrings
 import com.grkj.iscs.extentions.toHexStrings
+import com.grkj.iscs.model.eventmsg.GetTicketStatusMsg
+import com.grkj.iscs.model.eventmsg.MsgEvent
+import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_GET_TICKET_STATUS
 import com.grkj.iscs.util.Executor
 import com.grkj.iscs.util.Executor
 import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.util.log.LogUtil
 import java.io.File
 import java.io.File
@@ -192,6 +196,7 @@ object BleCmdManager {
             0x0E.toByte() -> LogUtil.i("Work ticket send data crc error")
             0x0E.toByte() -> LogUtil.i("Work ticket send data crc error")
             0x14.toByte() -> LogUtil.i("Work ticket send json error")
             0x14.toByte() -> LogUtil.i("Work ticket send json error")
         }
         }
+        LogUtil.i("idx : $idx : $total : $res")
         if (idx != total - 1) {
         if (idx != total - 1) {
             if (res == 0x00.toByte() || res == 0x02.toByte()) {
             if (res == 0x00.toByte() || res == 0x02.toByte()) {
                 // TODO 要判断res
                 // TODO 要判断res
@@ -280,6 +285,7 @@ object BleCmdManager {
 
 
                 override fun onWriteFailure(exception: BleException?) {
                 override fun onWriteFailure(exception: BleException?) {
                     println("getTicketStatusPart fail")
                     println("getTicketStatusPart fail")
+                    mEventBus.postValue(MsgEvent(MSG_EVENT_GET_TICKET_STATUS, GetTicketStatusMsg(false, bleDevice)))
                 }
                 }
             })
             })
         } else {
         } else {

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

@@ -6,6 +6,8 @@ import com.grkj.iscs.BusinessManager
 import com.grkj.iscs.R
 import com.grkj.iscs.R
 import com.grkj.iscs.extentions.removeLeadingZeros
 import com.grkj.iscs.extentions.removeLeadingZeros
 import com.grkj.iscs.extentions.toHexStrings
 import com.grkj.iscs.extentions.toHexStrings
+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_ELEC_LOCK_BOARD
 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_KEY
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
@@ -195,6 +197,7 @@ object ModBusController {
                         updateKeyRfid(dockBean.addr, isLeft, rfid)
                         updateKeyRfid(dockBean.addr, isLeft, rfid)
                         // 蓝牙准备操作
                         // 蓝牙准备操作
                         NetApi.getKeyInfo(rfid) {
                         NetApi.getKeyInfo(rfid) {
+                            println("getKeyInfo : $rfid - ${it?.macAddress}")
                             if (it != null && !it.macAddress.isNullOrEmpty()) {
                             if (it != null && !it.macAddress.isNullOrEmpty()) {
                                 // 更新mac
                                 // 更新mac
                                 updateKeyMac(dockBean.addr, key.isLeft, it.macAddress)
                                 updateKeyMac(dockBean.addr, key.isLeft, it.macAddress)
@@ -356,6 +359,25 @@ object ModBusController {
         dockList.find { it.addr == slaveAddress }?.getLockList()?.find { it.idx == lockIdx }?.rfid = rfid
         dockList.find { it.addr == slaveAddress }?.getLockList()?.find { it.idx == lockIdx }?.rfid = rfid
     }
     }
 
 
+    /**
+     * 设备是否存在,加入deviceType防止有重复的但是不同类型的
+     *
+     * @param deviceType {@link [com.grkj.iscs.model.bo.DeviceTakeUpdateBO]<class>#[deviceType]}
+     */
+    fun isDeviceExist(rfid: String, deviceType: Int) : Boolean {
+        return when (deviceType) {
+            DEVICE_TYPE_KEY -> {
+                dockList.find { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }?.getKeyList()?.find { it.rfid == rfid } != null
+            }
+            DEVICE_TYPE_LOCK -> {
+                dockList.find { it.type == DOCK_TYPE_LOCK || it.type == DOCK_TYPE_PORTABLE  }?.getLockList()?.find { it.rfid == rfid } != null
+            }
+            else -> {
+                false
+            }
+        }
+    }
+
     /**
     /**
      * 操作钥匙灯
      * 操作钥匙灯
      *
      *
@@ -496,11 +518,15 @@ object ModBusController {
     fun getOneKey(): Pair<Byte, DockBean.KeyBean?>? {
     fun getOneKey(): Pair<Byte, DockBean.KeyBean?>? {
         val keyDockList = dockList.filter { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }
         val keyDockList = dockList.filter { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }
         val keyList = keyDockList.flatMap { it.getKeyList() }.filter { it.isExist }
         val keyList = keyDockList.flatMap { it.getKeyList() }.filter { it.isExist }
+        LogUtil.i("keyList : $keyList")
         if (keyList.isEmpty()) {
         if (keyList.isEmpty()) {
             ToastUtils.tip(R.string.key_is_not_enough)
             ToastUtils.tip(R.string.key_is_not_enough)
             return null
             return null
         }
         }
 
 
+        keyList.forEach {
+            LogUtil.i("keyStatus : ${it.isExist} - ${it.rfid} - ${it.mac} - ${BusinessManager.getBleDeviceByMac(it.mac!!)?.bleDevice} - ${BleManager.getInstance().isConnected(BusinessManager.getBleDeviceByMac(it.mac!!)?.bleDevice)}")
+        }
         val key = keyList.find { it.isExist && it.rfid != null && it.mac != null &&
         val key = keyList.find { it.isExist && it.rfid != null && it.mac != null &&
                 BleManager.getInstance().isConnected(BusinessManager.getBleDeviceByMac(it.mac!!)?.bleDevice) }
                 BleManager.getInstance().isConnected(BusinessManager.getBleDeviceByMac(it.mac!!)?.bleDevice) }
         if (key == null) {
         if (key == null) {

+ 5 - 2
app/src/main/java/com/grkj/iscs/model/bo/DeviceTakeUpdateBO.kt

@@ -1,7 +1,10 @@
 package com.grkj.iscs.model.bo
 package com.grkj.iscs.model.bo
 
 
+/**
+ * @param deviceType {@link [com.grkj.iscs.model.bo.DeviceTakeUpdateBO]<class>#[deviceType]}
+ */
 data class DeviceTakeUpdateBO(
 data class DeviceTakeUpdateBO(
-    val deviceType: Int,    // 0:钥匙 1:挂锁
+    val deviceType: Int,    // DeviceConst.DEVICE_TYPE_KEY or DeviceConst.DEVICE_TYPE_LOCK
     val ticketId: Long,
     val ticketId: Long,
-    val nfc: String?
+    val nfc: String
 )
 )

+ 8 - 0
app/src/main/java/com/grkj/iscs/model/eventmsg/GetTicketStatusMsg.kt

@@ -0,0 +1,8 @@
+package com.grkj.iscs.model.eventmsg
+
+import com.clj.fastble.data.BleDevice
+
+data class GetTicketStatusMsg(
+    val isSuccess: Boolean,
+    val bleDevice: BleDevice
+)

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

@@ -7,4 +7,7 @@ object MsgEventConstants {
     
     
     // ------------------------------ 设备 1-002-000 ------------------------------
     // ------------------------------ 设备 1-002-000 ------------------------------
     const val MSG_EVENT_DEVICE_TAKE_UPDATE = 1_002_000  // 设备取出
     const val MSG_EVENT_DEVICE_TAKE_UPDATE = 1_002_000  // 设备取出
+
+    // ------------------------------ 作业票 1-003-000 ------------------------------
+    const val MSG_EVENT_GET_TICKET_STATUS = 1_003_000   // 获取设备工作票完成情况
 }
 }

+ 25 - 4
app/src/main/java/com/grkj/iscs/util/NetApi.kt

@@ -372,6 +372,7 @@ object NetApi {
      * 取出挂锁时更新数据
      * 取出挂锁时更新数据
      */
      */
     fun updateLockTake(list: MutableList<LockTakeUpdateReqVO>, callBack: (Boolean?) -> Unit) {
     fun updateLockTake(list: MutableList<LockTakeUpdateReqVO>, callBack: (Boolean?) -> Unit) {
+        println("updateLockTake : $list")
         NetHttpManager.getInstance().doRequestNet(
         NetHttpManager.getInstance().doRequestNet(
             UrlConsts.LOCK_TAKE_UPDATE,
             UrlConsts.LOCK_TAKE_UPDATE,
             false,
             false,
@@ -444,7 +445,7 @@ object NetApi {
     /**
     /**
      * 归还钥匙
      * 归还钥匙
      */
      */
-    fun updateKeyReturn(ticketId: Long, keyNfc: String, serialNumber: String, callBack: (Boolean) -> Unit) {
+    fun updateKeyReturn(ticketId: Long, keyNfc: String, serialNumber: String, retryCount: Int = 3, callBack: (Boolean) -> Unit) {
         NetHttpManager.getInstance().doRequestNet(
         NetHttpManager.getInstance().doRequestNet(
             UrlConsts.KEY_RETURN_UPDATE,
             UrlConsts.KEY_RETURN_UPDATE,
             false,
             false,
@@ -454,7 +455,17 @@ object NetApi {
                 "serialNumber" to serialNumber
                 "serialNumber" to serialNumber
             ),
             ),
             { res, _, _ ->
             { res, _, _ ->
-                callBack.invoke(res != null)
+                res?.let {
+                    callBack(true)
+                } ?: let {
+                    if (retryCount > 0) {
+                        Executor.delayOnIO(500) {
+                            updateKeyReturn(ticketId, keyNfc, serialNumber, retryCount - 1, callBack)
+                        }
+                    } else {
+                        callBack.invoke(false)
+                    }
+                }
                 // TODO isAuth需要配置
                 // TODO isAuth需要配置
             }, isGet = false, isAuth = BusinessManager.NEED_AUTH
             }, isGet = false, isAuth = BusinessManager.NEED_AUTH
         )
         )
@@ -480,7 +491,7 @@ object NetApi {
     /**
     /**
      * 批量更新作业票下隔离点的上锁解锁状况
      * 批量更新作业票下隔离点的上锁解锁状况
      */
      */
-    fun updateLockPointBatch(list: MutableList<LockPointUpdateReqVO>, callBack: (Boolean) -> Unit) {
+    fun updateLockPointBatch(list: MutableList<LockPointUpdateReqVO>, retryCount: Int = 3, callBack: (Boolean) -> Unit) {
         NetHttpManager.getInstance().doRequestNet(
         NetHttpManager.getInstance().doRequestNet(
             UrlConsts.LOCK_POINT_UPDATE_BATCH,
             UrlConsts.LOCK_POINT_UPDATE_BATCH,
             false,
             false,
@@ -488,7 +499,17 @@ object NetApi {
                 "list" to list
                 "list" to list
             ),
             ),
             { res, _, _ ->
             { res, _, _ ->
-                callBack.invoke(res != null)
+                res?.let {
+                    callBack(true)
+                } ?: let {
+                    if (retryCount > 0) {
+                        Executor.delayOnIO(500) {
+                            updateLockPointBatch(list, retryCount - 1, callBack)
+                        }
+                    } else {
+                        callBack.invoke(false)
+                    }
+                }
             }, isGet = false, isAuth =true
             }, isGet = false, isAuth =true
         )
         )
     }
     }

+ 9 - 28
app/src/main/java/com/grkj/iscs/view/presenter/HomePresenter.kt

@@ -20,16 +20,14 @@ class HomePresenter : BasePresenter<IHomeView>() {
         BusinessManager.registerStatusListener(this) { dockBean ->
         BusinessManager.registerStatusListener(this) { dockBean ->
             when (dockBean.type) {
             when (dockBean.type) {
                 DOCK_TYPE_KEY -> {
                 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)
-                                    }
+                    dockBean.getKeyList().forEach { keyBean ->
+                        if (keyBean.isExist) {
+                            Executor.repeatOnMain({
+                                keyBean.mac?.let {
+                                    getTicketNew(it, 3)
                                 }
                                 }
-                            }
+                                return@repeatOnMain keyBean.mac == null
+                            }, 1000, true)
                         }
                         }
                     }
                     }
                 }
                 }
@@ -37,25 +35,8 @@ class HomePresenter : BasePresenter<IHomeView>() {
         }
         }
     }
     }
 
 
-    private fun getTicket(dockBean: DockBean, isLeft: Boolean, retryCount: Int) {
-        if (retryCount == 0) {
-            return
-        }
-        ModBusController.readKeyRfid(dockBean.addr, if (isLeft) 0 else 1) { isLeft, res ->
-            if (res.size < 11) {
-                LogUtil.e("Key rfid error")
-                return@readKeyRfid
-            }
-            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!!, true)
-        }
+    private fun getTicketNew(mac: String, retryCount: Int) {
+        BusinessManager.getTicketStatusBusiness(mac, true)
     }
     }
 
 
     fun unregisterListener() {
     fun unregisterListener() {

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

@@ -8,6 +8,8 @@ import com.grkj.iscs.model.Constants.JOB_STATUS_ACQUIRE_KEY
 import com.grkj.iscs.model.Constants.JOB_STATUS_ACQUIRE_LOCK
 import com.grkj.iscs.model.Constants.JOB_STATUS_ACQUIRE_LOCK
 import com.grkj.iscs.model.Constants.JOB_STATUS_NOT_STARTED
 import com.grkj.iscs.model.Constants.JOB_STATUS_NOT_STARTED
 import com.grkj.iscs.model.Constants.USER_TYPE_LOCKER
 import com.grkj.iscs.model.Constants.USER_TYPE_LOCKER
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
+import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_LOCK
 import com.grkj.iscs.model.vo.card.CardInfoRespVO
 import com.grkj.iscs.model.vo.card.CardInfoRespVO
 import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
 import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
 import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
 import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
@@ -70,6 +72,16 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
             }
             }
         }
         }
     }
     }
+
+    /**
+     * 检查是否可以继续执行后续操作(例:点击后不拿设备或者无法拿设备,又再次点击按钮)
+     *
+     * @return 0:可以继续
+     */
+//    fun checkCanProcess(ticketId: Long): Int {
+//        val takeList = BusinessManager.mDeviceTakeList.filter { it.ticketId == ticketId }
+
+//    }
     
     
     /**
     /**
      * 上锁人上锁流程
      * 上锁人上锁流程
@@ -86,6 +98,7 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
             // 3个状态全检查锁和钥匙分配情况,防止第一次拿了钥匙和部分锁
             // 3个状态全检查锁和钥匙分配情况,防止第一次拿了钥匙和部分锁
             if (role.jobStatus == JOB_STATUS_NOT_STARTED || role.jobStatus == JOB_STATUS_ACQUIRE_LOCK || role.jobStatus == JOB_STATUS_ACQUIRE_KEY) {
             if (role.jobStatus == JOB_STATUS_NOT_STARTED || role.jobStatus == JOB_STATUS_ACQUIRE_LOCK || role.jobStatus == JOB_STATUS_ACQUIRE_KEY) {
                 NetApi.getTicketEquipDetail(ticketId) { equipDetail ->
                 NetApi.getTicketEquipDetail(ticketId) { equipDetail ->
+                    println("EquipDetail : $equipDetail")
                     // 取锁具、取钥匙
                     // 取锁具、取钥匙
                     val needLockCount = equipDetail?.ticketLockVOList?.filter { it.lockId == null }?.size ?: 0
                     val needLockCount = equipDetail?.ticketLockVOList?.filter { it.lockId == null }?.size ?: 0
                     val isNeedKey = equipDetail?.ticketKeyVOList?.filter { it.keyId == null }?.size != 1
                     val isNeedKey = equipDetail?.ticketKeyVOList?.filter { it.keyId == null }?.size != 1
@@ -96,12 +109,12 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                             // 开锁卡扣
                             // 开锁卡扣
                             ModBusController.controlLockBuckle(true, addr, mLockList.map { it.idx }.toMutableList())
                             ModBusController.controlLockBuckle(true, addr, mLockList.map { it.idx }.toMutableList())
                             mLockList.forEach { itLock ->
                             mLockList.forEach { itLock ->
-                                BusinessManager.addDeviceTake(1, ticketId, itLock.rfid)
+                                BusinessManager.addDeviceTake(DEVICE_TYPE_LOCK, ticketId, itLock.rfid)
                             }
                             }
                         }
                         }
                         // null表示锁具数量不够,不给钥匙
                         // null表示锁具数量不够,不给钥匙
                         if (keyPair != null) {
                         if (keyPair != null) {
-                            BusinessManager.addDeviceTake(0, ticketId, keyPair.second?.rfid!!)
+                            BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
                             LogUtil.i("工作票挂锁list : $lockList")
                             LogUtil.i("工作票挂锁list : $lockList")
                             // 下发工作票
                             // 下发工作票
                             BusinessManager.sendTicketBusiness(
                             BusinessManager.sendTicketBusiness(
@@ -131,7 +144,7 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
             BusinessManager.checkEquipCount(0, true) { keyPair, _ ->
             BusinessManager.checkEquipCount(0, true) { keyPair, _ ->
                 // null表示锁具数量不够,不给钥匙
                 // null表示锁具数量不够,不给钥匙
                 if (keyPair != null) {
                 if (keyPair != null) {
-                    BusinessManager.addDeviceTake(0, ticketId, keyPair.second?.rfid!!)
+                    BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
                     // 下发工作票
                     // 下发工作票
                     BusinessManager.sendTicketBusiness(
                     BusinessManager.sendTicketBusiness(
                         keyPair.second?.mac!!,
                         keyPair.second?.mac!!,