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