修改人脸同步逻辑
This commit is contained in:
@@ -19,5 +19,7 @@ data class UserFaceModel(
|
||||
@SerializedName("userFaceId")
|
||||
val userFaceId: String? = "",
|
||||
@SerializedName("userId")
|
||||
val userId: String? = ""
|
||||
val userId: String? = "",
|
||||
@SerializedName("updateTimeStamp")
|
||||
val updateTimeStamp: Long = 0,
|
||||
) : Parcelable
|
||||
@@ -6,7 +6,9 @@ import androidx.work.CoroutineWorker
|
||||
import androidx.work.WorkerParameters
|
||||
import com.arcsoft.face.FaceEngine
|
||||
import com.sw.inbound.utils.GsonUtils
|
||||
import com.sw.plate.App
|
||||
import com.sw.plate.utils.Base64
|
||||
import com.sw.plate.utils.PrefUtils
|
||||
import com.sw.plate.utils.arcface.FaceApi
|
||||
import com.sw.plate.utils.arcface.facedb.entity.FaceEntity
|
||||
import com.sw.plate.utils.arcface.faceserver.FaceServer
|
||||
@@ -14,6 +16,7 @@ import com.sw.platecabinet.network.ApiClient
|
||||
import com.sw.platecabinet.repository.RemoteRepository
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
|
||||
class HeartBeatTask(appContext: Context, workerParams: WorkerParameters) :
|
||||
CoroutineWorker(appContext, workerParams) {
|
||||
@@ -44,10 +47,19 @@ class HeartBeatTask(appContext: Context, workerParams: WorkerParameters) :
|
||||
|
||||
private suspend fun performSync() {
|
||||
withContext(Dispatchers.IO) {
|
||||
val faceUpdateTimeStamp = PrefUtils.getLong(App.getContext(), "faceUpdateTimeStamp", 0)
|
||||
if (faceUpdateTimeStamp == 0L) {
|
||||
val timestamp = System.currentTimeMillis()
|
||||
// val timestamp = 1757063902000
|
||||
val resp = repository.getHeartbeatInterface(timestamp)
|
||||
Log.d(TAG, "performSync: ${GsonUtils.toJson(resp)}")
|
||||
PrefUtils.setLong(App.getContext(), "faceUpdateTimeStamp", timestamp)
|
||||
}
|
||||
val resp = repository.getHeartbeatInterface(
|
||||
PrefUtils.getLong(
|
||||
App.getContext(),
|
||||
"faceUpdateTimeStamp",
|
||||
0
|
||||
)
|
||||
)
|
||||
Timber.tag(TAG).d("performSync: ${GsonUtils.toJson(resp)}")
|
||||
val list = resp.data
|
||||
if (list.isNullOrEmpty()) {
|
||||
return@withContext
|
||||
@@ -55,15 +67,22 @@ class HeartBeatTask(appContext: Context, workerParams: WorkerParameters) :
|
||||
val faceServer = FaceServer.getInstance()
|
||||
val faceEngine: FaceEngine? = faceServer.faceEngine
|
||||
|
||||
list.forEach {
|
||||
list.forEachIndexed { index, it ->
|
||||
try {
|
||||
if (it.faceType == "0") {
|
||||
if (index == list.size - 1) {
|
||||
PrefUtils.setLong(
|
||||
App.getContext(),
|
||||
"faceUpdateTimeStamp",
|
||||
it.updateTimeStamp
|
||||
)
|
||||
}
|
||||
if (it.faceType == "1") {
|
||||
if (it.userId.isNullOrBlank().not()) {
|
||||
//userId非空,根据userId删除人脸数据
|
||||
faceApi.deleteByUserName(it.userId)
|
||||
faceEngine?.removeFaceFeature(it.userId.toInt())
|
||||
}
|
||||
} else if (it.faceType == "1") {
|
||||
} else if (it.faceType == "0") {
|
||||
//新增人脸数据
|
||||
val featureData = Base64.decode(it.faceFeatureString)
|
||||
val insertEntity = FaceEntity(it.userId, null, featureData)
|
||||
|
||||
@@ -11,7 +11,7 @@ object TaskManager {
|
||||
|
||||
fun startTask() {
|
||||
val nextRequest = OneTimeWorkRequestBuilder<HeartBeatTask>()
|
||||
.setInitialDelay(3, TimeUnit.MINUTES)
|
||||
.setInitialDelay(1, TimeUnit.MINUTES)
|
||||
// .setInputData(inputData)
|
||||
.build()
|
||||
WorkManager.getInstance(App.getContext())
|
||||
|
||||
Reference in New Issue
Block a user