打开app不再清除本地数据,不再发送数据到结算终端,改为新增人脸采集接口,全量增量接口优化
This commit is contained in:
@@ -1,22 +1,14 @@
|
||||
package com.sw.platecabinet.viewmodel
|
||||
|
||||
import android.text.TextUtils
|
||||
import com.sw.inbound.utils.DateTimeUtils
|
||||
import com.sw.platecabinet.GlobalData
|
||||
import com.sw.platecabinet.GlobalData.globalEquipmentCode
|
||||
import com.sw.platecabinet.model.ErrorInfo
|
||||
import com.sw.platecabinet.model.request.BindParam
|
||||
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
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* 管理员操作viewmodel
|
||||
@@ -71,43 +63,43 @@ class SettingViewModel : BaseViewModel() {
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 搜索会员信息列表
|
||||
*/
|
||||
fun getSearchMemberList(param:String, pageNum: Int = 1, pageSize: Int = 50) {
|
||||
if (TextUtils.isEmpty(param)) return
|
||||
currentPage = pageNum
|
||||
var name =""
|
||||
var phone =""
|
||||
val num = param.toIntOrNull()
|
||||
if (num != null) {
|
||||
phone = param
|
||||
} else {
|
||||
name = param
|
||||
}
|
||||
launch {
|
||||
val searchParam = SearchParam(
|
||||
// appVersion = GlobalData.appVersion,
|
||||
name = name,
|
||||
phone = phone,
|
||||
pageNum = pageNum,
|
||||
pageSize = pageSize
|
||||
)
|
||||
isLoading = true
|
||||
val response = repository.searchUser(searchParam)
|
||||
isLoading = false
|
||||
if (parseResponse(response)) {
|
||||
response.data?.let { list ->
|
||||
if (pageNum == 1) {
|
||||
_searchMemberList.value = list
|
||||
} else {
|
||||
_searchMemberList.value = _searchMemberList.value.plus(list)
|
||||
}
|
||||
if (list.size >= pageSize) currentPage++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * 搜索会员信息列表
|
||||
// */
|
||||
// fun getSearchMemberList(param:String, pageNum: Int = 1, pageSize: Int = 50) {
|
||||
// if (TextUtils.isEmpty(param)) return
|
||||
// currentPage = pageNum
|
||||
// var name =""
|
||||
// var phone =""
|
||||
// val num = param.toIntOrNull()
|
||||
// if (num != null) {
|
||||
// phone = param
|
||||
// } else {
|
||||
// name = param
|
||||
// }
|
||||
// launch {
|
||||
// val searchParam = SearchParam(
|
||||
//// appVersion = GlobalData.appVersion,
|
||||
// name = name,
|
||||
// phone = phone,
|
||||
// pageNum = pageNum,
|
||||
// pageSize = pageSize
|
||||
// )
|
||||
// isLoading = true
|
||||
// val response = repository.searchUser(searchParam)
|
||||
// isLoading = false
|
||||
// if (parseResponse(response)) {
|
||||
// response.data?.let { list ->
|
||||
// if (pageNum == 1) {
|
||||
// _searchMemberList.value = list
|
||||
// } else {
|
||||
// _searchMemberList.value = _searchMemberList.value.plus(list)
|
||||
// }
|
||||
// if (list.size >= pageSize) currentPage++
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// fun bindPlate(
|
||||
// equipmentBoxCode: String,
|
||||
@@ -158,35 +150,35 @@ class SettingViewModel : BaseViewModel() {
|
||||
// }
|
||||
// }
|
||||
|
||||
fun unbindPlate(id: Long?, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
|
||||
block(null to ErrorInfo())
|
||||
launchWithLoading {
|
||||
val response = repository.plateUnbind(id)
|
||||
if (parseResponse(response)) {
|
||||
block(false to ErrorInfo())
|
||||
} else {
|
||||
block(false to ErrorInfo(response.code, response.msg.toString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun bindPlate(bindParam: BindParam, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
|
||||
launchWithLoading {
|
||||
// val response = repository.plateBind(bindParam)
|
||||
// fun unbindPlate(id: Long?, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
|
||||
// block(null to ErrorInfo())
|
||||
// launchWithLoading {
|
||||
// val response = repository.plateUnbind(id)
|
||||
// if (parseResponse(response)) {
|
||||
// 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))
|
||||
// block(false to ErrorInfo())
|
||||
// } else {
|
||||
// block(true to ErrorInfo(response.code, response.msg.toString()))
|
||||
// block(false to ErrorInfo(response.code, response.msg.toString()))
|
||||
// }
|
||||
}
|
||||
}
|
||||
// }
|
||||
// }
|
||||
|
||||
// fun bindPlate(bindParam: BindParam, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
|
||||
// launchWithLoading {
|
||||
//// val response = repository.plateBind(bindParam)
|
||||
//// if (parseResponse(response)) {
|
||||
//// 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 {
|
||||
//// block(true to ErrorInfo(response.code, response.msg.toString()))
|
||||
//// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun findByPlateNumber(
|
||||
plateNumber: String,
|
||||
@@ -234,4 +226,25 @@ class SettingViewModel : BaseViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加人脸数据
|
||||
*/
|
||||
fun addUserFace(faceData: String, imageFile: File, block: (Boolean, UserFaceModel?) -> Unit) {
|
||||
launch {
|
||||
val imageResp = repository.uploadImage(imageFile)
|
||||
val imageUrl = imageResp.data?:""
|
||||
if (imageUrl.isBlank()) {
|
||||
block(false, null)
|
||||
return@launch
|
||||
}
|
||||
val faceResp = repository.addUserFace(faceData, imageUrl)
|
||||
val status = parseResponse(faceResp)
|
||||
if (status.not()) {
|
||||
block(false, null)
|
||||
return@launch
|
||||
}
|
||||
block(true, faceResp.data)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,38 +58,45 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 获取人脸数据
|
||||
*/
|
||||
fun getUserFaceCache(pageNo: Int = 1, pageSize: Int = PAGE_SIZE, refreshFaceBlock: () -> Unit={}) {
|
||||
fun getUserFaceCache(
|
||||
pageNo: Int = 1,
|
||||
pageSize: Int = PAGE_SIZE,
|
||||
callback: (Boolean, String?) -> Unit = { statue, msg -> }
|
||||
) {
|
||||
var currentPageNo = pageNo
|
||||
launchWithLoading {
|
||||
val response = repository.getUserFaceCache(pageNum = pageNo, pageSize = pageSize)
|
||||
if (parseResponse(response)) {
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
return@launchWithLoading
|
||||
val status = parseResponse(response)
|
||||
if (status.not()) {
|
||||
callback(false, response.msg)
|
||||
return@launchWithLoading
|
||||
}
|
||||
// 获取成功一次后缓存状态
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||
if (pageNo == 1 && list.isEmpty()) {
|
||||
callback(true, "暂无数据")
|
||||
return@launchWithLoading
|
||||
}
|
||||
val faceEntityList = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureStr))
|
||||
}
|
||||
withContext(Dispatchers.Default) {
|
||||
faceApi.updateFaceData(pageNo, faceEntityList)
|
||||
if (list.size >= pageSize) {
|
||||
faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||
currentPageNo++
|
||||
getUserFaceCache(
|
||||
pageNo = currentPageNo,
|
||||
callback = callback
|
||||
)
|
||||
return@withContext
|
||||
}
|
||||
val faceEntityList = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureStr))
|
||||
}
|
||||
withContext(Dispatchers.Default) {
|
||||
faceApi.updateFaceData(pageNo, faceEntityList)
|
||||
refreshFaceBlock()
|
||||
if (list.size >= pageSize) {
|
||||
faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||
currentPageNo++
|
||||
getUserFaceCache(
|
||||
pageNo = currentPageNo,
|
||||
refreshFaceBlock = refreshFaceBlock
|
||||
)
|
||||
return@withContext
|
||||
}
|
||||
if (list.isNotEmpty()) {
|
||||
faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||
}
|
||||
SpTool.lastFaceTimestamp = faceTimestamp
|
||||
//activeEngine()
|
||||
if (list.isNotEmpty()) {
|
||||
faceTimestamp = list.last().faceUpdateTimestamp ?: 0
|
||||
}
|
||||
SpTool.lastFaceTimestamp = faceTimestamp
|
||||
callback(true, "查询完成")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user