فهرست منبع

添加上锁前、解锁前检查

Frankensteinly 6 ماه پیش
والد
کامیت
e80e918349

+ 10 - 0
app/src/main/java/com/grkj/iscs/model/UrlConsts.kt

@@ -262,4 +262,14 @@ object UrlConsts {
      * 查询基础数据-分页
      */
     const val SYSTEM_ATTRIBUTE_PAGE = "/iscs/attribute/getIsSystemAttributePage"
+
+    /**
+     * 上锁取钥匙前检查
+     */
+    const val CHECK_BEFORE_LOCKING = "/iscs/hardware-api/checkBeforeToLock"
+
+    /**
+     * 解锁取钥匙前检查
+     */
+    const val CHECK_BEFORE_UNLOCKING = "/iscs/hardware-api/checkBeforeToUnlock"
 }

+ 20 - 0
app/src/main/java/com/grkj/iscs/util/NetApi.kt

@@ -1001,4 +1001,24 @@ object NetApi {
             }, isGet = true, isAuth = true
         )
     }
+
+    /**
+     * 上锁、解锁取钥匙前检查
+     */
+    fun checkBeforeAction(ticketId: Long, isLock: Boolean, callBack: (Boolean) -> Unit) {
+        NetHttpManager.getInstance().doRequestNet(
+            if (isLock) UrlConsts.CHECK_BEFORE_LOCKING else UrlConsts.CHECK_BEFORE_UNLOCKING,
+            false,
+            mapOf(
+                "ticketId" to ticketId
+            ),
+            { res, _, _ ->
+                res?.let {
+                    callBack.invoke(true)
+                } ?: run {
+                    callBack.invoke(false)
+                }
+            }, isGet = true, isAuth = true
+        )
+    }
 }

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

@@ -89,57 +89,64 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
      * 上锁人上锁流程
      */
     fun handleLockProcess(ticketId: Long) {
-        getTicketDetail(ticketId) { ticketDetail ->
-            LogUtil.i("getTicketDetail lock: $ticketDetail")
-            val role = ticketDetail?.ticketUserVOList?.find { it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER }
-            if (role == null) {
-                ToastUtils.tip(R.string.you_are_not_locker_tip)
+        NetApi.checkBeforeAction(ticketId, true) {
+            if (!it) {
+                LogUtil.w("handleLockProcess check false")
                 BusinessManager.sendLoadingEventMsg(null, false)
-                return@getTicketDetail
+                return@checkBeforeAction
             }
-
-            // 3个状态全检查锁和钥匙分配情况,防止第一次拿了钥匙和部分锁
-            if (role.jobStatus == JOB_STATUS_NOT_STARTED || role.jobStatus == JOB_STATUS_ACQUIRE_LOCK || role.jobStatus == JOB_STATUS_ACQUIRE_KEY) {
-                LogUtil.i("EquipDetail : $ticketDetail")
-                // 取锁具、取钥匙
-                val needLockCount = ticketDetail.ticketLockVOList?.count { it.lockId == null } ?: 0
-                val readyLockCount = BusinessManager.mDeviceTakeList.count { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == ticketId }
-                val realCount = (needLockCount - readyLockCount).coerceAtLeast(0)
-                if (readyLockCount > 0) {
-                    ToastUtils.tip(R.string.please_take_out_ready_device_first)
+            getTicketDetail(ticketId) { ticketDetail ->
+                LogUtil.i("getTicketDetail lock: $ticketDetail")
+                val role = ticketDetail?.ticketUserVOList?.find { it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER }
+                if (role == null) {
+                    ToastUtils.tip(R.string.you_are_not_locker_tip)
+                    BusinessManager.sendLoadingEventMsg(null, false)
+                    return@getTicketDetail
                 }
-                val isNeedKey = ticketDetail.ticketKeyVOList?.filter { it.keyId == null }?.size != 1
-                        && BusinessManager.mDeviceTakeList.none { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == ticketId }
-                LogUtil.i("needLockCount = $needLockCount , readyLockCount = $readyLockCount, realCount = $realCount, isNeedKey = $isNeedKey")
-                BusinessManager.checkEquipCount(realCount, isNeedKey) { keyPair, lockMap ->
-                    if (keyPair == null) {
-                        Executor.runOnMain {
-                            val dialog = TipDialog(mContext!!)
-                            dialog.setTip(mContext!!.getString(R.string.no_key_available_dialog_tip))
-                            var state = 0
-                            dialog.setConfirmListener {
-                                state = 1
-                                handleGiveKey(ticketDetail, null, lockMap)
-                            }
-                            dialog.setOnCancelListener {
-                                state = 2
-                                BusinessManager.sendLoadingEventMsg(null, false)
-                            }
-                            dialog.setOnDismissListener {
-                                if (state == 0) {
+
+                // 3个状态全检查锁和钥匙分配情况,防止第一次拿了钥匙和部分锁
+                if (role.jobStatus == JOB_STATUS_NOT_STARTED || role.jobStatus == JOB_STATUS_ACQUIRE_LOCK || role.jobStatus == JOB_STATUS_ACQUIRE_KEY) {
+                    LogUtil.i("EquipDetail : $ticketDetail")
+                    // 取锁具、取钥匙
+                    val needLockCount = ticketDetail.ticketLockVOList?.count { it.lockId == null } ?: 0
+                    val readyLockCount = BusinessManager.mDeviceTakeList.count { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == ticketId }
+                    val realCount = (needLockCount - readyLockCount).coerceAtLeast(0)
+                    if (readyLockCount > 0) {
+                        ToastUtils.tip(R.string.please_take_out_ready_device_first)
+                    }
+                    val isNeedKey = ticketDetail.ticketKeyVOList?.filter { it.keyId == null }?.size != 1
+                            && BusinessManager.mDeviceTakeList.none { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == ticketId }
+                    LogUtil.i("needLockCount = $needLockCount , readyLockCount = $readyLockCount, realCount = $realCount, isNeedKey = $isNeedKey")
+                    BusinessManager.checkEquipCount(realCount, isNeedKey) { keyPair, lockMap ->
+                        if (keyPair == null) {
+                            Executor.runOnMain {
+                                val dialog = TipDialog(mContext!!)
+                                dialog.setTip(mContext!!.getString(R.string.no_key_available_dialog_tip))
+                                var state = 0
+                                dialog.setConfirmListener {
+                                    state = 1
+                                    handleGiveKey(ticketDetail, null, lockMap)
+                                }
+                                dialog.setOnCancelListener {
+                                    state = 2
                                     BusinessManager.sendLoadingEventMsg(null, false)
                                 }
+                                dialog.setOnDismissListener {
+                                    if (state == 0) {
+                                        BusinessManager.sendLoadingEventMsg(null, false)
+                                    }
+                                }
+                                dialog.show()
                             }
-                            dialog.show()
+                        } else {
+                            handleGiveKey(ticketDetail, keyPair, lockMap)
                         }
-                    } else {
-                        handleGiveKey(ticketDetail, keyPair, lockMap)
                     }
+                } else {
+                    LogUtil.w("Can't lock in current step")
+                    ToastUtils.tip(R.string.can_not_lock_in_current_step)
+                    BusinessManager.sendLoadingEventMsg(null, false)
                 }
-            } else {
-                LogUtil.w("Can't lock in current step")
-                ToastUtils.tip(R.string.can_not_lock_in_current_step)
-                BusinessManager.sendLoadingEventMsg(null, false)
             }
         }
     }
@@ -171,31 +178,38 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
      * 上锁人解锁流程
      */
     fun handleUnlockProcess(ticketId: Long, keyRfid: String? = null) {
-        getTicketDetail(ticketId) { ticketDetail ->
-            LogUtil.i("getTicketDetail unlock: $ticketDetail")
-            val role = ticketDetail?.ticketUserVOList?.find { it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER }
-            if (role == null) {
-                ToastUtils.tip(R.string.you_are_not_locker_tip)
+        NetApi.checkBeforeAction(ticketId, false) {
+            if (!it) {
+                LogUtil.w("handleUnlockProcess check false")
                 BusinessManager.sendLoadingEventMsg(null, false)
-                return@getTicketDetail
+                return@checkBeforeAction
             }
-            BusinessManager.checkEquipCount(0, true) { keyPair, _ ->
-                // null表示锁具数量不够,不给钥匙
-                if (keyPair == null) {
+            getTicketDetail(ticketId) { ticketDetail ->
+                LogUtil.i("getTicketDetail unlock: $ticketDetail")
+                val role = ticketDetail?.ticketUserVOList?.find { it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER }
+                if (role == null) {
+                    ToastUtils.tip(R.string.you_are_not_locker_tip)
                     BusinessManager.sendLoadingEventMsg(null, false)
-                    keyRfid?.let {
-                        showKeyErrorDialog(it)
-                    }
-                } else {
-                    BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
+                    return@getTicketDetail
+                }
+                BusinessManager.checkEquipCount(0, true) { keyPair, _ ->
+                    // null表示锁具数量不够,不给钥匙
+                    if (keyPair == null) {
+                        BusinessManager.sendLoadingEventMsg(null, false)
+                        keyRfid?.let {
+                            showKeyErrorDialog(it)
+                        }
+                    } else {
+                        BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
 
-                    BusinessManager.getCurrentStatus(5, BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice) {
-                        if (!it) {
-                            return@getCurrentStatus
+                        BusinessManager.getCurrentStatus(5, BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice) {
+                            if (!it) {
+                                return@getCurrentStatus
+                            }
+                            LogUtil.w("handleUnlockProcess timeout")
+                            BusinessManager.removeDeviceTake(DEVICE_TYPE_KEY, keyPair.second?.rfid!!)
+                            handleUnlockProcess(ticketId, keyPair.second?.rfid!!)
                         }
-                        LogUtil.w("handleUnlockProcess timeout")
-                        BusinessManager.removeDeviceTake(DEVICE_TYPE_KEY, keyPair.second?.rfid!!)
-                        handleUnlockProcess(ticketId, keyPair.second?.rfid!!)
                     }
                 }
             }