|
|
@@ -3,6 +3,8 @@ package com.grkj.iscs.features.main.viewmodel.exception_manage
|
|
|
import androidx.lifecycle.LiveData
|
|
|
import androidx.lifecycle.liveData
|
|
|
import com.grkj.data.data.DictConstants
|
|
|
+import com.grkj.data.model.dos.IsExceptionSourceStandard
|
|
|
+import com.grkj.data.model.dos.IsExceptionStandard
|
|
|
import com.grkj.data.model.res.CommonDictRes
|
|
|
import com.grkj.iscs.features.main.entity.ExceptionSourceDataEntity
|
|
|
import com.grkj.data.model.vo.IsExceptionStandardVo
|
|
|
@@ -13,6 +15,7 @@ import com.grkj.iscs.R
|
|
|
import com.grkj.ui_base.base.BaseViewModel
|
|
|
import com.grkj.ui_base.business.DataBusiness
|
|
|
import com.grkj.ui_base.utils.CommonUtils
|
|
|
+import com.sik.sikcore.extension.toJson
|
|
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import javax.inject.Inject
|
|
|
@@ -26,6 +29,26 @@ class ExceptionViewModel @Inject constructor(
|
|
|
val hardwareRepository: IHardwareRepository,
|
|
|
val jobTicketRepository: IJobTicketRepository
|
|
|
) : BaseViewModel() {
|
|
|
+ /**
|
|
|
+ * 钥匙状态
|
|
|
+ */
|
|
|
+ var keyStatus: List<CommonDictRes> = mutableListOf()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 挂锁状态
|
|
|
+ */
|
|
|
+ var lockStatus: List<CommonDictRes> = mutableListOf()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 仓位状态
|
|
|
+ */
|
|
|
+ var slotsStatus: List<CommonDictRes> = mutableListOf()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 作业状态
|
|
|
+ */
|
|
|
+ var jobTicketStatus: List<CommonDictRes> = mutableListOf()
|
|
|
+
|
|
|
/**
|
|
|
* 异常类型
|
|
|
*/
|
|
|
@@ -80,6 +103,10 @@ class ExceptionViewModel @Inject constructor(
|
|
|
*/
|
|
|
fun getDictData(): LiveData<Boolean> {
|
|
|
return liveData(Dispatchers.IO) {
|
|
|
+ keyStatus = DataBusiness.fetchDict(DictConstants.KEY_KEY_STATUS)
|
|
|
+ lockStatus = DataBusiness.fetchDict(DictConstants.KEY_PAD_LOCK_STATUS)
|
|
|
+ slotsStatus = DataBusiness.fetchDict(DictConstants.KEY_SLOT_STATUS)
|
|
|
+ jobTicketStatus = DataBusiness.fetchDict(DictConstants.KEY_JOB_TICKET_STATUS)
|
|
|
exceptionType = DataBusiness.fetchDict(DictConstants.KEY_EXCEPTION_TYPE)
|
|
|
exceptionStatus = DataBusiness.fetchDict(DictConstants.KEY_EXCEPTION_STATUS)
|
|
|
exceptionSourceDataType =
|
|
|
@@ -194,7 +221,7 @@ class ExceptionViewModel @Inject constructor(
|
|
|
exceptionSourceData.clear()
|
|
|
when (selectedExceptionType) {
|
|
|
//异常硬件
|
|
|
- "0" -> {
|
|
|
+ exceptionType.find { it.dictLabel == "硬件异常" }?.dictValue -> {
|
|
|
val keyData = hardwareRepository.getAllKeyInfo()
|
|
|
keyData.map {
|
|
|
val exceptionSourceDataEntity =
|
|
|
@@ -203,7 +230,7 @@ class ExceptionViewModel @Inject constructor(
|
|
|
exceptionSourceDataEntity.sourceDataId = it.keyId
|
|
|
exceptionSourceDataEntity.sourceDataType =
|
|
|
exceptionSourceDataType.find { it.dictLabel == "钥匙" }?.dictValue?.toInt()
|
|
|
- ?: 2
|
|
|
+ ?: 0
|
|
|
exceptionSourceDataEntity
|
|
|
}.toMutableList().let {
|
|
|
val exceptionSourceDataEntity =
|
|
|
@@ -211,7 +238,7 @@ class ExceptionViewModel @Inject constructor(
|
|
|
exceptionSourceDataEntity.sourceDataText = "钥匙"
|
|
|
exceptionSourceDataEntity.sourceDataType =
|
|
|
exceptionSourceDataType.find { it.dictLabel == "钥匙" }?.dictValue?.toInt()
|
|
|
- ?: 2
|
|
|
+ ?: 0
|
|
|
exceptionSourceDataEntity.children = it
|
|
|
exceptionSourceData.add(exceptionSourceDataEntity)
|
|
|
}
|
|
|
@@ -223,7 +250,7 @@ class ExceptionViewModel @Inject constructor(
|
|
|
exceptionSourceDataEntity.sourceDataId = it.lockId
|
|
|
exceptionSourceDataEntity.sourceDataType =
|
|
|
exceptionSourceDataType.find { it.dictLabel == "挂锁" }?.dictValue?.toInt()
|
|
|
- ?: 2
|
|
|
+ ?: 1
|
|
|
exceptionSourceDataEntity
|
|
|
}.toMutableList().let {
|
|
|
val exceptionSourceDataEntity =
|
|
|
@@ -231,7 +258,7 @@ class ExceptionViewModel @Inject constructor(
|
|
|
exceptionSourceDataEntity.sourceDataText = "挂锁"
|
|
|
exceptionSourceDataEntity.sourceDataType =
|
|
|
exceptionSourceDataType.find { it.dictLabel == "挂锁" }?.dictValue?.toInt()
|
|
|
- ?: 2
|
|
|
+ ?: 1
|
|
|
exceptionSourceDataEntity.children = it
|
|
|
exceptionSourceData.add(exceptionSourceDataEntity)
|
|
|
}
|
|
|
@@ -239,7 +266,8 @@ class ExceptionViewModel @Inject constructor(
|
|
|
slotsData.map {
|
|
|
val exceptionSourceDataEntity =
|
|
|
ExceptionSourceDataEntity(itemGroupPosition = 1)
|
|
|
- exceptionSourceDataEntity.sourceDataText = "仓位${it.row + 1}-${it.col}"
|
|
|
+ exceptionSourceDataEntity.sourceDataText =
|
|
|
+ "仓位${it.row?.toInt()?.plus(1)}-${it.col}"
|
|
|
exceptionSourceDataEntity.sourceDataId = it.slotId
|
|
|
exceptionSourceDataEntity.sourceDataType =
|
|
|
exceptionSourceDataType.find { it.dictLabel == "仓位" }?.dictValue?.toInt()
|
|
|
@@ -257,7 +285,7 @@ class ExceptionViewModel @Inject constructor(
|
|
|
}
|
|
|
}
|
|
|
//异常作业
|
|
|
- "1" -> {
|
|
|
+ exceptionType.find { it.dictLabel == "作业异常" }?.dictValue -> {
|
|
|
val jobTicketData = jobTicketRepository.getAllInProgressJob()
|
|
|
exceptionSourceData = jobTicketData.map {
|
|
|
val exceptionSourceDataEntity =
|
|
|
@@ -271,6 +299,72 @@ class ExceptionViewModel @Inject constructor(
|
|
|
}.toMutableList()
|
|
|
}
|
|
|
}
|
|
|
+ logger.info("异常源:${exceptionSourceData.toJson()}")
|
|
|
+ emit(true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常上报
|
|
|
+ */
|
|
|
+ fun exceptionReport(): LiveData<Boolean> {
|
|
|
+ return liveData(Dispatchers.IO) {
|
|
|
+
|
|
|
+ val exceptionData = IsExceptionStandard()
|
|
|
+ exceptionData.exceptionType = selectedExceptionType?.toInt() ?: 0
|
|
|
+ exceptionData.exceptionDescription = selectedExceptionDescription
|
|
|
+ exceptionData.processApplication = selectedProcessApplication
|
|
|
+ val exceptionId = exceptionRepository.reportException(exceptionData)
|
|
|
+ for (exceptionSource in selectedSourceData) {
|
|
|
+ when (exceptionSource.sourceDataType) {
|
|
|
+ exceptionSourceDataType.find { it.dictLabel == "钥匙" }?.dictValue?.toInt() -> {
|
|
|
+ val keyInfo =
|
|
|
+ hardwareRepository.getKeyInfoByKeyId(exceptionSource.sourceDataId)
|
|
|
+ keyInfo?.exStatus = keyStatus.find { it.dictLabel == "异常" }?.dictValue
|
|
|
+ keyInfo?.remark = selectedExceptionDescription.joinToString(",")
|
|
|
+ keyInfo?.let {
|
|
|
+ hardwareRepository.updateKeyInfo(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ exceptionSourceDataType.find { it.dictLabel == "挂锁" }?.dictValue?.toInt() -> {
|
|
|
+ val lockInfo =
|
|
|
+ hardwareRepository.getLockInfoByLockId(exceptionSource.sourceDataId)
|
|
|
+ lockInfo?.exStatus = lockStatus.find { it.dictLabel == "异常" }?.dictValue
|
|
|
+ lockInfo?.remark = selectedExceptionDescription.joinToString(",")
|
|
|
+ lockInfo?.let {
|
|
|
+ hardwareRepository.updateLockInfo(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ exceptionSourceDataType.find { it.dictLabel == "仓位" }?.dictValue?.toInt() -> {
|
|
|
+ val slotsInfo =
|
|
|
+ hardwareRepository.getIsLockCabinetSlotBySlotId(exceptionSource.sourceDataId)
|
|
|
+ slotsInfo?.status = slotsStatus.find { it.dictLabel == "异常" }?.dictValue
|
|
|
+ slotsInfo?.remark = selectedExceptionDescription.joinToString(",")
|
|
|
+ slotsInfo?.let {
|
|
|
+ hardwareRepository.updateSlotsInfo(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ exceptionSourceDataType.find { it.dictLabel == "作业" }?.dictValue?.toInt() -> {
|
|
|
+ val jobTicketData =
|
|
|
+ jobTicketRepository.getTicketRawDataByTicketId(exceptionSource.sourceDataId)
|
|
|
+ jobTicketData?.exStatus =
|
|
|
+ jobTicketStatus.find { it.dictLabel == "异常" }?.dictValue?.toInt()
|
|
|
+ jobTicketData?.remark = selectedExceptionDescription.joinToString(",")
|
|
|
+ jobTicketData?.let {
|
|
|
+ jobTicketRepository.updateTicketData(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val exceptionSourceData = IsExceptionSourceStandard()
|
|
|
+ exceptionSourceData.exceptionId = exceptionId
|
|
|
+ exceptionSourceData.sourceDataId = exceptionSource.sourceDataId
|
|
|
+ exceptionSourceData.sourceDataType = exceptionSource.sourceDataType
|
|
|
+ exceptionRepository.saveExceptionSourceData(exceptionSourceData)
|
|
|
+ }
|
|
|
+ emit(true)
|
|
|
}
|
|
|
}
|
|
|
}
|