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)
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.sw.dualscreen.model.response.UserEnergy
|
||||
import com.sw.dualscreen.model.response.UserNutrition
|
||||
import com.sw.dualscreen.utils.Debouncer
|
||||
import com.sw.dualscreen.utils.SPUtil
|
||||
import com.sw.dualscreen.utils.countDownByFlow
|
||||
import com.sw.dualscreen.viewmodel.UserViewModel
|
||||
import com.sw.plate.utils.LightManager
|
||||
import com.sw.plate.utils.ToastUtils
|
||||
@@ -59,6 +60,7 @@ import com.sw.plate.utils.arcface.face.model.CompareResult
|
||||
import com.sw.plate.utils.arcface.face.model.FacePreviewInfo
|
||||
import com.sw.plate.utils.arcface.face.model.RecognizeConfiguration
|
||||
import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
@@ -75,7 +77,7 @@ class MainScreenPresentation(
|
||||
) : Presentation(activity, display), ViewTreeObserver.OnGlobalLayoutListener {
|
||||
|
||||
companion object {
|
||||
const val TAG = "SubScreenPresentation"
|
||||
const val TAG = "MainScreenPresentation"
|
||||
}
|
||||
|
||||
private lateinit var binding: PresentationMainScreenBinding
|
||||
@@ -144,55 +146,55 @@ class MainScreenPresentation(
|
||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
//0-计费,1-不计费
|
||||
val chargeMode = SPUtil.getInstance().get(GlobalKey.KEY_CHARGE_MODE, 0)
|
||||
// if (mealPickupMode == 1 && chargeMode == 0) {
|
||||
// //余量计量+计费模式
|
||||
// if (isFirstGetWeight && lastWeight > 5) {
|
||||
// recognitionWeight = lastWeight
|
||||
// isFirstGetWeight = false
|
||||
// }
|
||||
// if (lastWeight > 5) {
|
||||
// //余量计量,有重量的情况下不回到重新识别状态
|
||||
// return
|
||||
// }
|
||||
// isFirstGetWeight = true
|
||||
// }
|
||||
if (currentStep == 2 && lastWeight <= MainActivity.WEIGHT_RESET_RECOGNIZE && isGoStep1) {
|
||||
//人脸识别过程中,秤上物品拿走
|
||||
isGoStep1 = false
|
||||
activity.runOnUiThread {
|
||||
Timber.tag(TAG).e("切回step1")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000000")
|
||||
step1FoodRecognizing()
|
||||
}
|
||||
} else if (lastWeight <= MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||
isGoStep1 = false
|
||||
activity.runOnUiThread {
|
||||
Timber.tag(TAG).e("切回step1")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000001")
|
||||
if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
step1FoodRecognizing()
|
||||
} else {
|
||||
//秤上菜品不足,请补充
|
||||
if (currentStep == 1 && currentFood == null) {
|
||||
return@runOnUiThread
|
||||
}
|
||||
//余量计量
|
||||
if (countDownResetJob == null) {
|
||||
countDownResetJob = countDownByFlow(
|
||||
total = 30,
|
||||
scope = activity.lifecycleScope,
|
||||
onStart = {},
|
||||
onTick = { seconds ->
|
||||
Timber.tag(TAG).e("余量计量模型秤重量已清空,等待${seconds}秒后继续重置识别状态")
|
||||
if (lastWeight > MainActivity.WEIGHT_RESET_RECOGNIZE) {
|
||||
countDownResetJob?.cancel()
|
||||
}
|
||||
},
|
||||
onFinish = {
|
||||
step1FoodRecognizing()
|
||||
countDownResetJob?.cancel()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if (currentStep != 3) {
|
||||
// return
|
||||
// }
|
||||
if (currentFood == null) {
|
||||
Timber.tag(TAG).e("updateWeight currentFood is null")
|
||||
return
|
||||
}
|
||||
|
||||
//if (userNutritionData == null) {
|
||||
if (userNutrition == null) {
|
||||
Timber.tag(TAG).e("updateWeight userNutritionData is null")
|
||||
return
|
||||
}
|
||||
// if (dinnerTypeInfo == null) {
|
||||
// Timber.tag(TAG).e("updateWeight dinnerType is null")
|
||||
// return
|
||||
// }
|
||||
if (chargeMode == 1 || activity.settlementMode == 0) {
|
||||
//不计费或者联合支付模式更新营养热量数据
|
||||
if (mealPickupMode == 0) {
|
||||
@@ -205,6 +207,8 @@ class MainScreenPresentation(
|
||||
}
|
||||
}
|
||||
|
||||
private var countDownResetJob: Job? = null
|
||||
|
||||
fun setStepChangeCallback(callback: (Int) -> Unit) {
|
||||
stepChangeCallback = callback
|
||||
}
|
||||
@@ -518,7 +522,7 @@ class MainScreenPresentation(
|
||||
* 餐品识别中
|
||||
*/
|
||||
fun step1FoodRecognizing() {
|
||||
if (currentStep == 1) {
|
||||
if (currentStep == 1 && currentFood == null) {
|
||||
return
|
||||
}
|
||||
Timber.tag(TAG).d("main,step1,耗时:${System.currentTimeMillis() - startTime}")
|
||||
@@ -764,10 +768,7 @@ class MainScreenPresentation(
|
||||
}
|
||||
|
||||
private fun calculateNutrition(value: Int) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"addFoodToOrder: weight = $value, recognitionWeight = $recognitionWeight foodInfo = $currentFood"
|
||||
)
|
||||
Timber.tag(TAG) .d("calculateNutrition:weight=$value,recognitionWeight=$recognitionWeight,foodInfo=$currentFood")
|
||||
if (currentFood == null || userNutrition == null) {
|
||||
return
|
||||
}
|
||||
@@ -906,6 +907,7 @@ class MainScreenPresentation(
|
||||
*/
|
||||
fun updateMealPickupMode(mode: Int) {
|
||||
Timber.tag(TAG).d("updateMealPickupMode mode = $mode")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000003")
|
||||
mealPickupMode = mode
|
||||
step1FoodRecognizing()
|
||||
}
|
||||
@@ -1359,6 +1361,7 @@ class MainScreenPresentation(
|
||||
}
|
||||
} else {
|
||||
Timber.tag(TAG).d("drawPreviewInfo,successBlock,订单已生成,step1FoodRecognizing")
|
||||
Timber.tag(TAG).e("切回step1,------2000000000002")
|
||||
activity.isAnalyzing = false
|
||||
step1FoodRecognizing()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user