fix(weight): 修复称重逻辑和支付模式相关问题
- 将 WEIGHT_CHANGE_VALUE 从 25 修改为 20 - 添加 currentWeight 变量用于准确记录当前称重值 - 临时修改 settlementMode 为独立支付模式用于测试 - 更新日志输出以更好地跟踪称重变化 - 修复即放即取和余量计量模式下的称重处理逻辑 - 添加食物识别状态控制变量 foodRecognizeState - 在不同模式下正确设置 eatWeight 和 foodWeight 计算方式 - 优化余量计量模式下的状态重置逻辑 - 添加倒计时功能用于余量计量模式状态重置 - 修复营养计算相关的日志输出格式
This commit is contained in:
@@ -100,7 +100,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
private const val TAG = "MainActivity"
|
||||
const val TIME_OUT = 5 * 60 * 1000L
|
||||
|
||||
const val WEIGHT_CHANGE_VALUE = 25
|
||||
const val WEIGHT_CHANGE_VALUE = 20
|
||||
const val WEIGHT_RESET_RECOGNIZE = 10
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
private var canIdentify: Boolean = false
|
||||
private var bottomSheetDialog: CustomBottomSheetDialog? = null
|
||||
private var lastWeight: Int = 0
|
||||
private var currentWeight: Int = 0
|
||||
private var lastPhotoUri: Uri? = null // 最后拍照的图片
|
||||
private var debouncer = Debouncer(2000)
|
||||
private var isRecognitionFood = true
|
||||
@@ -200,6 +201,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
//结算模式:1-独立支付,2-联合结算
|
||||
settlementMode = if (deviceConfig.payType == 2) 0 else 1
|
||||
// TODO: 临时修改为独立支付模式用于测试--------------------------
|
||||
settlementMode = 1
|
||||
// TODO: 临时修改为独立支付模式用于测试--------------------------
|
||||
SPUtil.getInstance().put(GlobalKey.KEY_SETTLEMENT_MODE, settlementMode)
|
||||
|
||||
GlobalData.appId = deviceConfig.arcsoftAppId ?: ""
|
||||
@@ -284,8 +288,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
return
|
||||
}
|
||||
pauseAnalysis()
|
||||
recognizeWeight = lastWeight
|
||||
log("registerDataChange,副屏updateFood调用前耗时:${System.currentTimeMillis() - startTime}")
|
||||
recognizeWeight = currentWeight
|
||||
log("registerDataChange,副屏updateFood调用前耗时:${System.currentTimeMillis() - startTime}, recognizeWeight = ${recognizeWeight}")
|
||||
startTime = System.currentTimeMillis()
|
||||
presentation?.updateFood(foodInfo)
|
||||
binding.tvFoodName.text = foodInfo.foodName
|
||||
@@ -343,7 +347,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
log("registerDataChange weight 联合支付-余量计量,重量小于${WEIGHT_RESET_RECOGNIZE}g,step1FoodRecognizing")
|
||||
//秤上重量过小,显示识别中页面
|
||||
presentation?.step1FoodRecognizing()
|
||||
lastWeight = weight
|
||||
return
|
||||
}
|
||||
log("registerDataChange weight 联合支付-余量计量,订单完成状态:${presentation!!.jointPaymentQueryFinish}")
|
||||
@@ -351,6 +354,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
if (presentation!!.jointPaymentQueryFinish) {
|
||||
log("registerDataChange weight 联合支付-余量计量,updateWeight")
|
||||
presentation?.updateWeight(weight)
|
||||
log("registerDataChange weight 重置lastWeight与weigh:${weight}一致----------------1000006")
|
||||
lastWeight = weight
|
||||
return
|
||||
}
|
||||
@@ -359,7 +363,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
|
||||
private fun readWeight(weight: Int) {
|
||||
log("registerDataChange weight = $weight")
|
||||
currentWeight = weight
|
||||
log("registerDataChange weight = $weight, lastWeight = $lastWeight")
|
||||
binding.tvShowWeight.let {
|
||||
if (it.text.toString() != weight.toString()) {
|
||||
it.text = "$weight"
|
||||
@@ -381,18 +386,21 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
loadJFJQBySettlement(weight)
|
||||
return
|
||||
}
|
||||
|
||||
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
||||
log("registerDataChange weight 秤重量小于${WEIGHT_RESET_RECOGNIZE}g")
|
||||
//检测到秤上没有东西
|
||||
checkedItem = null
|
||||
}
|
||||
//独立支付-------------------------------------------
|
||||
if (lastWeight - weight > 5) {
|
||||
//及放及取,从秤上拿走超过5克
|
||||
if (presentation?.mealPickupMode == 0) {
|
||||
presentation?.updateWeight(weight)
|
||||
lastWeight = weight
|
||||
//0-即放即取,1-余量计量
|
||||
val mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
//0-计费,1-不计费
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
if(mealPickupMode == 0 && chargeMode == 1) {
|
||||
//即放即取+不计费模式,
|
||||
if (presentation?.currentUserId.isNullOrBlank().not()) {
|
||||
//已识别人脸的状态下,从秤上拿餐品后,不再读取数据,等待人脸离开提交订单
|
||||
return
|
||||
}
|
||||
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
||||
log("registerDataChange weight 秤重量小于${WEIGHT_RESET_RECOGNIZE}g")
|
||||
//检测到秤上没有东西
|
||||
presentation?.step1FoodRecognizing()
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -411,6 +419,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
super.registerDataChange()
|
||||
SensorScaleUtils.addWeightListener { value ->
|
||||
runOnUiThread {
|
||||
if (foodRecognizeState.not()) return@runOnUiThread
|
||||
readWeight(value)
|
||||
}
|
||||
}
|
||||
@@ -426,7 +435,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
|
||||
if (weight <= WEIGHT_RESET_RECOGNIZE) {
|
||||
log("registerDataChange weight recognizeByWeight---00002,秤重未超过${WEIGHT_RESET_RECOGNIZE}克")
|
||||
//检测到秤上没有东西,重新启动识别菜品 && presentation?.mealPickupMode == 1
|
||||
//检测到秤上没有东西,重新启动识别菜品
|
||||
isRecognitionFood = true
|
||||
return
|
||||
}
|
||||
@@ -439,11 +448,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
debouncer.debounce {
|
||||
log("registerDataChange weight recognizeByWeight---00004--recognizeFood")
|
||||
//保存当前重量
|
||||
currentWeight = weight
|
||||
recognizeFood()
|
||||
if (presentation?.mealPickupMode == 0) {
|
||||
log("registerDataChange weight recognizeByWeight---00004--recognizeFood,mealPickupMode == 0")
|
||||
lastWeight = weight
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log("registerDataChange weight recognizeByWeight---block")
|
||||
@@ -457,10 +464,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
recognizeFood()
|
||||
}
|
||||
}
|
||||
lastWeight = weight
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var startTime = 0L
|
||||
|
||||
fun recognizeFood() {
|
||||
@@ -500,18 +507,27 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
*/
|
||||
private var failCount = 0
|
||||
|
||||
/**
|
||||
* 是否进行识别:true-识别,false-不识别,默认开启识别
|
||||
*/
|
||||
private var foodRecognizeState = true
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun updateFoodInfo(list: MutableList<FoodInfo>, scoreList: List<IdNameScore>) {
|
||||
val queryData = GsonUtils.toJson(list)
|
||||
val recData = GsonUtils.toJson(scoreList)
|
||||
log("registerDataChange识别后查询接口数据:$queryData,识别数据:$recData")
|
||||
if (list.isEmpty()) {
|
||||
foodRecognizeState = false
|
||||
binding.tvToSearch.let {
|
||||
it.text = "未查询到,手动搜索"
|
||||
it.visible()
|
||||
}
|
||||
return
|
||||
}
|
||||
foodRecognizeState = true
|
||||
//查询到菜品信息,同步设置lastWeight=currentWeight
|
||||
lastWeight=currentWeight
|
||||
list.forEach { foodInfo ->
|
||||
val scoreItem = scoreList.firstOrNull { it.name == foodInfo.foodName }
|
||||
val score = scoreItem?.score ?: 0.0
|
||||
@@ -526,7 +542,6 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
// list
|
||||
// }
|
||||
|
||||
|
||||
adapter.submitList(list)
|
||||
binding.recyclerview.visible()
|
||||
|
||||
@@ -720,6 +735,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
binding.previewView.visible()
|
||||
binding.ivImg.gone()
|
||||
checkedItem = null
|
||||
lastWeight = 0
|
||||
foodRecognizeState = true
|
||||
}
|
||||
|
||||
private fun updateDateTime() {
|
||||
@@ -886,8 +903,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
}
|
||||
|
||||
fun getEatNum(realWeight: Double?, specWeight: Double?): Int {
|
||||
if (realWeight == null || realWeight <= 0.0 || specWeight == null || specWeight <= 0.0) return 0
|
||||
return (realWeight / specWeight).roundToInt()
|
||||
if (realWeight == null || realWeight <= 0.0 || specWeight == null || specWeight <= 0.0) {
|
||||
log("getEatNum:realWeight=$realWeight,specWeight=$specWeight")
|
||||
return 0
|
||||
}
|
||||
val eatNum = (realWeight / specWeight).roundToInt()
|
||||
log("getEatNum:eatNum=$eatNum,realWeight=$realWeight,specWeight=$specWeight,realWeight/$specWeight=${realWeight / specWeight}}")
|
||||
return eatNum;
|
||||
}
|
||||
|
||||
private var foodOrderId: String = ""
|
||||
@@ -955,6 +977,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
// }
|
||||
|
||||
private fun clickPayButton() {
|
||||
log("eatWeight:recognizeWeight=$recognizeWeight, currentWeight=$currentWeight, lastWeight=$lastWeight")
|
||||
if (checkedItem == null) {
|
||||
ToastUtils.showToast("暂无识别数据,请搜索选择")
|
||||
return
|
||||
@@ -971,13 +994,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
//计费
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
eatWeight = lastWeight
|
||||
foodWeight = lastWeight
|
||||
eatWeight = currentWeight
|
||||
foodWeight = currentWeight
|
||||
} else {
|
||||
//余量计量
|
||||
eatWeight = recognizeWeight - lastWeight
|
||||
eatWeight = recognizeWeight - currentWeight
|
||||
foodWeight = recognizeWeight
|
||||
log("eatWeight=$eatWeight, recognizeWeight=$recognizeWeight, lastWeight=$lastWeight")
|
||||
log("eatWeight=$eatWeight, recognizeWeight=$recognizeWeight, currentWeight=$currentWeight, lastWeight=$lastWeight")
|
||||
}
|
||||
} else {
|
||||
//不计费
|
||||
@@ -987,7 +1010,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
||||
recognizeWeight
|
||||
} else {
|
||||
//余量计量
|
||||
recognizeWeight - lastWeight
|
||||
recognizeWeight - currentWeight
|
||||
}
|
||||
}
|
||||
val eatNum = getEatNum(eatWeight.toDouble(), checkedItem!!.specWeight)
|
||||
|
||||
Reference in New Issue
Block a user