This commit is contained in:
mazengfei
2026-01-20 12:23:38 +08:00
parent 662e2c63e1
commit ec12017fd4
3 changed files with 51 additions and 65 deletions
@@ -5,6 +5,7 @@ import android.content.Context
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.WindowInsetsController import android.view.WindowInsetsController
@@ -16,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import com.google.gson.Gson
import com.sw.inbound.utils.DateTimeUtils import com.sw.inbound.utils.DateTimeUtils
import com.sw.plate.utils.Base64 import com.sw.plate.utils.Base64
import com.sw.plate.utils.ScanGunKeyEventHelper import com.sw.plate.utils.ScanGunKeyEventHelper
@@ -113,6 +115,10 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
if (scanInfo.length > 6) { if (scanInfo.length > 6) {
plateNumber = scanInfo.take(6) plateNumber = scanInfo.take(6)
} }
Log.d("TAG", "handleScanKeyInfo: "+ Gson().toJson(MyApp.plateList))
if (MyApp.plateList == null) {
initPlateList()
}
//柜子未关联该餐盘,直接找空位置放入盘子 //柜子未关联该餐盘,直接找空位置放入盘子
val item = MyApp.plateList?.firstOrNull { it.plateNumber.isNullOrBlank() } val item = MyApp.plateList?.firstOrNull { it.plateNumber.isNullOrBlank() }
if (item == null) { if (item == null) {
@@ -486,12 +492,24 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
try { try {
if (faceList.isNotEmpty()) { if (faceList.isNotEmpty()) {
FaceDatabase.getInstance(this).faceDao().insert(faceList) FaceDatabase.getInstance(this).faceDao().insert(faceList)
recognizeViewModel.refreshFaceList()
} }
recognizeViewModel.refreshFaceList()
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
}.start() }.start()
} }
fun initPlateList() {
// SpTool.putString(SpTool.PLATE_BOX_DATA, "")
// var list = SpTool.getPlateData()
val list: MutableList<EquipmentUserInfo> = mutableListOf()
repeat(22) { index ->
list.add(
EquipmentUserInfo(equipmentBoxCode = "${index + 1}")
)
}
MyApp.plateList = list
}
} }
@@ -63,7 +63,7 @@ class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
// } // }
// } // }
}.start() }.start()
// viewModel.getUserFaceCache() viewModel.getUserFaceCache()
viewModel.getDeviceConfig { deviceConfig -> viewModel.getDeviceConfig { deviceConfig ->
runOnUiThread { runOnUiThread {
if (deviceConfig == null) { if (deviceConfig == null) {
@@ -107,38 +107,4 @@ class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
} }
private fun initPlateList() {
// SpTool.putString(SpTool.PLATE_BOX_DATA, "")
// var list = SpTool.getPlateData()
var list:List<EquipmentUserInfo>? = null;
// if (list.isNullOrEmpty()) {
list = mutableListOf()
repeat(22) { index ->
list.add(
EquipmentUserInfo(
equipmentBoxCode = "${index + 1}",
// faceId = null,
// plateNumber = null,
// updateTime = null
)
)
}
// }
// TODO: 测试数据----------------------------⬇️
// else {
// list[0].let {
// it.plateNumber = "013748"
// it.faceId = "111111111"
// it.updateTime = DateTimeUtils.getDateTimeString()
// }
// list[1].let {
// it.plateNumber = "013749"
// it.faceId = "222222222"
// it.updateTime = DateTimeUtils.getDateTimeString()
// }
// }
// TODO: 测试数据----------------------------⬆️
MyApp.plateList = list
}
} }
@@ -271,41 +271,43 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
} }
private var currentPlateInfo: EquipmentUserInfo? = null private var currentPlateInfo: EquipmentUserInfo? = null
private var debouncer = Debouncer(5000)
// private var debouncer = Debouncer(5000)
private var plateEnable = true private var plateEnable = true
/** /**
* 打开餐盘柜 * 打开餐盘柜
*/ */
private fun openPlate(userId: String?) { private fun openPlate(userId: String?) {
if (plateEnable.not()) return if (plateEnable.not()) return
debouncer.debounce { // debouncer.debounce {
Log.d(TAG, "openPlate: userId=$userId") Log.d(TAG, "openPlate: userId=$userId")
getPlateData { items -> getPlateData { items ->
Log.d(TAG, "openPlate: items:${Gson().toJson(items)}") Log.d(TAG, "openPlate: items:${Gson().toJson(items)}")
// 未查询到当前用户,查询第一个未绑定的餐盘 // 未查询到当前用户,查询第一个未绑定的餐盘
val item = items.firstOrNull { it.plateNumber.isNullOrEmpty().not() } val item = items.firstOrNull { it.plateNumber.isNullOrEmpty().not() }
Log.d(TAG, "openPlate: item2:${item}") Log.d(TAG, "openPlate: item2:${item}")
if (item == null) { if (item == null) {
//暂无餐盘 //暂无餐盘
ToastUtils.showToast("暂无餐盘,请联系管理人员!") ToastUtils.showToast("暂无餐盘,请联系管理人员!")
goInitActivity() goInitActivity()
return@getPlateData return@getPlateData
}
Log.d(TAG, "openPlate: item3:${item}")
item.faceId = userId
item.updateTime = DateTimeUtils.getDateTimeString()
item.plateNumber = null
//打开柜子
PlateUtils.open(this, item.equipmentBoxCode, false)
plateEnable = false
currentPlateInfo = item
MyApp.plateList = items
SpTool.savePlateData(items)
debouncer.reset()
//recognizeViewModel.recognizeUserId.postValue(CompareResult(null,0f))
} }
Log.d(TAG, "openPlate: item3:${item}")
item.faceId = userId
item.updateTime = DateTimeUtils.getDateTimeString()
item.plateNumber = null
//打开柜子
PlateUtils.open(this, item.equipmentBoxCode, false)
plateEnable = false
currentPlateInfo = item
MyApp.plateList = items
SpTool.savePlateData(items)
// debouncer.reset()
//recognizeViewModel.recognizeUserId.postValue(CompareResult(null,0f))
} }
// }
} }
// /** // /**
@@ -732,8 +734,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
// if (collectCount <= 5) { // if (collectCount <= 5) {
// collectFace() // collectFace()
// } else { // } else {
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------") loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
ToastUtils.showToast("人脸采集异常:${e.message}") ToastUtils.showToast("人脸采集异常:${e.message}")
// } // }
} }
} }