优化
This commit is contained in:
@@ -54,7 +54,6 @@ import com.sw.platecabinet.utils.BitmapSaver
|
|||||||
import com.sw.platecabinet.utils.CountDownUtil
|
import com.sw.platecabinet.utils.CountDownUtil
|
||||||
import com.sw.platecabinet.utils.Debouncer
|
import com.sw.platecabinet.utils.Debouncer
|
||||||
import com.sw.platecabinet.utils.LogFileUtil
|
import com.sw.platecabinet.utils.LogFileUtil
|
||||||
import com.sw.platecabinet.utils.PlateUtils
|
|
||||||
import com.sw.platecabinet.utils.RegisterCallbackHandler
|
import com.sw.platecabinet.utils.RegisterCallbackHandler
|
||||||
import com.sw.platecabinet.utils.SoundPoolUtil
|
import com.sw.platecabinet.utils.SoundPoolUtil
|
||||||
import com.sw.platecabinet.utils.mego.PlcCallback
|
import com.sw.platecabinet.utils.mego.PlcCallback
|
||||||
@@ -295,7 +294,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
recognizeViewModel.recognizeUserId.observe(this) { result: CompareResult? ->
|
recognizeViewModel.recognizeUserId.observe(this) { result: CompareResult? ->
|
||||||
loadLogInfo("collectFace,recognizeUserId observe userId = ${result?.faceEntity?.userName}")
|
loadLogInfo("collectFace,recognizeUserId observe userId=${result?.faceEntity?.userName},similar=${result?.similar},userType=${result?.faceEntity?.userType}")
|
||||||
loadFaceRecognizeResult3(result)
|
loadFaceRecognizeResult3(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +318,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
*/
|
*/
|
||||||
private val faceSuccessThreshold by lazy { ConfigUtil.getRecognizeThreshold(this) }
|
private val faceSuccessThreshold by lazy { ConfigUtil.getRecognizeThreshold(this) }
|
||||||
|
|
||||||
private val openPlateDebouncer = Debouncer(5000)
|
private val openPlateDebouncer = Debouncer(3000)
|
||||||
private val isCollecting = AtomicBoolean(false)
|
private val isCollecting = AtomicBoolean(false)
|
||||||
|
|
||||||
private fun loadFaceRecognizeResult3(result: CompareResult?) {
|
private fun loadFaceRecognizeResult3(result: CompareResult?) {
|
||||||
@@ -371,7 +370,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
currentUserId = userId
|
currentUserId = userId
|
||||||
|
|
||||||
// 防抖,防止重复开闸
|
// 防抖,防止重复开闸
|
||||||
openPlateDebouncer.debounce {
|
openPlateDebouncer.debounce("openPlateDebouncer") {
|
||||||
openPlate(userId)
|
openPlate(userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,6 +399,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
text = "新用户采集"
|
text = "新用户采集"
|
||||||
}
|
}
|
||||||
binding.ivCollectPhoto.gone()
|
binding.ivCollectPhoto.gone()
|
||||||
|
openPlateDebouncer.reset()
|
||||||
|
plateEnable = true
|
||||||
resumeCamera()
|
resumeCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,9 +410,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
* 打开餐盘柜:先获取 PLC 状态,有盘则出盘,无盘则播放提示音
|
* 打开餐盘柜:先获取 PLC 状态,有盘则出盘,无盘则播放提示音
|
||||||
*/
|
*/
|
||||||
private fun openPlate(userId: String?) {
|
private fun openPlate(userId: String?) {
|
||||||
|
loadLogInfo("collectFace,openPlate: userId=$userId,plateEnable=$plateEnable")
|
||||||
if (plateEnable.not()) return
|
if (plateEnable.not()) return
|
||||||
loadLogInfo("collectFace,openPlate: userId=$userId")
|
// showWaitingDialog("检测餐盘中,请稍候……")
|
||||||
showWaitingDialog("检测餐盘中,请稍候……")
|
|
||||||
PlcHelper.getInstance(this).getStatus(object : PlcCallback<PlcStatus> {
|
PlcHelper.getInstance(this).getStatus(object : PlcCallback<PlcStatus> {
|
||||||
override fun onSuccess(result: PlcStatus) {
|
override fun onSuccess(result: PlcStatus) {
|
||||||
hideWaitingDialog()
|
hideWaitingDialog()
|
||||||
@@ -435,6 +436,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(message: String) {
|
override fun onError(message: String) {
|
||||||
|
ToastUtils.showToast("出盘失败,message=$message")
|
||||||
loadLogInfo("collectFace,openPlate: 出盘失败,message=$message")
|
loadLogInfo("collectFace,openPlate: 出盘失败,message=$message")
|
||||||
goInitActivity()
|
goInitActivity()
|
||||||
}
|
}
|
||||||
@@ -598,9 +600,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
binding.btnCollect.tag = ""
|
binding.btnCollect.tag = ""
|
||||||
binding.tvSimilarValue.text = ""
|
binding.tvSimilarValue.text = ""
|
||||||
retryFailCount = 0
|
retryFailCount = 0
|
||||||
|
// 人脸离开时,发送空帧清除 ViewModel 内部识别缓存,防止再次进入时使用旧数据
|
||||||
|
recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
||||||
if (binding.llCollectButton.isVisible) {
|
if (binding.llCollectButton.isVisible) {
|
||||||
leftDebouncer.debounce { leftCountDown() }
|
leftDebouncer.debounce("leftDebouncer") { leftCountDown() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
||||||
@@ -724,13 +727,13 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
// private var tempUserId: String = ""
|
// private var tempUserId: String = ""
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
plateEnable = true
|
||||||
try {
|
try {
|
||||||
if (isFirstOpen) {
|
if (isFirstOpen) {
|
||||||
isFirstOpen = false
|
isFirstOpen = false
|
||||||
goInitActivity()
|
goInitActivity()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
val faceDao = FaceDatabase.getInstance(this@LoginByFaceActivity).faceDao()
|
val faceDao = FaceDatabase.getInstance(this@LoginByFaceActivity).faceDao()
|
||||||
@@ -764,6 +767,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
plateEnable = true
|
plateEnable = true
|
||||||
collectCount = 0
|
collectCount = 0
|
||||||
// tempUserId = "${System.currentTimeMillis()}"
|
// tempUserId = "${System.currentTimeMillis()}"
|
||||||
|
openPlateDebouncer.reset()
|
||||||
resumeCamera()
|
resumeCamera()
|
||||||
registerHandler = RegisterCallbackHandler()
|
registerHandler = RegisterCallbackHandler()
|
||||||
|
|
||||||
@@ -852,7 +856,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
ToastUtils.showToast("获取人脸照片失败")
|
ToastUtils.showToast("获取人脸照片失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uploadFaceDebouncer.debounce {
|
uploadFaceDebouncer.debounce("uploadFaceDebouncer") {
|
||||||
addUserFace(faceData, imageFile)
|
addUserFace(faceData, imageFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,10 +19,15 @@ import java.io.StringReader;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class LogFileUtil {
|
public class LogFileUtil {
|
||||||
private static boolean isSaveLog = true;
|
private static boolean isSaveLog = true;
|
||||||
public static final String FILE_STR_PATH = App.getContext().getExternalCacheDir().getAbsolutePath();
|
// 使用内部存储,不会被系统缓存清理策略影响
|
||||||
|
public static final String FILE_STR_PATH = new File(App.getContext().getFilesDir(), "logs").getAbsolutePath();
|
||||||
|
// 单线程执行器,保证日志串行写入,避免多线程并发竞争
|
||||||
|
private static final ExecutorService LOG_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
public static final int SIZETYPE_B = 1;//获取文件大小单位为B的double值
|
public static final int SIZETYPE_B = 1;//获取文件大小单位为B的double值
|
||||||
public static final int SIZETYPE_KB = 2;//获取文件大小单位为KB的double值
|
public static final int SIZETYPE_KB = 2;//获取文件大小单位为KB的double值
|
||||||
@@ -610,10 +615,8 @@ public class LogFileUtil {
|
|||||||
if (!isSaveLog) {
|
if (!isSaveLog) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Thread() {
|
// 提交到单线程队列,串行执行,避免并发写入竞争
|
||||||
@Override
|
LOG_EXECUTOR.execute(() -> {
|
||||||
public void run() {
|
|
||||||
super.run();
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (String log : logs) {
|
for (String log : logs) {
|
||||||
sb.append("===")
|
sb.append("===")
|
||||||
@@ -625,9 +628,7 @@ public class LogFileUtil {
|
|||||||
}
|
}
|
||||||
String fileName = "log" + AppUtil.formatDateGetDay(System.currentTimeMillis()) + ".txt";
|
String fileName = "log" + AppUtil.formatDateGetDay(System.currentTimeMillis()) + ".txt";
|
||||||
LogFileUtil.saveStrFile(sb.toString(), fileName, FILE_STR_PATH, true);
|
LogFileUtil.saveStrFile(sb.toString(), fileName, FILE_STR_PATH, true);
|
||||||
|
});
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[][] MIME_MapTable = {
|
private static final String[][] MIME_MapTable = {
|
||||||
|
|||||||
Reference in New Issue
Block a user