|
|
@@ -47,7 +47,8 @@ import java.util.concurrent.atomic.AtomicInteger
|
|
|
*/
|
|
|
@HiltViewModel
|
|
|
class JobExecuteViewModel @Inject constructor(
|
|
|
- val jobTicketRepository: IJobTicketRepository, val workflowRepository: IWorkflowRepository,
|
|
|
+ val jobTicketRepository: IJobTicketRepository,
|
|
|
+ val workflowRepository: IWorkflowRepository,
|
|
|
userRepository: UserRepository
|
|
|
) : BaseViewModel(userRepository) {
|
|
|
var ticketId: Long = 0
|
|
|
@@ -57,6 +58,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
lateinit var ticketPoints: List<IsJobTicketPointsDataVo>
|
|
|
lateinit var ticketStep: List<IsJobTicketStepDataVo>
|
|
|
lateinit var ticketUser: List<IsJobTicketUserDataVo>
|
|
|
+ var groupInfo: MutableList<JobTicketGroupInfoVo> = mutableListOf()
|
|
|
var selectedLockerData: List<JobTicketGroupDataVo<JobUserVo>> = mutableListOf()
|
|
|
var selecteColockerData: List<JobUserVo> = mutableListOf()
|
|
|
var checkMemberFinish: Boolean = false
|
|
|
@@ -118,10 +120,11 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
selectedLockerData =
|
|
|
tempJobTicketUserId.filter { it.roleKeys.contains(RoleEnum.JTLOCKER.roleKey) }
|
|
|
.groupBy { it.groupId to it.groupName }.map {
|
|
|
- JobTicketGroupDataVo(JobTicketGroupInfoVo(
|
|
|
- it.key.first,
|
|
|
- it.key.second
|
|
|
- ),it.value.toMutableList())
|
|
|
+ JobTicketGroupDataVo(
|
|
|
+ JobTicketGroupInfoVo(
|
|
|
+ it.key.first, it.key.second
|
|
|
+ ), it.value.toMutableList()
|
|
|
+ )
|
|
|
}
|
|
|
selecteColockerData =
|
|
|
tempJobTicketUserId.filter { it.roleKeys.contains(RoleEnum.JTCOLOCKER.roleKey) }
|
|
|
@@ -135,8 +138,7 @@ 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 workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true
|
|
|
}
|
|
|
@@ -169,9 +171,8 @@ 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 }
|
|
|
- ?: workflowSteps.last()
|
|
|
+ val workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
+ ?: workflowSteps.last()
|
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
it.userId == MainDomainData.userInfo?.userId
|
|
|
}
|
|
|
@@ -201,13 +202,35 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
/**
|
|
|
* 去上锁
|
|
|
*/
|
|
|
- fun toLock(): LiveData<Boolean> {
|
|
|
+ fun toLock(groupId: Long): LiveData<Boolean> {
|
|
|
return liveData(Dispatchers.IO) {
|
|
|
+ if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
|
|
|
+ DeviceConst.DEVICE_TYPE_LOCK, ticketId
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ showLoading(CommonUtils.getStr(com.grkj.ui_base.R.string.please_take_out_ready_device_first))
|
|
|
+ return@liveData
|
|
|
+ }
|
|
|
+ if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
|
|
|
+ DeviceConst.DEVICE_TYPE_KEY, ticketId
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ showLoading(CommonUtils.getStr(com.grkj.ui_base.R.string.check_key_and_lock))
|
|
|
+ val rfid = ModbusBusinessManager.getWaitTakeDeviceByTicketId(
|
|
|
+ DeviceConst.DEVICE_TYPE_KEY, ticketId
|
|
|
+ )?.nfc
|
|
|
+ rfid?.let {
|
|
|
+ val keyMac = ModbusBusinessManager.getKeyMacByRfid(it)
|
|
|
+ ModbusBusinessManager.checkTicketAndSendTicket(keyMac)
|
|
|
+ return@liveData
|
|
|
+ } ?: run {
|
|
|
+ hideLoading()
|
|
|
+ }
|
|
|
+ }
|
|
|
val ticketDetail = RepositoryManager.jobTicketRepo.getTicketDetail(ticketId)
|
|
|
- val workflowStep =
|
|
|
- workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
+ val workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
- it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true
|
|
|
+ it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true && it.groupId == groupId
|
|
|
}
|
|
|
if (role == null) {
|
|
|
ThreadUtils.runOnMain {
|
|
|
@@ -228,15 +251,14 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
return@liveData
|
|
|
}
|
|
|
ModbusBusinessManager.checkEquipCount(ticketId, ticketPoints.count {
|
|
|
- it.pointStatus == "0" || (it.pointStatus == "2" && workflowRepository.isUnlockBeforeLock(
|
|
|
+ it.groupId == groupId && (it.pointStatus == "0" || (it.pointStatus == "2" && workflowRepository.isUnlockBeforeLock(
|
|
|
ticketData?.modeId!!
|
|
|
- ))
|
|
|
+ )))
|
|
|
}, true) { keyMap, lockMap ->
|
|
|
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 = {
|
|
|
@@ -250,8 +272,7 @@ 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 = {
|
|
|
@@ -266,6 +287,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
DeviceConst.DEVICE_TYPE_KEY, ticketId, keyMap.second?.rfid!!
|
|
|
)
|
|
|
}
|
|
|
+ MainDomainData.deviceTakeTicketGroupBound.put(ticketId, groupId)
|
|
|
val waitOpenLockDockSize = lockMap.keys.size
|
|
|
val openedLockDockSize = AtomicInteger(0)
|
|
|
lockMap.keys.forEach { lockDockAddr ->
|
|
|
@@ -282,8 +304,7 @@ 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
|
|
|
@@ -300,13 +321,35 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
/**
|
|
|
* 去解锁
|
|
|
*/
|
|
|
- fun toUnLock(): LiveData<Boolean> {
|
|
|
+ fun toUnLock(groupId: Long): LiveData<Boolean> {
|
|
|
return liveData(Dispatchers.IO) {
|
|
|
+ if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
|
|
|
+ DeviceConst.DEVICE_TYPE_LOCK, ticketId
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ showLoading(CommonUtils.getStr(com.grkj.ui_base.R.string.please_take_out_ready_device_first))
|
|
|
+ return@liveData
|
|
|
+ }
|
|
|
+ if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
|
|
|
+ DeviceConst.DEVICE_TYPE_KEY, ticketId
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ showLoading(CommonUtils.getStr(com.grkj.ui_base.R.string.check_key_and_lock))
|
|
|
+ val rfid = ModbusBusinessManager.getWaitTakeDeviceByTicketId(
|
|
|
+ DeviceConst.DEVICE_TYPE_KEY, ticketId
|
|
|
+ )?.nfc
|
|
|
+ rfid?.let {
|
|
|
+ val keyMac = ModbusBusinessManager.getKeyMacByRfid(it)
|
|
|
+ ModbusBusinessManager.checkTicketAndSendTicket(keyMac)
|
|
|
+ return@liveData
|
|
|
+ } ?: run {
|
|
|
+ hideLoading()
|
|
|
+ }
|
|
|
+ }
|
|
|
val ticketDetail = RepositoryManager.jobTicketRepo.getTicketDetail(ticketId)
|
|
|
- val workflowStep =
|
|
|
- workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
+ val workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
- it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true
|
|
|
+ it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true && it.groupId == groupId
|
|
|
}
|
|
|
if (role == null) {
|
|
|
ThreadUtils.runOnMain {
|
|
|
@@ -328,12 +371,13 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
}
|
|
|
if (checkBeforeToUnlock()) {
|
|
|
//全部或不分交叉点位重叠进行重叠点位解锁
|
|
|
- jobTicketRepository.updateCoincideToUnLock(ticketDetail)
|
|
|
- if (ticketDetail.ticketPointsVOList?.all {
|
|
|
+ jobTicketRepository.updateCoincideToUnLock(ticketDetail, groupId)
|
|
|
+ if (ticketDetail.ticketPointsVOList?.filter { it.groupId == groupId }?.all {
|
|
|
it.pointId in (ticketDetail.noUnlockTicketPointsVOSet?.map { it.pointId }
|
|
|
?: mutableListOf())
|
|
|
} == true) {
|
|
|
- BleBusinessManager.handleUnlockVirtualKeyReturn(ticketId)
|
|
|
+ MainDomainData.deviceTakeTicketGroupBound.put(ticketId, groupId)
|
|
|
+ BleBusinessManager.handleUnlockVirtualKeyReturn(ticketId, groupId)
|
|
|
} else {
|
|
|
ModbusBusinessManager.checkEquipCount(ticketId, 0, true) { keyMap, _ ->
|
|
|
LoadingEvent.sendLoadingEvent()
|
|
|
@@ -348,11 +392,14 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
)
|
|
|
return@checkEquipCount
|
|
|
}
|
|
|
+ MainDomainData.deviceTakeTicketGroupBound.put(ticketId, groupId)
|
|
|
ModbusBusinessManager.addDeviceTake(
|
|
|
DeviceConst.DEVICE_TYPE_KEY, ticketId, keyMap.second?.rfid!!
|
|
|
)
|
|
|
val deviceTakeUpdate = DeviceTakeUpdate(
|
|
|
- DeviceConst.DEVICE_TYPE_KEY, ticketId, keyMap.second?.rfid ?: ""
|
|
|
+ DeviceConst.DEVICE_TYPE_KEY,
|
|
|
+ ticketId,
|
|
|
+ keyMap.second?.rfid ?: "",
|
|
|
)
|
|
|
BleBusinessManager.handleGiveKey(deviceTakeUpdate)
|
|
|
}
|
|
|
@@ -429,8 +476,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
val currentWorkflowStep = workflowSteps.find {
|
|
|
it.stepId == ticketStep.firstOrNull { it.stepStatus == "0" }?.workflowStepId
|
|
|
}
|
|
|
- ticketData?.ticketStatus =
|
|
|
- currentWorkflowStep?.getTicketStatus() ?: ""
|
|
|
+ ticketData?.ticketStatus = currentWorkflowStep?.getTicketStatus() ?: ""
|
|
|
jobTicketRepository.updateTicketDataStatus(
|
|
|
ticketId,
|
|
|
currentWorkflowStep?.getTicketStatus()?.toInt()
|
|
|
@@ -521,8 +567,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
RoleEnum.JTCOLOCKER.roleKey
|
|
|
) == true
|
|
|
}.all { it.jobStatus == "1" }
|
|
|
- }"
|
|
|
- )
|
|
|
+ }")
|
|
|
return workflowStep?.enableColock == true && ticketUser.filter {
|
|
|
it.userRole?.contains(
|
|
|
RoleEnum.JTCOLOCKER.roleKey
|
|
|
@@ -541,8 +586,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
RoleEnum.JTCOLOCKER.roleKey
|
|
|
) == true
|
|
|
}.all { it.jobStatus == "2" }
|
|
|
- }"
|
|
|
- )
|
|
|
+ }")
|
|
|
return workflowStep?.enableReleaseColock == true && ticketUser.filter {
|
|
|
it.userRole?.contains(
|
|
|
RoleEnum.JTCOLOCKER.roleKey
|
|
|
@@ -617,8 +661,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
CommonUtils.getStr(R.string.please_select_member).toString() to null
|
|
|
}
|
|
|
|
|
|
- workflowStep?.enableLock == true || workflowStep?.enableColock == true ||
|
|
|
- workflowStep?.enableReleaseColock == true || workflowStep?.enableUnlock == true -> {
|
|
|
+ workflowStep?.enableLock == true || workflowStep?.enableColock == true || workflowStep?.enableReleaseColock == true || workflowStep?.enableUnlock == true -> {
|
|
|
var tip = ""
|
|
|
var index: Int? = null
|
|
|
if (workflowStep.enableLock) {
|
|
|
@@ -673,9 +716,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
fun needShowTip(): Boolean {
|
|
|
val currentWorkflowStep =
|
|
|
workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
- return currentWorkflowStep?.enableSetLocker == true || currentWorkflowStep?.enableSetColocker == true ||
|
|
|
- currentWorkflowStep?.enableLock == true || currentWorkflowStep?.enableColock == true ||
|
|
|
- currentWorkflowStep?.enableReleaseColock == true || currentWorkflowStep?.enableUnlock == true
|
|
|
+ return currentWorkflowStep?.enableSetLocker == true || currentWorkflowStep?.enableSetColocker == true || currentWorkflowStep?.enableLock == true || currentWorkflowStep?.enableColock == true || currentWorkflowStep?.enableReleaseColock == true || currentWorkflowStep?.enableUnlock == true
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -689,8 +730,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
CommonUtils.getStr(R.string.please_select_member).toString()
|
|
|
}
|
|
|
|
|
|
- currentWorkflowStep?.enableLock == true || currentWorkflowStep?.enableColock == true ||
|
|
|
- currentWorkflowStep?.enableReleaseColock == true || currentWorkflowStep?.enableUnlock == true -> {
|
|
|
+ currentWorkflowStep?.enableLock == true || currentWorkflowStep?.enableColock == true || currentWorkflowStep?.enableReleaseColock == true || currentWorkflowStep?.enableUnlock == true -> {
|
|
|
var tip = ""
|
|
|
if (currentWorkflowStep.enableLock) {
|
|
|
if (ticketPoints.any { it.pointStatus != "1" } && ticketKey.isEmpty()) {
|
|
|
@@ -737,8 +777,7 @@ class JobExecuteViewModel @Inject constructor(
|
|
|
fun canCheckStep(): LiveData<Boolean> {
|
|
|
return liveData(Dispatchers.IO) {
|
|
|
val ticketDetail = RepositoryManager.jobTicketRepo.getTicketDetail(ticketId)
|
|
|
- val workflowStep =
|
|
|
- workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
+ val workflowStep = workflowSteps.find { it.stepId == currentStepData?.workflowStepId }
|
|
|
val role = ticketDetail?.ticketUserVOList?.find {
|
|
|
it.userId == MainDomainData.userInfo?.userId && workflowStep?.currentUserCanConfirm() == true
|
|
|
}
|