餐盘柜接口改造

This commit is contained in:
2025-12-26 14:05:41 +08:00
parent 5e4dc4baa4
commit 7a6c4012d1
28 changed files with 859 additions and 507 deletions
@@ -9,16 +9,21 @@ import com.sw.platecabinet.model.request.EquipmentParam
import com.sw.platecabinet.model.request.SearchParam
import com.sw.platecabinet.model.response.EquipmentUserInfo
import com.sw.platecabinet.model.response.SearchResult
import com.sw.platecabinet.model.response.UserFaceModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import timber.log.Timber
/**
* 管理员操作viewmodel
*/
class SettingViewModel : BaseViewModel() {
// 设备绑定列表
private val _equipmentList = MutableStateFlow<List<EquipmentUserInfo>>(emptyList())
val equipmentList: StateFlow<List<EquipmentUserInfo>> = _equipmentList
// private val _equipmentList = MutableStateFlow<List<EquipmentUserInfo>>(emptyList())
// val equipmentList: StateFlow<List<EquipmentUserInfo>> = _equipmentList
private val _searchMemberList = MutableStateFlow<List<SearchResult.Member>>(emptyList())
val searchMemberList: StateFlow<List<SearchResult.Member>> = _searchMemberList
@@ -33,27 +38,36 @@ class SettingViewModel : BaseViewModel() {
/**
* 绑定/解绑状态 <绑定/解绑, 错误信息,>
*/
private val _bindStateChange = MutableStateFlow<Pair<Boolean?, ErrorInfo>>(null to ErrorInfo())
val bindStateChange: StateFlow<Pair<Boolean?, ErrorInfo>> = _bindStateChange
// private val _bindStateChange = MutableStateFlow<Pair<Boolean?, ErrorInfo>>(null to ErrorInfo())
// val bindStateChange: StateFlow<Pair<Boolean?, ErrorInfo>> = _bindStateChange
/**
* 获取设备绑定用户信息列表
*/
fun getEquipmentList(equipmentCode: String = globalEquipmentCode) {
// fun getEquipmentList(equipmentCode: String = globalEquipmentCode) {
// launchWithLoading {
// val param =
// EquipmentParam(appVersion = GlobalData.appVersion, equipmentCode = equipmentCode)
// val response = repository.getEquipmentList(param)
// if (parseResponse(response)) {
// _equipmentList.value = response.data ?: emptyList()
// }
// }
//// val list = mutableListOf<EquipmentUserInfo>()
//// for (i in 1 .. 30){
//// list.add(EquipmentUserInfo(id = i, equipmentBoxCode = i.toString()))
//// }
//// _equipmentList.value = list
// }
fun getEquipmentList(block: (List<EquipmentUserInfo>) -> Unit) {
launchWithLoading {
val param =
EquipmentParam(appVersion = GlobalData.appVersion, equipmentCode = equipmentCode)
val response = repository.getEquipmentList(param)
val response = repository.getEquipmentList()
if (parseResponse(response)) {
_equipmentList.value = response.data ?: emptyList()
val list = response.data ?: emptyList()
block(list)
}
}
// val list = mutableListOf<EquipmentUserInfo>()
// for (i in 1 .. 30){
// list.add(EquipmentUserInfo(id = i, equipmentBoxCode = i.toString()))
// }
// _equipmentList.value = list
}
/**
@@ -86,52 +100,81 @@ class SettingViewModel : BaseViewModel() {
}
}
fun bindPlate(
equipmentBoxCode: String,
equipmentCode: String = globalEquipmentCode,
memberId: Int,
plateNumber: String
) {
_bindStateChange.value = null to ErrorInfo()
// fun bindPlate(
// equipmentBoxCode: String,
// equipmentCode: String = globalEquipmentCode,
// memberId: Int,
// plateNumber: String
// ) {
// _bindStateChange.value = null to ErrorInfo()
// launchWithLoading {
// val bindParam = BindParam(
// appVersion = GlobalData.appVersion,
// equipmentBoxCode = equipmentBoxCode,
// equipmentCode = equipmentCode,
// memberId = memberId,
// plateNumber = plateNumber
// )
// val response = repository.bindEquipment(bindParam)
// if (parseResponse(response)) {
// var userInfo = response.data
// if (userInfo == null) {
// userInfo = EquipmentUserInfo()
// userInfo.equipmentBoxCode = equipmentBoxCode
// userInfo.plateNumber = plateNumber
// userInfo.equipmentCode = equipmentCode
// }
// _bindStateChange.value = true to ErrorInfo(equipmentUserInfo = userInfo)
// } else {
// _bindStateChange.value = true to ErrorInfo(response.code, response.msg.toString())
// }
// }
// }
// fun unbindPlate(
// equipmentBoxCode: String,
// equipmentCode: String = globalEquipmentCode
// ) {
// launchWithLoading {
// val bindParam = BindParam(
// appVersion = GlobalData.appVersion,
// equipmentBoxCode = equipmentBoxCode,
// equipmentCode = equipmentCode
// )
// val response = repository.bindEquipment(bindParam)
// if (parseResponse(response)) {
// _bindStateChange.value = false to ErrorInfo()
// } else {
// _bindStateChange.value = false to ErrorInfo(response.code, response.msg.toString())
// }
// }
// }
fun unbindPlate(id: Int, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
block(null to ErrorInfo())
launchWithLoading {
val bindParam = BindParam(
appVersion = GlobalData.appVersion,
equipmentBoxCode = equipmentBoxCode,
equipmentCode = equipmentCode,
memberId = memberId,
plateNumber = plateNumber
)
val response = repository.bindEquipment(bindParam)
val response = repository.plateUnbind(id)
if (parseResponse(response)) {
var userInfo = response.data
if (userInfo == null) {
userInfo = EquipmentUserInfo()
userInfo.equipmentBoxCode = equipmentBoxCode
userInfo.plateNumber = plateNumber
userInfo.equipmentCode = equipmentCode
}
_bindStateChange.value = true to ErrorInfo(equipmentUserInfo = userInfo)
block(false to ErrorInfo())
} else {
_bindStateChange.value = true to ErrorInfo(response.code, response.msg.toString())
block(false to ErrorInfo(response.code, response.msg.toString()))
}
}
}
fun unbindPlate(
equipmentBoxCode: String,
equipmentCode: String = globalEquipmentCode
) {
fun bindPlate(bindParam: BindParam, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
launchWithLoading {
val bindParam = BindParam(
appVersion = GlobalData.appVersion,
equipmentBoxCode = equipmentBoxCode,
equipmentCode = equipmentCode
)
val response = repository.bindEquipment(bindParam)
val response = repository.plateBind(bindParam)
if (parseResponse(response)) {
_bindStateChange.value = false to ErrorInfo()
var userInfo = response.data
if (userInfo == null) {
userInfo = EquipmentUserInfo()
userInfo.equipmentBoxCode = bindParam.equipmentBoxCode
userInfo.plateNumber = bindParam.plateNumber
userInfo.equipmentCode = bindParam.equipmentCode
}
block(true to ErrorInfo(equipmentUserInfo = userInfo))
} else {
_bindStateChange.value = false to ErrorInfo(response.code, response.msg.toString())
block(true to ErrorInfo(response.code, response.msg.toString()))
}
}
}
@@ -142,12 +185,8 @@ class SettingViewModel : BaseViewModel() {
) {
_searchUserInfo.value = null
launchWithLoading {
val bindParam = BindParam(
appVersion = GlobalData.appVersion,
plateNumber = plateNumber,
equipmentCode = equipmentCode
)
val response = repository.findByPlateNumber(bindParam)
// val bindParam = BindParam(plateNumber = plateNumber)
val response = repository.findByPlateNumber(plateNumber)
if (response.code == 200) {
_searchUserInfo.value = response.data
} else {
@@ -159,4 +198,31 @@ class SettingViewModel : BaseViewModel() {
}
}
}
val PAGE_SIZE = 100
/**
* 获取人脸数据
*/
fun getFaceIncrementList(
pageNo: Int = 1,
pageSize: Int = PAGE_SIZE,
timestamp: Long,
block: (List<UserFaceModel>) -> Unit
) {
launch {
val response = repository.getFaceIncrementList(
pageNum = pageNo.toLong(),
pageSize = pageSize.toLong(),
timestamp = timestamp
)
if (parseResponse(response)) {
withContext(Dispatchers.Default) {
val list: List<UserFaceModel> = response.data ?: emptyList()
block(list)
}
}
}
}
}