Pārlūkot izejas kodu

refactor(更新)
- 修改作业操作的权限

周文健 4 mēneši atpakaļ
vecāks
revīzija
8a58b48048

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

@@ -3,6 +3,7 @@ package com.grkj.iscs.features.main.viewmodel.job_manage
 import androidx.lifecycle.LiveData
 import androidx.lifecycle.liveData
 import com.grkj.data.data.MainDomainData
+import com.grkj.data.di.RepositoryManager
 import com.grkj.data.enums.RoleEnum
 import com.grkj.data.model.dos.IsJobTicketStep
 import com.grkj.data.model.dos.WorkflowMode
@@ -28,6 +29,7 @@ import com.grkj.ui_base.utils.modbus.DeviceConst
 import com.grkj.ui_base.utils.modbus.ModBusController
 import com.kongzue.dialogx.dialogs.PopTip
 import com.sik.sikcore.data.BeanUtils
+import com.sik.sikcore.thread.ThreadUtils
 import dagger.hilt.android.lifecycle.HiltViewModel
 import javax.inject.Inject
 import kotlinx.coroutines.Dispatchers
@@ -111,6 +113,18 @@ class JobExecuteViewModel @Inject constructor(
      */
     fun cancelJob(): 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))
+                }
+                return@liveData
+            }
             jobTicketRepository.cancelJob(ticketId)
             emit(true)
         }
@@ -121,6 +135,18 @@ class JobExecuteViewModel @Inject constructor(
      */
     fun finishJob(): 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))
+                }
+                return@liveData
+            }
             jobTicketRepository.finishJob(ticketId)
             emit(true)
         }
@@ -131,15 +157,17 @@ class JobExecuteViewModel @Inject constructor(
      */
     fun toLock(): LiveData<Boolean> {
         return liveData(Dispatchers.IO) {
-            val workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
-            if (workflowStep?.confirmType == 0 && !workflowStep.confirmRoleCode.isNullOrEmpty()) {
-                if (MainDomainData.roleKeys?.contains(
-                        workflowStep.confirmRoleCode!!
-                    ) == false && (workflowStep.confirmUser != null && MainDomainData.userInfo?.userId != workflowStep.confirmUser)
-                ) {
-                    PopTip.tip(com.grkj.ui_base.R.string.you_are_not_locker_tip)
-                    return@liveData
+            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))
                 }
+                return@liveData
             }
             ModbusBusinessManager.checkEquipCount(ticketPoints.count {
                 it.pointStatus == "0" || (it.pointStatus == "2" && workflowRepository.isUnlockBeforeLock(
@@ -149,7 +177,8 @@ class JobExecuteViewModel @Inject constructor(
                 if (lockMap.isEmpty()) {
                     TipDialog.show(
                         CommonUtils.getStr(com.grkj.ui_base.R.string.action_failed).toString(),
-                        CommonUtils.getStr(com.grkj.ui_base.R.string.lock_is_not_enough).toString(),
+                        CommonUtils.getStr(com.grkj.ui_base.R.string.lock_is_not_enough)
+                            .toString(),
                         TipDialog.DialogType.ERROR,
                         countDownTime = 10,
                         onConfirmClick = {
@@ -163,7 +192,8 @@ class JobExecuteViewModel @Inject constructor(
                 if (keyMap == null) {
                     TipDialog.show(
                         CommonUtils.getStr(com.grkj.ui_base.R.string.action_failed).toString(),
-                        CommonUtils.getStr(com.grkj.ui_base.R.string.no_available_key).toString(),
+                        CommonUtils.getStr(com.grkj.ui_base.R.string.no_available_key)
+                            .toString(),
                         TipDialog.DialogType.ERROR,
                         countDownTime = 10,
                         onConfirmClick = {
@@ -194,7 +224,8 @@ class JobExecuteViewModel @Inject constructor(
                             if (openedLockDockSize.get() >= waitOpenLockDockSize) {
                                 LoadingEvent.sendLoadingEvent(
                                     CommonUtils.getStr(
-                                        com.grkj.ui_base.R.string.take_out_lock_tip, args = listOf(
+                                        com.grkj.ui_base.R.string.take_out_lock_tip,
+                                        args = listOf(
                                             lockMap.values.flatten().count().toInt()
                                         ).toTypedArray()
                                     ), true
@@ -213,22 +244,25 @@ class JobExecuteViewModel @Inject constructor(
      */
     fun toUnLock(): LiveData<Boolean> {
         return liveData(Dispatchers.IO) {
-            val workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
-            if (workflowStep?.confirmType == 0 && !workflowStep.confirmRoleCode.isNullOrEmpty()) {
-                if (MainDomainData.roleKeys?.contains(
-                        workflowStep.confirmRoleCode!!
-                    ) == false && (workflowStep.confirmUser != null && MainDomainData.userInfo?.userId != workflowStep.confirmUser)
-                ) {
-                    PopTip.tip(com.grkj.ui_base.R.string.you_are_not_locker_tip)
-                    return@liveData
+            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))
                 }
+                return@liveData
             }
             if (checkBeforeToUnlock()) {
                 ModbusBusinessManager.checkEquipCount(0, true) { keyMap, _ ->
                     LoadingEvent.sendLoadingEvent()
                     if (keyMap == null) {
                         TipDialog.show(
-                            CommonUtils.getStr(com.grkj.ui_base.R.string.action_failed).toString(),
+                            CommonUtils.getStr(com.grkj.ui_base.R.string.action_failed)
+                                .toString(),
                             CommonUtils.getStr(com.grkj.ui_base.R.string.no_available_key)
                                 .toString(),
                             TipDialog.DialogType.ERROR,
@@ -244,8 +278,8 @@ class JobExecuteViewModel @Inject constructor(
                     )
                     BleBusinessManager.handleGiveKey(deviceTakeUpdate)
                 }
-                emit(true)
             }
+            emit(true)
         }
     }
 

+ 11 - 0
data/src/main/java/com/grkj/data/repository/IJobTicketRepository.kt

@@ -1,5 +1,6 @@
 package com.grkj.data.repository
 
+import com.grkj.data.model.dos.IsJobTicket
 import com.grkj.data.model.dos.IsJobTicketStep
 import com.grkj.data.model.req.LockPointUpdateReq
 import com.grkj.data.model.res.StepDetailRes
@@ -50,6 +51,11 @@ interface IJobTicketRepository {
      */
     fun getTicketDetail(ticketId: Long, callback: (TicketDetailRes?) -> Unit)
 
+    /**
+     * 工作票详情
+     */
+    fun getTicketDetail(ticketId: Long): TicketDetailRes?
+
     /**
      * 根据工作票id列表删除工作票相关数据
      */
@@ -154,6 +160,11 @@ interface IJobTicketRepository {
      */
     fun getAllJobSize(workstationId: Long?, startTime: String, endTime: String): Int
 
+    /**
+     * 获取所有进行中的作业
+     */
+    fun getAllInProgressJob(): List<IsJobTicket>
+
     /**
      * 获取锁定中的点位
      */

+ 10 - 3
data/src/main/java/com/grkj/data/repository/impl/standard/JobTicketRepository.kt

@@ -187,10 +187,13 @@ class JobTicketRepository @Inject constructor(
     override fun getTicketDetail(
         ticketId: Long, callback: (TicketDetailRes?) -> Unit
     ) {
+        callback(getTicketDetail(ticketId))
+    }
+
+    override fun getTicketDetail(ticketId: Long): TicketDetailRes? {
         val ticketData = getJobTicketDataByTicketId(ticketId)
         if (ticketData == null) {
-            callback(null)
-            return
+            return null
         }
         val ticketDetailRes = BeanUtils.copyProperties(ticketData, TicketDetailRes::class.java)
         val ticketKeyData = getJobTicketKeyDataByTicketId(ticketId)
@@ -250,7 +253,7 @@ class JobTicketRepository @Inject constructor(
                 jobTicketDao.getVirtualLockConflictPoint(it.pointId, it.lockId, ticketId)
             }
                 ?.filterIsInstance<TicketDetailRes.JobTicketPointsVO>() as MutableList<TicketDetailRes.JobTicketPointsVO>
-        callback(ticketDetailRes)
+        return ticketDetailRes
     }
 
     override fun deleteTicketByTicketIds(ticketIds: List<Long>) {
@@ -377,6 +380,10 @@ class JobTicketRepository @Inject constructor(
         return jobTicketDao.getInProgressJobSize()
     }
 
+    override fun getAllInProgressJob(): List<IsJobTicket> {
+        return jobTicketDao.getAllInProgressJob()
+    }
+
     override fun getLockedPointsData(current: Int, size: Int): List<PointManageVo> {
         return jobTicketDao.getLockedPointsData(size, current * size)
     }

+ 1 - 0
ui-base/src/main/java/com/grkj/ui_base/utils/ble/BleConnectionManager.kt

@@ -235,6 +235,7 @@ object BleConnectionManager {
         currentConnectingMac = listener.mac
         ThreadUtils.runOnIODelayed(10 * 1000) {
             isPreparing = false
+            currentConnectingMac = null
         }
         isPreparing = true
         if (ActivityTracker.getCurrentActivity() == null) {