feat(face): 优化人脸数据同步及类型映射
- 新增接口注释,完善全量及增量人脸数据获取说明 - FaceVO中faceUpdateTimestamp由Long改为String以防JS大数精度丢失 - 增加personType字段标识人员类型 - MainActivity保存人脸数据时映射完整字段,使用personType优先判断用户类型 - NetViewModelV2中获取人脸数据时改用完整构造函数创建FaceEntity - 累积更新lastFaceTimestamp为当前页最大时间戳,避免时间戳遗漏 - 优化时间戳更新逻辑,避免直接使用列表最后一条数据
This commit is contained in:
@@ -84,7 +84,9 @@ class NetViewModelV2 : BaseViewModel() {
|
||||
Timber.tag(TAG).d("getFacePage index = $currentPageNum")
|
||||
launch {
|
||||
_loadFaceResult.value = false
|
||||
// 重置持久化时间戳和内存累加器
|
||||
SpTool.lastFaceTimestamp = 0
|
||||
lastFaceTimestamp = 0L
|
||||
FileUtil.saveLog("获取人脸全量数据开始,重置时间戳为0")
|
||||
val response = ApiClient.repositoryV2.getFacePage(currentPageNum, pageSize)
|
||||
if (!parseResponse(response)) {
|
||||
@@ -98,21 +100,26 @@ class NetViewModelV2 : BaseViewModel() {
|
||||
return@withContext
|
||||
}
|
||||
val faceEntity = list.map { vo ->
|
||||
FaceEntity(vo.userId, null, Base64.decode(vo.faceFeature)).also {
|
||||
it.userType = if (vo.member == true) "1" else "2"
|
||||
it.cardNo = vo.cardNo
|
||||
}
|
||||
FaceEntity(
|
||||
vo.userId, // userName
|
||||
Base64.decode(vo.faceFeature), // featureData
|
||||
vo.personType ?: if (vo.member == true) "1" else "2", // userType
|
||||
vo.cardNo ?: "", // cardNo
|
||||
vo.userId ?: "", // userId
|
||||
vo.userFaceId ?: "", // userFaceId
|
||||
vo.member ?: false, // member
|
||||
vo.faceUpdateTimestamp?.toLongOrNull() ?: 0L // faceUpdateTimestamp
|
||||
)
|
||||
}
|
||||
faceApi.updateFaceData(currentPageNum.toInt(), faceEntity)
|
||||
// 取当前页最大时间戳(后端返回 String 类型,需转为 Long 比较),跨页累加防止中间页有更大值被覆盖
|
||||
val pageMaxTimestamp = list.maxOf { it.faceUpdateTimestamp?.toLongOrNull() ?: 0L }
|
||||
lastFaceTimestamp = maxOf(lastFaceTimestamp, pageMaxTimestamp)
|
||||
if (list.size >= pageSize) {
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
currentPageNum++
|
||||
getFacePage(currentPageNum, pageSize, onSuccess, onFailure)
|
||||
return@withContext
|
||||
}
|
||||
if (list.isNotEmpty()) {
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
}
|
||||
SpTool.lastFaceTimestamp = lastFaceTimestamp
|
||||
FileUtil.saveLog("获取人脸[全量]数据结束,时间戳为:$lastFaceTimestamp")
|
||||
_loadFaceResult.value = true
|
||||
@@ -143,9 +150,8 @@ class NetViewModelV2 : BaseViewModel() {
|
||||
return@withContext
|
||||
}
|
||||
onPageQueryFinished(list)
|
||||
if (list.isNotEmpty()) {
|
||||
lastFaceTimestamp = list.last().faceUpdateTimestamp ?: 0L
|
||||
}
|
||||
// 取列表中最大时间戳(后端返回 String 类型,需转为 Long),而非依赖列表最后一条
|
||||
lastFaceTimestamp = list.maxOf { it.faceUpdateTimestamp?.toLongOrNull() ?: 0L }
|
||||
SpTool.lastFaceTimestamp = lastFaceTimestamp
|
||||
FileUtil.saveLog("获取人脸[增量]数据结束,时间戳为:$lastFaceTimestamp")
|
||||
onAllQueryFinished()
|
||||
|
||||
Reference in New Issue
Block a user