|
|
@@ -13,7 +13,9 @@ import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
|
|
|
import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_LOCK
|
|
|
import com.grkj.iscs.model.eventmsg.DeviceExceptionMsg
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEvent
|
|
|
+import com.grkj.iscs.model.eventmsg.MsgEventConstants
|
|
|
import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_DEVICE_EXCEPTION
|
|
|
+import com.grkj.iscs.model.eventmsg.UpdateTicketProgressMsg
|
|
|
import com.grkj.iscs.model.vo.card.CardInfoRespVO
|
|
|
import com.grkj.iscs.model.vo.lock.LockTakeUpdateReqVO
|
|
|
import com.grkj.iscs.model.vo.ticket.StepDetailRespVO
|
|
|
@@ -55,7 +57,12 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- fun updateColockerStatus(ticketId: Long, cardNfc: String, jobStatus: String, callBack: (Boolean) -> Unit) {
|
|
|
+ fun updateColockerStatus(
|
|
|
+ ticketId: Long,
|
|
|
+ cardNfc: String,
|
|
|
+ jobStatus: String,
|
|
|
+ callBack: (Boolean) -> Unit
|
|
|
+ ) {
|
|
|
NetApi.updateColockerStatus(ticketId, cardNfc, jobStatus) {
|
|
|
Executor.runOnMain {
|
|
|
callBack(it)
|
|
|
@@ -84,7 +91,7 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
// val takeList = BusinessManager.mDeviceTakeList.filter { it.ticketId == ticketId }
|
|
|
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 上锁人上锁流程
|
|
|
*/
|
|
|
@@ -97,7 +104,9 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
}
|
|
|
getTicketDetail(ticketId) { ticketDetail ->
|
|
|
LogUtil.i("getTicketDetail lock: $ticketDetail")
|
|
|
- val role = ticketDetail?.ticketUserVOList?.find { it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER }
|
|
|
+ val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
+ it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER
|
|
|
+ }
|
|
|
if (role == null) {
|
|
|
LogUtil.w("User is not locker")
|
|
|
ToastUtils.tip(R.string.you_are_not_locker_tip)
|
|
|
@@ -109,18 +118,25 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
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 }?.let { lockPointSize ->
|
|
|
- ticketDetail.noUnlockTicketPointsVOSet?.filter { conflictData -> ticketDetail.ticketLockVOList.any { conflictData.lockId == it.lockId } }?.size?.let { conflictSize ->
|
|
|
- lockPointSize - conflictSize
|
|
|
- } ?: lockPointSize
|
|
|
- } ?: 0
|
|
|
- val readyLockCount = BusinessManager.mDeviceTakeList.count { it.deviceType == DEVICE_TYPE_LOCK && it.ticketId == ticketId }
|
|
|
+ //todo 原逻辑
|
|
|
+// val needLockCount = ticketDetail.ticketLockVOList?.count { it.lockId == null }?.let { lockPointSize ->
|
|
|
+// ticketDetail.noUnlockTicketPointsVOSet?.filter { conflictData -> ticketDetail.ticketLockVOList.any { conflictData.lockId == it.lockId } }?.size?.let { conflictSize ->
|
|
|
+// lockPointSize - conflictSize
|
|
|
+// } ?: lockPointSize
|
|
|
+// } ?: 0
|
|
|
+ //后端已经处理,所以直接计算即可
|
|
|
+ val needLockCount =
|
|
|
+ ticketDetail.ticketPointsVOList?.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 }
|
|
|
+ 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) {
|
|
|
@@ -144,7 +160,18 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
dialog.show()
|
|
|
}
|
|
|
} else {
|
|
|
- handleGiveKey(ticketDetail, keyPair, lockMap)
|
|
|
+ if (needLockCount == 0) {
|
|
|
+ ToastUtils.tip(R.string.all_point_already_locked)
|
|
|
+ keyPair.second?.rfid?.let { keyNfc ->
|
|
|
+ BusinessManager.handleVirtualKeyGive(ticketId, keyNfc) {
|
|
|
+ BusinessManager.handleVirtualKeyReturn(ticketId, keyNfc){
|
|
|
+ BusinessManager.sendLoadingEventMsg(null, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ handleGiveKey(ticketDetail, keyPair, lockMap)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
@@ -156,18 +183,37 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun handleGiveKey(ticketDetail: TicketDetailRespVO, keyPair: Pair<Byte, DockBean.KeyBean?>?, lockMap: MutableMap<Byte, MutableList<DockBean.LockBean>>) {
|
|
|
+ private fun handleGiveKey(
|
|
|
+ ticketDetail: TicketDetailRespVO,
|
|
|
+ keyPair: Pair<Byte, DockBean.KeyBean?>?,
|
|
|
+ lockMap: MutableMap<Byte, MutableList<DockBean.LockBean>>
|
|
|
+ ) {
|
|
|
val lockList = mutableListOf<LockTakeUpdateReqVO>()
|
|
|
lockMap.forEach { (addr, mLockList) ->
|
|
|
- lockList.addAll(mLockList.map { LockTakeUpdateReqVO(ticketDetail.ticketId, it.rfid, mContext!!.serialNo()) })
|
|
|
+ lockList.addAll(mLockList.map {
|
|
|
+ LockTakeUpdateReqVO(
|
|
|
+ ticketDetail.ticketId,
|
|
|
+ it.rfid,
|
|
|
+ mContext!!.serialNo()
|
|
|
+ )
|
|
|
+ })
|
|
|
// 开锁卡扣
|
|
|
ModBusController.controlLockBuckle(true, addr, mLockList.map { it.idx }.toMutableList())
|
|
|
mLockList.forEach { itLock ->
|
|
|
- BusinessManager.addDeviceTake(DEVICE_TYPE_LOCK, ticketDetail.ticketId!!, itLock.rfid)
|
|
|
+ BusinessManager.addDeviceTake(
|
|
|
+ DEVICE_TYPE_LOCK,
|
|
|
+ ticketDetail.ticketId!!,
|
|
|
+ itLock.rfid
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
if (lockList.isNotEmpty()) {
|
|
|
- BusinessManager.sendLoadingEventMsg(mContext?.getString(R.string.take_out_lock_tip, lockList.size))
|
|
|
+ BusinessManager.sendLoadingEventMsg(
|
|
|
+ mContext?.getString(
|
|
|
+ R.string.take_out_lock_tip,
|
|
|
+ lockList.size
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
// null表示锁具数量不够,不给钥匙
|
|
|
if (keyPair == null) {
|
|
|
@@ -175,7 +221,11 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
BusinessManager.sendLoadingEventMsg(null, false)
|
|
|
}
|
|
|
} else {
|
|
|
- BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketDetail.ticketId!!, keyPair.second?.rfid!!)
|
|
|
+ BusinessManager.addDeviceTake(
|
|
|
+ DEVICE_TYPE_KEY,
|
|
|
+ ticketDetail.ticketId!!,
|
|
|
+ keyPair.second?.rfid!!
|
|
|
+ )
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -191,12 +241,24 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
}
|
|
|
getTicketDetail(ticketId) { ticketDetail ->
|
|
|
LogUtil.i("getTicketDetail unlock: $ticketDetail")
|
|
|
- val role = ticketDetail?.ticketUserVOList?.find { it.userId == SPUtils.getLoginUser(mContext!!)?.userId && it.userType == USER_TYPE_LOCKER }
|
|
|
+ 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 canUnlockCount =
|
|
|
+ ticketDetail.ticketPointsVOList?.count {
|
|
|
+ it.pointStatus == "1" && it.pointId !in (ticketDetail.noUnlockTicketPointsVOSet?.map { it.pointId }
|
|
|
+ ?: listOf())
|
|
|
+ } ?: 0
|
|
|
+ if (canUnlockCount <= 0) {
|
|
|
+ ToastUtils.tip(R.string.has_no_point_can_unlock)
|
|
|
+ BusinessManager.sendLoadingEventMsg(null, false)
|
|
|
+ return@getTicketDetail
|
|
|
+ }
|
|
|
BusinessManager.checkEquipCount(0, true) { keyPair, _ ->
|
|
|
// null表示锁具数量不够,不给钥匙
|
|
|
if (keyPair == null) {
|
|
|
@@ -205,14 +267,24 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
showKeyErrorDialog(it)
|
|
|
}
|
|
|
} else {
|
|
|
- BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
|
|
|
+ BusinessManager.addDeviceTake(
|
|
|
+ DEVICE_TYPE_KEY,
|
|
|
+ ticketId,
|
|
|
+ keyPair.second?.rfid!!
|
|
|
+ )
|
|
|
|
|
|
- BusinessManager.getCurrentStatus(5, BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice) {
|
|
|
+ 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!!)
|
|
|
+ BusinessManager.removeDeviceTake(
|
|
|
+ DEVICE_TYPE_KEY,
|
|
|
+ keyPair.second?.rfid!!
|
|
|
+ )
|
|
|
handleUnlockProcess(ticketId, keyPair.second?.rfid!!)
|
|
|
}
|
|
|
}
|
|
|
@@ -232,7 +304,12 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
|
|
|
}
|
|
|
tipDialog?.setConfirmListener {
|
|
|
tipDialog?.dismiss()
|
|
|
- BusinessManager.sendEventMsg(MsgEvent(MSG_EVENT_DEVICE_EXCEPTION, DeviceExceptionMsg(DEVICE_TYPE_KEY, keyRfid)))
|
|
|
+ BusinessManager.sendEventMsg(
|
|
|
+ MsgEvent(
|
|
|
+ MSG_EVENT_DEVICE_EXCEPTION,
|
|
|
+ DeviceExceptionMsg(DEVICE_TYPE_KEY, keyRfid)
|
|
|
+ )
|
|
|
+ )
|
|
|
}
|
|
|
tipDialog?.show()
|
|
|
}
|