餐盘柜接口改造
This commit is contained in:
@@ -67,10 +67,10 @@ abstract class BaseViewModel() : ViewModel() {
|
||||
|
||||
fun parseEquipmentInfo(equipmentInfo: EquipmentInfo) {
|
||||
// GlobalData.appBaseUrl = equipmentInfo.appPackageUrl!!
|
||||
GlobalData.appBaseUrl="https://vip.shuziweidao.com"
|
||||
// GlobalData.appBaseUrl="https://vip.shuziweidao.com"
|
||||
// GlobalData.sdkKey = equipmentInfo.arcsoftSdkKey!!
|
||||
// GlobalData.appId = equipmentInfo.arcsoftAppId!!
|
||||
// GlobalData.activeKey = equipmentInfo.arcsoftActiveKey!!
|
||||
GlobalData.restId = equipmentInfo.canteenId!!
|
||||
// GlobalData.restId = equipmentInfo.canteenId!!
|
||||
}
|
||||
}
|
||||
@@ -1,68 +1,68 @@
|
||||
package com.sw.platecabinet.viewmodel
|
||||
|
||||
import com.sw.inbound.utils.GsonUtils
|
||||
import com.sw.inbound.utils.SPUtil
|
||||
import com.sw.platecabinet.GlobalData
|
||||
import com.sw.platecabinet.GlobalKey
|
||||
import com.sw.platecabinet.model.response.EquipmentInfo
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import timber.log.Timber
|
||||
import kotlin.jvm.java
|
||||
|
||||
/**
|
||||
* 初始化的viewmodel
|
||||
*/
|
||||
class DeviceViewModel : BaseViewModel() {
|
||||
private val _deviceInfoResult = MutableStateFlow<Boolean?>(null)
|
||||
val deviceInfoResult: StateFlow<Boolean?> = _deviceInfoResult
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
fun getDeviceToken(deviceId: String = GlobalData.deviceId) {
|
||||
launchWithLoading {
|
||||
val response = repository.getDeviceToken(deviceId)
|
||||
if (parseResponse(response)) {
|
||||
val response1 = repository.getDeviceInfo(deviceId, response.result!!)
|
||||
|
||||
if (parseResponse(response1)) {
|
||||
val equipmentInfo = response1.result
|
||||
if (equipmentInfo == null) return@launchWithLoading
|
||||
try {
|
||||
parseEquipmentInfo(equipmentInfo)
|
||||
SPUtil.getInstance()
|
||||
.put(GlobalKey.KEY_EQUIPMENT_INFO, GsonUtils.toJson(equipmentInfo))
|
||||
_deviceInfoResult.value = true
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查缓存数据
|
||||
*/
|
||||
fun checkEquipmentInfo(): Boolean {
|
||||
val equipmentInfoStr = SPUtil.getInstance().get(GlobalKey.KEY_EQUIPMENT_INFO, "")
|
||||
if (equipmentInfoStr == null) {
|
||||
Timber.e("获取缓存设备信息失败")
|
||||
return false
|
||||
}
|
||||
val equipmentInfo =
|
||||
GsonUtils.fromJson<EquipmentInfo>(equipmentInfoStr, EquipmentInfo::class.java)
|
||||
if (equipmentInfo == null) {
|
||||
Timber.e("解析缓存设备信息失败")
|
||||
return false
|
||||
}
|
||||
try {
|
||||
parseEquipmentInfo(equipmentInfo)
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
//package com.sw.platecabinet.viewmodel
|
||||
//
|
||||
//import com.sw.inbound.utils.GsonUtils
|
||||
//import com.sw.inbound.utils.SPUtil
|
||||
//import com.sw.platecabinet.GlobalData
|
||||
//import com.sw.platecabinet.GlobalKey
|
||||
//import com.sw.platecabinet.model.response.EquipmentInfo
|
||||
//import kotlinx.coroutines.flow.MutableStateFlow
|
||||
//import kotlinx.coroutines.flow.StateFlow
|
||||
//import timber.log.Timber
|
||||
//import kotlin.jvm.java
|
||||
//
|
||||
///**
|
||||
// * 初始化的viewmodel
|
||||
// */
|
||||
//class DeviceViewModel : BaseViewModel() {
|
||||
// private val _deviceInfoResult = MutableStateFlow<Boolean?>(null)
|
||||
// val deviceInfoResult: StateFlow<Boolean?> = _deviceInfoResult
|
||||
//
|
||||
// /**
|
||||
// * 获取token
|
||||
// */
|
||||
// fun getDeviceToken(deviceId: String = GlobalData.deviceId) {
|
||||
// launchWithLoading {
|
||||
// val response = repository.getDeviceToken(deviceId)
|
||||
// if (parseResponse(response)) {
|
||||
// val response1 = repository.getDeviceInfo(deviceId, response.result!!)
|
||||
//
|
||||
// if (parseResponse(response1)) {
|
||||
// val equipmentInfo = response1.result
|
||||
// if (equipmentInfo == null) return@launchWithLoading
|
||||
// try {
|
||||
// parseEquipmentInfo(equipmentInfo)
|
||||
// SPUtil.getInstance()
|
||||
// .put(GlobalKey.KEY_EQUIPMENT_INFO, GsonUtils.toJson(equipmentInfo))
|
||||
// _deviceInfoResult.value = true
|
||||
// } catch (e: Exception) {
|
||||
// Timber.e(e)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 检查缓存数据
|
||||
// */
|
||||
// fun checkEquipmentInfo(): Boolean {
|
||||
// val equipmentInfoStr = SPUtil.getInstance().get(GlobalKey.KEY_EQUIPMENT_INFO, "")
|
||||
// if (equipmentInfoStr == null) {
|
||||
// Timber.e("获取缓存设备信息失败")
|
||||
// return false
|
||||
// }
|
||||
// val equipmentInfo =
|
||||
// GsonUtils.fromJson<EquipmentInfo>(equipmentInfoStr, EquipmentInfo::class.java)
|
||||
// if (equipmentInfo == null) {
|
||||
// Timber.e("解析缓存设备信息失败")
|
||||
// return false
|
||||
// }
|
||||
// try {
|
||||
// parseEquipmentInfo(equipmentInfo)
|
||||
// return true
|
||||
// } catch (e: Exception) {
|
||||
// Timber.e(e)
|
||||
// return false
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.sw.platecabinet.GlobalKey
|
||||
import com.sw.platecabinet.model.request.LoginParam
|
||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||
import com.sw.platecabinet.model.response.UserFaceModel
|
||||
import com.sw.platecabinet.utils.SpTool
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -25,6 +26,11 @@ import timber.log.Timber
|
||||
* 用户viewmodel
|
||||
*/
|
||||
class UserViewModel : BaseViewModel() {
|
||||
|
||||
companion object {
|
||||
const val PAGE_SIZE = 100
|
||||
}
|
||||
|
||||
// 通过人脸获取到的用户信息
|
||||
private val _currentUserInfo = MutableStateFlow<EquipmentUserInfo?>(null)
|
||||
val currentUserInfo: StateFlow<EquipmentUserInfo?> = _currentUserInfo
|
||||
@@ -34,36 +40,46 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 获取token
|
||||
*/
|
||||
fun generateToken(deviceId: String = "SWSN:88:12:AC:4E:D9:CC") {
|
||||
launchWithLoading {
|
||||
val response = repository.generateToken(deviceId)
|
||||
if (parseResponse(response)) {
|
||||
// 缓存token
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_TOKEN, response.data)
|
||||
// 首次运行获取人脸数据
|
||||
if (SPUtil.getInstance().get(GlobalKey.KEY_FIRST_RUN, false) != true) {
|
||||
getUserFaceCache()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// fun generateToken(deviceId: String = "SWSN:88:12:AC:4E:D9:CC") {
|
||||
// launchWithLoading {
|
||||
// val response = repository.generateToken(deviceId)
|
||||
// if (parseResponse(response)) {
|
||||
// // 缓存token
|
||||
// SPUtil.getInstance().put(GlobalKey.KEY_TOKEN, response.data)
|
||||
// // 首次运行获取人脸数据
|
||||
// if (SPUtil.getInstance().get(GlobalKey.KEY_FIRST_RUN, false) != true) {
|
||||
// getUserFaceCache()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* 获取人脸数据
|
||||
*/
|
||||
fun getUserFaceCache(index: Int = 0) {
|
||||
fun getUserFaceCache(pageNo: Int = 1, pageSize: Int = PAGE_SIZE) {
|
||||
var currentPageNo = pageNo
|
||||
launchWithLoading {
|
||||
val response = repository.getUserFaceCache()
|
||||
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()
|
||||
val faceEntity = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureString))
|
||||
if (list.isEmpty()) {
|
||||
return@launchWithLoading
|
||||
}
|
||||
|
||||
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||
val faceEntityList = list.map {
|
||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureStr))
|
||||
}
|
||||
withContext(Dispatchers.Default) {
|
||||
faceApi.updateFaceData(index, faceEntity)
|
||||
activeEngine()
|
||||
faceApi.updateFaceData(pageNo, faceEntityList)
|
||||
if (list.size >= pageSize) {
|
||||
currentPageNo++
|
||||
getUserFaceCache(currentPageNo)
|
||||
}
|
||||
//activeEngine()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,14 +128,8 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 校验码登录
|
||||
*/
|
||||
fun loginWithPwd(equipmentCode: String = globalEquipmentCode, phone: String, password: String) {
|
||||
fun loginWithPwd(loginParam: LoginParam) {
|
||||
launchWithLoading {
|
||||
val loginParam = LoginParam(
|
||||
appVersion = GlobalData.appVersion,
|
||||
equipmentCode = equipmentCode,
|
||||
phone = phone,
|
||||
password = password
|
||||
)
|
||||
val response = repository.equipmentBoxLogin(loginParam)
|
||||
if (parseResponse(response)) {
|
||||
_currentUserInfo.value = response.data
|
||||
@@ -130,14 +140,10 @@ class UserViewModel : BaseViewModel() {
|
||||
/**
|
||||
* 通过用户id获取用户信息
|
||||
*/
|
||||
fun getUserInfoById(equipmentCode: String = globalEquipmentCode, memberId: Int, action:(EquipmentUserInfo?)->Unit={}) {
|
||||
fun getUserInfoById(memberId: Int?, action:(EquipmentUserInfo?)->Unit={}) {
|
||||
_currentUserInfo.value = null
|
||||
launchWithLoading {
|
||||
val loginParam = LoginParam(
|
||||
appVersion = GlobalData.appVersion,
|
||||
equipmentCode = equipmentCode,
|
||||
memberId = memberId
|
||||
)
|
||||
val loginParam = LoginParam(memberId = memberId)
|
||||
val response = repository.equipmentBoxLogin(loginParam)
|
||||
if (parseResponse(response)) {
|
||||
_currentUserInfo.value = response.data
|
||||
|
||||
Reference in New Issue
Block a user