Pārlūkot izejas kodu

初始化/下发工作票/放回钥匙,先读状态,如果是工作模式,则先处理内部工作票,再进行后续处理

Frankensteinly 8 mēneši atpakaļ
vecāks
revīzija
1d415552c8

+ 47 - 6
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -25,6 +25,7 @@ import com.grkj.iscs.modbus.DockBean
 import com.grkj.iscs.modbus.ModBusController
 import com.grkj.iscs.model.Constants
 import com.grkj.iscs.model.Constants.PERMISSION_REQUEST_CODE
+import com.grkj.iscs.model.Constants.USER_TYPE_LOCKER
 import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_CARD
 import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_FINGERPRINT
 import com.grkj.iscs.model.DeviceConst.DEVICE_TYPE_KEY
@@ -39,12 +40,10 @@ import com.grkj.iscs.model.bo.WorkTicketSendBO
 import com.grkj.iscs.model.bo.WorkTicketSendBO.LockListBO
 import com.grkj.iscs.model.eventmsg.CurrentModeMsg
 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.MsgEvent
 import com.grkj.iscs.model.eventmsg.MsgEventConstants.MSG_EVENT_CURRENT_MODE
 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.vo.lock.LockTakeUpdateReqVO
 import com.grkj.iscs.model.vo.ticket.LockPointUpdateReqVO
@@ -57,7 +56,6 @@ import com.grkj.iscs.util.SPUtils
 import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.log.LogUtil
 import com.grkj.iscs.view.base.BaseActivity
-import com.grkj.iscs.view.dialog.TipDialog
 import pub.devrel.easypermissions.AfterPermissionGranted
 
 /**
@@ -742,7 +740,7 @@ object BusinessManager {
     /**
      * 读取工作票完成情况
      */
-    fun getTicketStatusBusiness(
+    private fun getTicketStatusBusiness(
         mac: String,
         isNeedLoading: Boolean = false
     ) {
@@ -1079,13 +1077,56 @@ object BusinessManager {
 
     private fun handleCurrentMode(currentModeMsg: CurrentModeMsg) {
         when (currentModeMsg.mode) {
+            // 工作模式
             0x01.toByte() -> {
-                // TODO 读工作票
+                // 读工作票
                 getTicketStatusBusiness(currentModeMsg.bleBean.bleDevice.mac)
             }
+            // 待机模式
             0x02.toByte() -> {
-                // 暂无
+                // 根据情况看是否需要下发工作票
+                ModBusController.getKeyByMac(currentModeMsg.bleBean.bleDevice.mac)?.let { key ->
+                    // 判断是否有待取的钥匙
+                    val updateBo = mDeviceTakeList.find { it.deviceType == DEVICE_TYPE_KEY && key.rfid == it.nfc }
+                    updateBo?.let { itBO ->
+                        NetApi.getStepDetail(itBO.ticketId) {
+                            var step = 0
+                            it?.filter { it.stepStatus == "1" }?.maxByOrNull { it.stepIndex!! }?.stepIndex?.let {
+                                step = it
+                            }
+                            NetApi.getTicketDetail(itBO.ticketId) { ticketDetail ->
+                                val role = ticketDetail?.jobTicketUserList?.find {
+                                    it.userId == SPUtils.getLoginUser(MyApplication.instance?.applicationContext!!)?.userId && it.userType == USER_TYPE_LOCKER
+                                }
+                                if (role == null) {
+                                    ToastUtils.tip(R.string.you_are_not_locker_tip)
+                                    return@getTicketDetail
+                                }
+                                if (step == 4) {    // 上锁工作票
+                                    NetApi.getTicketEquipDetail(itBO.ticketId) { equipDetail ->
+                                        sendTicketBusiness(
+                                            currentModeMsg.bleBean.bleDevice.mac,
+                                            ticketDetail,
+                                            equipDetail?.ticketLockVOList?.map { it.lockNfc }?.toMutableList(),
+                                            ActivityUtils.currentActivity() as BaseActivity<*>,
+                                            true
+                                        )
+                                    }
+                                } else if (step == 7) { // 解锁工作票
+                                    sendTicketBusiness(
+                                        currentModeMsg.bleBean.bleDevice.mac,
+                                        ticketDetail,
+                                        null,
+                                        ActivityUtils.currentActivity() as BaseActivity<*>,
+                                        true
+                                    )
+                                }
+                            }
+                        }
+                    }
+                }
             }
+            // 故障模式
             0x03.toByte() -> {
                 // TODO 上报?
             }

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

@@ -101,7 +101,7 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                     println("EquipDetail : $equipDetail")
                     // 取锁具、取钥匙
                     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 && needLockCount == 0
                     BusinessManager.checkEquipCount(needLockCount, isNeedKey) { keyPair, lockMap ->
                         val lockList = mutableListOf<LockTakeUpdateReqVO>()
                         lockMap.forEach { (addr, mLockList) ->
@@ -116,14 +116,17 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                         if (keyPair != null) {
                             BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
                             LogUtil.i("工作票挂锁list : $lockList")
-                            // 下发工作票
-                            BusinessManager.sendTicketBusiness(
-                                keyPair.second?.mac!!,
-                                ticketDetail,
-                                lockList.map { it.lockNfc }.toMutableList(),
-                                ActivityUtils.currentActivity() as BaseActivity<*>,
-                                true
-                            )
+
+                            BusinessManager.getCurrentStatus(BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice)
+
+//                            // 下发工作票
+//                            BusinessManager.sendTicketBusiness(
+//                                keyPair.second?.mac!!,
+//                                ticketDetail,
+//                                lockList.map { it.lockNfc }.toMutableList(),
+//                                ActivityUtils.currentActivity() as BaseActivity<*>,
+//                                true
+//                            )
                         }
                     }
                 }
@@ -146,14 +149,17 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                 // null表示锁具数量不够,不给钥匙
                 if (keyPair != null) {
                     BusinessManager.addDeviceTake(DEVICE_TYPE_KEY, ticketId, keyPair.second?.rfid!!)
+                    
+                    BusinessManager.getCurrentStatus(BusinessManager.getBleDeviceByMac(keyPair.second?.mac)!!.bleDevice)
+
                     // 下发工作票
-                    BusinessManager.sendTicketBusiness(
-                        keyPair.second?.mac!!,
-                        ticketDetail,
-                        null,
-                        ActivityUtils.currentActivity() as BaseActivity<*>,
-                        true
-                    )
+//                    BusinessManager.sendTicketBusiness(
+//                        keyPair.second?.mac!!,
+//                        ticketDetail,
+//                        null,
+//                        ActivityUtils.currentActivity() as BaseActivity<*>,
+//                        true
+//                    )
                 }
             }
         }