Sfoglia il codice sorgente

refactor(更新)
- 步骤点击的提示权限错误问题

周文健 4 mesi fa
parent
commit
fe05f4f421

+ 45 - 40
app/src/main/java/com/grkj/iscs/features/main/fragment/job_manage/JobExecuteFragment.kt

@@ -185,46 +185,51 @@ class JobExecuteFragment : BaseFragment<FragmentJobExecuteBinding>() {
         itemBinding.stepLayout.setDebouncedClickListener {
             val workflowStep =
                 viewModel.workflowSteps.find { it.stepId == item.workflowStepId }
-            if (item.stepIndex < viewModel.currentStepData?.stepIndex!!) {
-                return@setDebouncedClickListener
-            }
-            if (item.stepId != viewModel.currentStepData?.stepId && workflowStep?.enableSetLocker == false && workflowStep.enableSetColocker == false) {
-                PopTip(
-                    getString(
-                        R.string.please_done_operation,
-                        viewModel.currentStepData?.androidStepContent
-                    )
-                )
-                return@setDebouncedClickListener
-            }
-            if (workflowStep?.confirmType != 0 &&
-                (workflowStep?.enableSetLocker == true || workflowStep?.enableSetColocker == true)
-            ) {
-                stepClickConfirm(adapter, item, workflowStep)
-            } else if (workflowStep?.confirmType == 0 &&
-                workflowStep.confirmRoleCode == null &&
-                workflowStep.confirmUser == null
-            ) {
-                stepClickConfirm(adapter, item, workflowStep)
-            } else if (workflowStep?.confirmType == 0 &&
-                (workflowStep.confirmRoleCode != null && MainDomainData.roleKeys?.contains(
-                    workflowStep.confirmRoleCode!!
-                ) == true) &&
-                workflowStep.confirmUser == null
-            ) {
-                stepClickConfirm(adapter, item, workflowStep)
-            } else if (workflowStep?.confirmType == 0 &&
-                (workflowStep.confirmRoleCode != null && MainDomainData.roleKeys?.contains(
-                    workflowStep.confirmRoleCode!!
-                ) == true) &&
-                (workflowStep.confirmUser != null && MainDomainData.userInfo?.userId == workflowStep.confirmUser)
-            ) {
-                stepClickConfirm(adapter, item, workflowStep)
-            } else {
-                val errorTipData = viewModel.getStepErrorTip(workflowStep)
-                PopTip.tip(errorTipData.first)
-                errorTipData.second?.let {
-                    checkLayout(it)
+            viewModel.canCheckStep().observe(this@JobExecuteFragment) {
+                if (it) {
+
+                    if (item.stepIndex < viewModel.currentStepData?.stepIndex!!) {
+                        return@observe
+                    }
+                    if (item.stepId != viewModel.currentStepData?.stepId && workflowStep?.enableSetLocker == false && workflowStep.enableSetColocker == false) {
+                        PopTip(
+                            getString(
+                                R.string.please_done_operation,
+                                viewModel.currentStepData?.androidStepContent
+                            )
+                        )
+                        return@observe
+                    }
+                    if (workflowStep?.confirmType != 0 &&
+                        (workflowStep?.enableSetLocker == true || workflowStep?.enableSetColocker == true)
+                    ) {
+                        stepClickConfirm(adapter, item, workflowStep)
+                    } else if (workflowStep?.confirmType == 0 &&
+                        workflowStep.confirmRoleCode == null &&
+                        workflowStep.confirmUser == null
+                    ) {
+                        stepClickConfirm(adapter, item, workflowStep)
+                    } else if (workflowStep?.confirmType == 0 &&
+                        (workflowStep.confirmRoleCode != null && MainDomainData.roleKeys?.contains(
+                            workflowStep.confirmRoleCode!!
+                        ) == true) &&
+                        workflowStep.confirmUser == null
+                    ) {
+                        stepClickConfirm(adapter, item, workflowStep)
+                    } else if (workflowStep?.confirmType == 0 &&
+                        (workflowStep.confirmRoleCode != null && MainDomainData.roleKeys?.contains(
+                            workflowStep.confirmRoleCode!!
+                        ) == true) &&
+                        (workflowStep.confirmUser != null && MainDomainData.userInfo?.userId == workflowStep.confirmUser)
+                    ) {
+                        stepClickConfirm(adapter, item, workflowStep)
+                    } else {
+                        val errorTipData = viewModel.getStepErrorTip(workflowStep)
+                        PopTip.tip(errorTipData.first)
+                        errorTipData.second?.let {
+                            checkLayout(it)
+                        }
+                    }
                 }
             }
         }

+ 24 - 2
app/src/main/java/com/grkj/iscs/features/main/viewmodel/job_manage/JobExecuteViewModel.kt

@@ -169,7 +169,7 @@ class JobExecuteViewModel @Inject constructor(
                 }
                 return@liveData
             }
-            ModbusBusinessManager.checkEquipCount(ticketPoints.count {
+            ModbusBusinessManager.checkEquipCount(ticketId, ticketPoints.count {
                 it.pointStatus == "0" || (it.pointStatus == "2" && workflowRepository.isUnlockBeforeLock(
                     ticketData?.modeId!!
                 ))
@@ -257,7 +257,7 @@ class JobExecuteViewModel @Inject constructor(
                 return@liveData
             }
             if (checkBeforeToUnlock()) {
-                ModbusBusinessManager.checkEquipCount(0, true) { keyMap, _ ->
+                ModbusBusinessManager.checkEquipCount(ticketId, 0, true) { keyMap, _ ->
                     LoadingEvent.sendLoadingEvent()
                     if (keyMap == null) {
                         TipDialog.show(
@@ -640,4 +640,26 @@ class JobExecuteViewModel @Inject constructor(
             else -> ""
         }
     }
+
+    /**
+     * 是否可以确认步骤
+     */
+    fun canCheckStep(): LiveData<Boolean> {
+        return liveData(Dispatchers.IO) {
+            val ticketDetail = RepositoryManager.jobTicketRepo.getTicketDetail(ticketId)
+            val workflowStep =
+                workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
+            val role = ticketDetail?.ticketUserVOList?.find {
+                it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true
+            }
+            if (role == null) {
+                ThreadUtils.runOnMain {
+                    PopTip.tip(CommonUtils.getStr(com.grkj.ui_base.R.string.no_permission_to_handle))
+                }
+                emit(false)
+            } else {
+                emit(true)
+            }
+        }
+    }
 }

+ 12 - 4
ui-base/src/main/java/com/grkj/ui_base/business/ModbusBusinessManager.kt

@@ -208,6 +208,7 @@ object ModbusBusinessManager {
 
     // 3. 重写 checkEquipCount
     fun checkEquipCount(
+        ticketId: Long,
         needLockCount: Int,
         isNeedKey: Boolean,
         callBack: (Pair<Byte, DockBean.KeyBean?>?, MutableMap<Byte, MutableList<DockBean.LockBean>>) -> Unit
@@ -244,8 +245,11 @@ object ModbusBusinessManager {
                         slotsPage?.records?.filter {
                             it.slotType == slotTypeList.find { d -> d.dictLabel == "锁" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
                         }?.toMutableList() ?: mutableListOf(),
-                        locksPage?.records?.filter { it.exStatus == lockStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
-                            ?.map { it.lockNfc ?: "" }?.toMutableList() ?: mutableListOf()
+                        (locksPage?.records?.filter { it.exStatus == lockStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
+                            ?.map { it.lockNfc ?: "" }?.toMutableList() ?: mutableListOf()).apply {
+                            addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_LOCK && it.ticketId != ticketId }
+                                .map { it.nfc })
+                        }
                     )
                 }
 
@@ -268,8 +272,12 @@ object ModbusBusinessManager {
                             slotsPage?.records?.filter {
                                 it.slotType == slotTypeList.find { d -> d.dictLabel == "钥匙" }?.dictValue && it.status == slotStatusList.find { d -> d.dictLabel == "异常" }?.dictValue
                             }?.toMutableList() ?: mutableListOf(),
-                            keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
-                                ?.map { it.keyNfc ?: "" }?.toMutableList() ?: mutableListOf()
+                            (keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
+                                ?.map { it.keyNfc ?: "" }?.toMutableList()
+                                ?: mutableListOf()).apply {
+                                    addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_KEY && it.ticketId != ticketId }
+                                        .map { it.nfc })
+                                }
                         )
                     }
                     if (keyPair == null) {