Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa96455f66 | ||
|
|
786f2a123c |
@@ -14,6 +14,7 @@ import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewbinding.ViewBinding
|
||||
import com.google.gson.Gson
|
||||
import com.sw.inbound.utils.DateTimeUtils
|
||||
@@ -468,9 +469,9 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
|
||||
public val recognizeViewModel by viewModels<RecognizeViewModel>()
|
||||
private fun updateFaceData(list: List<UserFaceModel>) {
|
||||
Thread {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val faceList = mutableListOf<FaceEntity>()
|
||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||
val faceDao = FaceDatabase.getInstance(this@BaseActivity).faceDao()
|
||||
try {
|
||||
list.forEach { model ->
|
||||
if (model.faceDeleted == true) {
|
||||
@@ -480,19 +481,14 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
// FaceEntity("-1", null, byteArrayOf(-1)).also { it.userType = "-1" }
|
||||
// }
|
||||
} else {
|
||||
val faceData = faceDao.queryByUserName(model.userId)
|
||||
if (faceData == null) {
|
||||
//保存数据
|
||||
val faceEntity = FaceEntity(
|
||||
model.userId,
|
||||
null,
|
||||
Base64.decode(model.faceFeatureStr)
|
||||
).also {
|
||||
//1-会员、2-临时用户
|
||||
it.userType = if (model.member) "1" else "2"
|
||||
it.cardNo = model.cardNo
|
||||
}
|
||||
faceList.add(faceEntity)
|
||||
// 获取该用户所有已存特征,判断当前特征是否已存在
|
||||
val existList = faceDao.queryAllByUserName(model.userId)
|
||||
val featureMatches = existList.map { Base64.encode(it.featureData) == model.faceFeatureStr }
|
||||
Timber.d("userId=${model.userId}, 已存记录数=${existList.size}, 各条特征是否与服务器一致=$featureMatches")
|
||||
val alreadyExists = featureMatches.any { it }
|
||||
if (!alreadyExists) {
|
||||
//当前特征不存在,保存
|
||||
faceList.add(getNewFaceEntity(model))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -501,13 +497,25 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
}
|
||||
try {
|
||||
if (faceList.isNotEmpty()) {
|
||||
FaceDatabase.getInstance(this).faceDao().insert(faceList)
|
||||
FaceDatabase.getInstance(this@BaseActivity).faceDao().insert(faceList)
|
||||
}
|
||||
recognizeViewModel.refreshFaceList()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNewFaceEntity(model: UserFaceModel) : FaceEntity {
|
||||
return FaceEntity(
|
||||
model.userId,
|
||||
null,
|
||||
Base64.decode(model.faceFeatureStr)
|
||||
).also {
|
||||
//1-会员、2-临时用户
|
||||
it.userType = if (model.member) "1" else "2"
|
||||
it.cardNo = model.cardNo
|
||||
}
|
||||
}
|
||||
|
||||
fun initPlateList() {
|
||||
|
||||
@@ -59,6 +59,7 @@ import com.sw.platecabinet.utils.SoundPoolUtil
|
||||
import com.sw.platecabinet.utils.SpTool
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import org.greenrobot.eventbus.ThreadMode
|
||||
@@ -348,6 +349,20 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
binding.ivCollectPhoto.visible()
|
||||
}
|
||||
|
||||
private fun newUserCollect() {
|
||||
recognizeCountDownUtil.cancelCountDown()
|
||||
binding.tvToInit.text = ""
|
||||
binding.tvSimilarValue.text = ""
|
||||
binding.llCollectButton.visible()
|
||||
binding.btnRetry.gone()
|
||||
binding.btnCollect.run {
|
||||
visible()
|
||||
text = "新用户采集"
|
||||
}
|
||||
binding.ivCollectPhoto.gone()
|
||||
resumeCamera()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询餐盘数据
|
||||
*/
|
||||
@@ -674,13 +689,24 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
super.onResume()
|
||||
try {
|
||||
if (isFirstOpen) {
|
||||
isFirstOpen = false
|
||||
goInitActivity()
|
||||
binding.root.postDelayed({
|
||||
isFirstOpen = false
|
||||
}, 1000)
|
||||
return
|
||||
}
|
||||
resetRecognizeState()
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val faceDao = FaceDatabase.getInstance(this@LoginByFaceActivity).faceDao()
|
||||
val faceCount = withContext(Dispatchers.IO) { faceDao.faceCount }
|
||||
if (faceCount == 0) {
|
||||
newUserCollect()
|
||||
} else {
|
||||
resetRecognizeState()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
android:layout_marginHorizontal="50dp"
|
||||
android:paddingHorizontal="30dp"
|
||||
android:background="@drawable/btn_outline"
|
||||
android:text="清除并重新拉取数据"
|
||||
android:text="清除并拉取全量数据"
|
||||
android:textColor="#FFCC99" />
|
||||
|
||||
<TextView
|
||||
|
||||
@@ -92,6 +92,15 @@ public interface FaceDao {
|
||||
@Query("SELECT * FROM face WHERE user_name = :userName limit 1")
|
||||
FaceEntity queryByUserName(String userName);
|
||||
|
||||
/**
|
||||
* 查询指定用户的所有人脸记录(同一用户可能存有多条特征数据)
|
||||
*
|
||||
* @param userName 用户ID
|
||||
* @return 该用户所有人脸记录列表
|
||||
*/
|
||||
@Query("SELECT * FROM face WHERE user_name = :userName")
|
||||
List<FaceEntity> queryAllByUserName(String userName);
|
||||
|
||||
/**
|
||||
* @return 删除临时用户人脸
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user