From 28a475ca43df14bb208a0815405e5cdb424be0ba Mon Sep 17 00:00:00 2001 From: mazengfei <331023091@qq.com> Date: Wed, 15 Jul 2026 10:56:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(face):=20=E4=BC=98=E5=8C=96=E4=BA=BA?= =?UTF-8?q?=E8=84=B8=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5=E5=8F=8A=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=98=A0=E5=B0=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增接口注释,完善全量及增量人脸数据获取说明 - FaceVO中faceUpdateTimestamp由Long改为String以防JS大数精度丢失 - 增加personType字段标识人员类型 - MainActivity保存人脸数据时映射完整字段,使用personType优先判断用户类型 - NetViewModelV2中获取人脸数据时改用完整构造函数创建FaceEntity - 累积更新lastFaceTimestamp为当前页最大时间戳,避免时间戳遗漏 - 优化时间戳更新逻辑,避免直接使用列表最后一条数据 --- app/src/main/java/com/sw/dualscreen/MyApp.kt | 4 +-- .../sw/dualscreen/activity/MainActivity.kt | 17 ++++++----- .../sw/dualscreen/model/response/v2/FaceVO.kt | 9 ++++-- .../sw/dualscreen/network/api/ApiServiceV2.kt | 6 ++++ .../sw/dualscreen/viewmodel/NetViewModelV2.kt | 28 +++++++++++-------- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/sw/dualscreen/MyApp.kt b/app/src/main/java/com/sw/dualscreen/MyApp.kt index 6d8f663..079287e 100644 --- a/app/src/main/java/com/sw/dualscreen/MyApp.kt +++ b/app/src/main/java/com/sw/dualscreen/MyApp.kt @@ -37,9 +37,9 @@ class MyApp : App() { if (!savedUrl.isNullOrEmpty()) { GlobalData.appBaseUrl = savedUrl } else { - // 未保存过则使用默认逻辑:特定设备走测试环境,其余走 UAT + // 未保存过则使用默认逻辑:特定设备走测试环境,其余走 UAT 测试档口机:2987f0c5-5754-33e9-b00a-251db5e2e55f GlobalData.appBaseUrl = - if ("2987f0c5-5754-33e9-b00a-251db5e2e55f" == deviceId) GlobalData.LOCAL_BASE_URL else GlobalData.PROD_BASE_URL + if ("2987f0c5-5754-33e9-b00a-251db5e2e55f" == deviceId) GlobalData.TEST_BASE_URL else GlobalData.PROD_BASE_URL } } diff --git a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt index c5a8dd7..d9dd42c 100644 --- a/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt +++ b/app/src/main/java/com/sw/dualscreen/activity/MainActivity.kt @@ -1236,14 +1236,17 @@ class MainActivity : BaseActivity() { FaceDatabase.getInstance(this@MainActivity).faceDao().deleteFaceById(vo.userId) } } else { - //保存数据 + // 保存数据:使用完整构造函数,映射后端全部字段到数据库 val faceEntity = FaceEntity( - vo.userId, null, Base64.decode(vo.faceFeature) - ).also { - //1-会员、2-临时用户 - it.userType = if (vo.member == true) "1" else "2" - it.cardNo = vo.cardNo - } + 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 + ) faceList.add(faceEntity) } } diff --git a/app/src/main/java/com/sw/dualscreen/model/response/v2/FaceVO.kt b/app/src/main/java/com/sw/dualscreen/model/response/v2/FaceVO.kt index fb22a8c..986d992 100644 --- a/app/src/main/java/com/sw/dualscreen/model/response/v2/FaceVO.kt +++ b/app/src/main/java/com/sw/dualscreen/model/response/v2/FaceVO.kt @@ -5,15 +5,18 @@ import kotlinx.parcelize.Parcelize /** * 新系统人脸数据 VO - * 对应接口:/neglect/booth/face/page 和 /neglect/booth/face/increment + * 对应接口:/nutrition/neglect/common/face/page 和 /nutrition/neglect/common/face/increment */ @Parcelize data class FaceVO( val userFaceId: String?, val userId: String?, val faceFeature: String?, - val faceUpdateTimestamp: Long?, + /** 后端返回 String 类型(防止 JS 大数精度丢失),映射时自行转为 Long */ + val faceUpdateTimestamp: String?, val cardNo: String?, val member: Boolean?, - val faceDeleted: Boolean? + val faceDeleted: Boolean?, + /** 人员类型:由后端定义,如 "1"-会员、"2"-临时用户、"3"-其他等 */ + val personType: String? ) : Parcelable diff --git a/app/src/main/java/com/sw/dualscreen/network/api/ApiServiceV2.kt b/app/src/main/java/com/sw/dualscreen/network/api/ApiServiceV2.kt index d36394c..7d02fc5 100644 --- a/app/src/main/java/com/sw/dualscreen/network/api/ApiServiceV2.kt +++ b/app/src/main/java/com/sw/dualscreen/network/api/ApiServiceV2.kt @@ -34,12 +34,18 @@ interface ApiServiceV2 { @Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/serve/device/config" ): ApiResponse + /** + * 获取全量人脸数据 + */ @POST suspend fun getFacePage( @Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/common/face/page", @Body request: Map ): ApiResponse?> + /** + * 获取增量人脸数据 + */ @POST suspend fun getFaceIncrement( @Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/common/face/increment", diff --git a/app/src/main/java/com/sw/dualscreen/viewmodel/NetViewModelV2.kt b/app/src/main/java/com/sw/dualscreen/viewmodel/NetViewModelV2.kt index 4d2371e..fee831c 100644 --- a/app/src/main/java/com/sw/dualscreen/viewmodel/NetViewModelV2.kt +++ b/app/src/main/java/com/sw/dualscreen/viewmodel/NetViewModelV2.kt @@ -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()