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