营养接口调试、支付接口联调
This commit is contained in:
@@ -34,6 +34,7 @@ import com.sw.dualscreen.ext.visible
|
||||
import com.sw.dualscreen.model.request.UserNutritionParam
|
||||
import com.sw.dualscreen.model.response.DinnerType
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.UserEnergy
|
||||
import com.sw.dualscreen.model.response.UserNutrition
|
||||
import com.sw.dualscreen.model.response.UserNutritionData
|
||||
import com.sw.dualscreen.utils.Debouncer
|
||||
@@ -91,14 +92,14 @@ class MainScreenPresentation(
|
||||
private var irFaceRectTransformer: FaceRectTransformer? = null
|
||||
|
||||
private var detectWeight = 0.0 //识别菜品时的重量
|
||||
private var lastWeight = 0.0 // 上一次的计算热量结果
|
||||
var lastWeight = 0.0 // 上一次的计算热量结果
|
||||
|
||||
// private var userNutritionData: UserNutritionData? = null
|
||||
private var userNutrition: UserNutrition? = null
|
||||
private var dinnerTypeInfo: DinnerType? = null
|
||||
private val debouncer = Debouncer(500)
|
||||
private var recognitionTime: Long = 0L // 人脸识别时的时间
|
||||
private var recognitionWeight: Double = 0.0 // 人脸识别时的重量
|
||||
var recognitionWeight: Double = 0.0 // 人脸识别时的重量
|
||||
|
||||
private var lastFaceTrackId: Int = -1 // 上一次的人脸信息
|
||||
var mealPickupMode: Int = 0 // 取餐模式 0 即放即取 1 余量取餐
|
||||
@@ -342,7 +343,7 @@ class MainScreenPresentation(
|
||||
/**
|
||||
* 餐品识别成功,不计费模式
|
||||
*/
|
||||
fun loadUnbilledMode(nutrition: UserNutrition) {
|
||||
fun loadUnbilledMode() {
|
||||
binding.calorieInclude.root.gone()
|
||||
binding.nutritionInclude.root.visible()
|
||||
|
||||
@@ -354,9 +355,9 @@ class MainScreenPresentation(
|
||||
//binding.ivRecImage.gone()
|
||||
|
||||
//updateFoodInfo(foodInfo)
|
||||
binding.nutritionInclude.tvUserName.text = nutrition.name.maskName()
|
||||
binding.nutritionInclude.tvUserName.text = userNutrition?.name.maskName()
|
||||
binding.nutritionInclude.tvRecommendHeat.text =
|
||||
"推荐热量:${nutrition.recommendEnergy ?: 0}kcal"
|
||||
"推荐热量:${userNutrition?.recommendCalorie.format2String(2)}kcal"
|
||||
//updateWeight(lastWeight / 1000)
|
||||
// -------------------------------------------------
|
||||
// 删除userNutritionData,改为userNutrition
|
||||
@@ -524,100 +525,107 @@ class MainScreenPresentation(
|
||||
val dinnerType = dinnerTypeInfo!!.dinnerType!!
|
||||
// Timber.tag(TAG)
|
||||
// .d("calculateNutrition foodName = ${currentFood!!.foodName}, dinnerType = $dinnerType, userId = ${userNutritionData!!.userId}")
|
||||
val calcResultInfo = UserNutritionUtils.calculateNutrition2(
|
||||
val energy: UserEnergy = UserNutritionUtils.calculateNutrition2(
|
||||
currentFood!!,
|
||||
// userNutritionData!!,
|
||||
userNutrition!!,
|
||||
weight,
|
||||
dinnerType = dinnerType
|
||||
)
|
||||
Timber.tag(TAG).d("calculateNutrition calcResultInfo = $calcResultInfo")
|
||||
val columnMax = UserNutritionUtils.getMaxInt(calcResultInfo)
|
||||
// Timber.tag(TAG).d("calculateNutrition calcResultInfo = $calcResultInfo")
|
||||
// val columnMax = UserNutritionUtils.getMaxInt(calcResultInfo)
|
||||
var columnMax = max(energy.grain, energy.fruitsVegetables)
|
||||
columnMax = max(columnMax, energy.meatEggs)
|
||||
|
||||
activity.runOnUiThread {
|
||||
val totalKcal = calcResultInfo.totalKcal
|
||||
val grain = calcResultInfo.grain
|
||||
val fruits = calcResultInfo.fruits
|
||||
val meat = calcResultInfo.meat
|
||||
// 设置热量
|
||||
binding.nutritionInclude.customKcalColumn.setImageDrawable(
|
||||
true,
|
||||
totalKcal.max < totalKcal.current
|
||||
)
|
||||
var maxKcal = totalKcal.max
|
||||
val totalKcal = energy.calorie
|
||||
val grain = energy.grain
|
||||
val fruitsVegetables = energy.fruitsVegetables
|
||||
val meatEggs = energy.meatEggs
|
||||
|
||||
val include = binding.nutritionInclude
|
||||
|
||||
// 设置热量---------------------------------------------------------------------
|
||||
val calorieArray = doubleArrayOf(
|
||||
0.0,
|
||||
userNutrition?.minCalorie?:0.0,
|
||||
userNutrition?.recommendCalorie?:0.0,
|
||||
((userNutrition?.recommendCalorie?:0.0) + (userNutrition?.maxCalorie?:0.0))/2,
|
||||
userNutrition?.maxCalorie?:0.0,
|
||||
)
|
||||
val calorieIndex = UserNutritionUtils.findCalorieIndex(energy.grain, calorieArray)
|
||||
include.customKcalColumn.setImageDrawable(true, calorieIndex)
|
||||
var maxKcal = userNutrition?.maxCalorie?:1.0
|
||||
Timber.tag(TAG).d("maxKcal = $maxKcal")
|
||||
// 避免0作为被除数
|
||||
if (maxKcal <= 0.0) {
|
||||
maxKcal = 1.0
|
||||
}
|
||||
Timber.tag(TAG).d("maxKcal 1 = $maxKcal")
|
||||
binding.nutritionInclude.totalKcalTv.text = totalKcal.current.format2String()
|
||||
var totalKcalHeight = (totalKcal.current / maxKcal).toFloat()
|
||||
include.totalKcalTv.text = totalKcal.format2String(2)
|
||||
var totalKcalHeight = (totalKcal / maxKcal).toFloat()
|
||||
if (totalKcalHeight == 0F) {
|
||||
binding.nutritionInclude.divKcalView.visibility = View.VISIBLE
|
||||
include.divKcalView.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.nutritionInclude.divKcalView.visibility = View.GONE
|
||||
include.divKcalView.visibility = View.GONE
|
||||
totalKcalHeight += 0.1F
|
||||
}
|
||||
binding.nutritionInclude.customKcalColumn.setCustomHeightPercent(
|
||||
totalKcalHeight,
|
||||
true
|
||||
)
|
||||
include.customKcalColumn.setCustomHeightPercent(totalKcalHeight, true)
|
||||
|
||||
// 设置主食
|
||||
binding.nutritionInclude.customFoodColumn.setImageDrawable(
|
||||
false,
|
||||
grain.max < grain.current
|
||||
// 设置主食-----------------------------------------------------------
|
||||
val grainArray = UserNutritionUtils.getCalorieArray(
|
||||
left = userNutrition?.stapleFoodRecommend,
|
||||
mid = userNutrition?.stapleFoodNearExcess,
|
||||
right = userNutrition?.stapleFoodExcess
|
||||
)
|
||||
binding.nutritionInclude.totalFoodTv.text = grain.current.format2String()
|
||||
var grainHeight = (grain.current / columnMax).toFloat()
|
||||
val grainIndex = UserNutritionUtils.findCalorieIndex(energy.grain, grainArray)
|
||||
include.customFoodColumn.setImageDrawable(false, grainIndex)
|
||||
include.totalFoodTv.text = grain.format2String(2)
|
||||
var grainHeight = (grain / columnMax).toFloat()
|
||||
if (grainHeight == 0F) {
|
||||
binding.nutritionInclude.divTotalFoodView.visibility = View.VISIBLE
|
||||
include.divTotalFoodView.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.nutritionInclude.divTotalFoodView.visibility = View.GONE
|
||||
include.divTotalFoodView.visibility = View.GONE
|
||||
grainHeight += 0.1F
|
||||
}
|
||||
binding.nutritionInclude.customFoodColumn.setCustomHeightPercent(
|
||||
grainHeight,
|
||||
true
|
||||
)
|
||||
include.customFoodColumn.setCustomHeightPercent(grainHeight, true)
|
||||
|
||||
// 设置果蔬
|
||||
binding.nutritionInclude.customVegetableColumn.setImageDrawable(
|
||||
false,
|
||||
fruits.max < fruits.current
|
||||
// 设置果蔬-------------------------------------------------------------
|
||||
val fruitsArray = UserNutritionUtils.getCalorieArray(
|
||||
left = userNutrition?.fruitsVegetablesRecommend,
|
||||
mid = userNutrition?.fruitsVegetablesNearExcess,
|
||||
right = userNutrition?.fruitsVegetablesExcess
|
||||
)
|
||||
binding.nutritionInclude.totalVegetableTv.text = fruits.current.format2String()
|
||||
var fruitsHeight = (fruits.current / columnMax).toFloat()
|
||||
val fruitsIndex = UserNutritionUtils.findCalorieIndex(energy.fruitsVegetables, fruitsArray)
|
||||
include.customVegetableColumn.setImageDrawable(false, fruitsIndex)
|
||||
include.totalVegetableTv.text = fruitsVegetables.format2String(2)
|
||||
var fruitsHeight = (fruitsVegetables / columnMax).toFloat()
|
||||
|
||||
if (fruitsHeight == 0F) {
|
||||
binding.nutritionInclude.divVegetableView.visibility = View.VISIBLE
|
||||
include.divVegetableView.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.nutritionInclude.divVegetableView.visibility = View.GONE
|
||||
include.divVegetableView.visibility = View.GONE
|
||||
fruitsHeight += 0.1F
|
||||
}
|
||||
binding.nutritionInclude.customVegetableColumn.setCustomHeightPercent(
|
||||
fruitsHeight,
|
||||
true
|
||||
)
|
||||
include.customVegetableColumn.setCustomHeightPercent(fruitsHeight, true)
|
||||
|
||||
// 设置肉蛋
|
||||
binding.nutritionInclude.customMeatColumn.setImageDrawable(
|
||||
false,
|
||||
meat.max < meat.current
|
||||
// 设置肉蛋-----------------------------------------------------------
|
||||
val meatEggsArray = UserNutritionUtils.getCalorieArray(
|
||||
left = userNutrition?.meatEggsRecommend,
|
||||
mid = userNutrition?.meatEggsNearExcess,
|
||||
right = userNutrition?.meatEggsExcess
|
||||
)
|
||||
binding.nutritionInclude.totalMeatTv.text = meat.current.format2String()
|
||||
var meatHeight = (meat.current / columnMax).toFloat()
|
||||
val meatEggsIndex = UserNutritionUtils.findCalorieIndex(energy.meatEggs, meatEggsArray)
|
||||
include.customMeatColumn.setImageDrawable(false, meatEggsIndex)
|
||||
include.totalMeatTv.text = meatEggs.format2String(2)
|
||||
var meatHeight = (meatEggs / columnMax).toFloat()
|
||||
if (meatHeight == 0F) {
|
||||
binding.nutritionInclude.divMeatView.visibility = View.VISIBLE
|
||||
include.divMeatView.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.nutritionInclude.divMeatView.visibility = View.GONE
|
||||
include.divMeatView.visibility = View.GONE
|
||||
meatHeight += 0.1F
|
||||
}
|
||||
binding.nutritionInclude.customMeatColumn.setCustomHeightPercent(
|
||||
meatHeight,
|
||||
true
|
||||
)
|
||||
include.customMeatColumn.setCustomHeightPercent(meatHeight, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -718,7 +726,7 @@ class MainScreenPresentation(
|
||||
val faceEntity = compareResult.faceEntity
|
||||
val userId = faceEntity.userName
|
||||
if (userId == null) return@Observer
|
||||
ToastUtils.showToast("人脸识别成功,userId = $userId")
|
||||
//ToastUtils.showToast("人脸识别成功,userId = $userId")
|
||||
if (currentFood == null) {
|
||||
currentFood = activity.checkedItem
|
||||
}
|
||||
@@ -737,7 +745,7 @@ class MainScreenPresentation(
|
||||
return@runOnUiThread
|
||||
}
|
||||
this@MainScreenPresentation.userNutrition = nutrition
|
||||
loadUnbilledMode(nutrition)
|
||||
loadUnbilledMode()
|
||||
// -------------------------------
|
||||
}
|
||||
}
|
||||
@@ -1058,10 +1066,14 @@ class MainScreenPresentation(
|
||||
.d("postUserData userNutritionData = ${userNutrition == null}, currentFood = ${currentFood == null}")
|
||||
return
|
||||
}
|
||||
var eatWeight = 0.0
|
||||
eatWeight = if (mealPickupMode == 0) {
|
||||
createOrder()
|
||||
}
|
||||
|
||||
fun createOrder() {
|
||||
mealPickupMode = SPUtil.getInstance().get(GlobalKey.KEY_PICKUP_MODE, 0) ?: 0
|
||||
val eatWeight = if (mealPickupMode == 0) {
|
||||
//即放即取
|
||||
recognitionWeight - 0
|
||||
recognitionWeight
|
||||
} else {
|
||||
recognitionWeight - lastWeight
|
||||
}
|
||||
@@ -1084,4 +1096,5 @@ class MainScreenPresentation(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package com.sw.dualscreen.presentation
|
||||
import android.text.TextUtils
|
||||
import com.sw.dualscreen.ext.toSafeDouble
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.UserEnergy
|
||||
import com.sw.dualscreen.model.response.UserNutrition
|
||||
import com.sw.dualscreen.model.response.UserNutritionData
|
||||
import timber.log.Timber
|
||||
@@ -22,7 +23,7 @@ object UserNutritionUtils {
|
||||
nutrition: UserNutrition,
|
||||
weight: Double,
|
||||
dinnerType: String
|
||||
): CalcResultInfo {
|
||||
): UserEnergy {
|
||||
// 初始化变量
|
||||
var totalKcal = 0.0
|
||||
var (calorie, grain, fruitsVegetables, meatEggs) = List(4) { 0.0 }
|
||||
@@ -34,6 +35,7 @@ object UserNutritionUtils {
|
||||
meatEggs = calculateValue(foodInfo.meatEggs, weight)
|
||||
|
||||
// 合并用户数据
|
||||
//val maxKcal = (nutrition.calorie?:0.0) * calculateDinnerTypeRatio(dinnerType) / 10.0
|
||||
calorie += nutrition.calorie ?: 0.0
|
||||
grain += nutrition.stapleFood ?: 0.0
|
||||
fruitsVegetables += nutrition.fruitsVegetables ?: 0.0
|
||||
@@ -43,24 +45,22 @@ object UserNutritionUtils {
|
||||
// 判断当餐最大热量
|
||||
//val maxKcal = userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
|
||||
//Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
|
||||
// TODO: 测试数据-------------------------------
|
||||
val rate = calculateDinnerTypeRatio(dinnerType) / 10.0
|
||||
val maxKcal = totalKcal/ 0.26 / rate
|
||||
val grainRecommend = "0-100"
|
||||
val meatRecommend = "0-100"
|
||||
val fruitsRecommend = "0-100"
|
||||
// TODO: 测试数据-------------------------------
|
||||
val calcResult = CalcResultInfo(
|
||||
totalKcal = CalcInfo(
|
||||
max = maxKcal,
|
||||
min = 0.0,
|
||||
current = totalKcal
|
||||
),
|
||||
grain = parseRecommend(grainRecommend, grain),
|
||||
fruits = parseRecommend(fruitsRecommend, fruitsVegetables),
|
||||
meat = parseRecommend(meatRecommend, meatEggs)
|
||||
// val calcResult = CalcResultInfo(
|
||||
// totalKcal = CalcInfo(
|
||||
// max = maxKcal,
|
||||
// min = 0.0,
|
||||
// current = totalKcal
|
||||
// ),
|
||||
// grain = parseRecommend(foodInfo.stapleFoodRecommend, grain),
|
||||
// fruits = parseRecommend(foodInfo.fruitsVegetablesRecommend, fruitsVegetables),
|
||||
// meat = parseRecommend(foodInfo.meatEggsRecommend, meatEggs)
|
||||
// )
|
||||
return UserEnergy(
|
||||
calorie = totalKcal,
|
||||
grain = grain,
|
||||
fruitsVegetables = fruitsVegetables,
|
||||
meatEggs = meatEggs
|
||||
)
|
||||
return calcResult
|
||||
}
|
||||
|
||||
// fun calculateNutrition(
|
||||
@@ -121,7 +121,7 @@ object UserNutritionUtils {
|
||||
// }
|
||||
|
||||
fun parseRecommend(recommend: String?, current: Double): CalcInfo {
|
||||
var newCurrent = if (current < 0) 0.0 else current
|
||||
val newCurrent = if (current < 0) 0.0 else current
|
||||
if (TextUtils.isEmpty(recommend) || !recommend!!.contains("-")) {
|
||||
Timber.e("parseRecommend recommend 格式错误")
|
||||
return CalcInfo(
|
||||
@@ -154,6 +154,36 @@ object UserNutritionUtils {
|
||||
return max(max1, calcResultInfo.meat.max).toInt()
|
||||
}
|
||||
|
||||
fun getCalorieArray(left:String?, mid:String?, right: String?):DoubleArray {
|
||||
val leftArray = (left?.ifBlank { "0-0" } ?: "0-0").split("-").map { it.toSafeDouble() }
|
||||
val midArray = (mid?.ifBlank { "0-0" } ?: "0-0").split("-").map { it.toSafeDouble() }
|
||||
val rightArray = (right?.ifBlank { "0-0" } ?: "0-0").split("-").map { it.toSafeDouble() }
|
||||
return doubleArrayOf(
|
||||
0.0, leftArray[0], midArray[0], rightArray[0], rightArray[1]
|
||||
)
|
||||
}
|
||||
|
||||
fun findCalorieIndex(num: Double, array: DoubleArray): Int {
|
||||
if (array.isEmpty()) return 0
|
||||
if (num < array[0]) return 0
|
||||
if (num >= array[array.lastIndex]) return array.lastIndex
|
||||
|
||||
var left = 0
|
||||
var right = array.lastIndex
|
||||
while (left < right) {
|
||||
val mid = left + (right - left) / 2
|
||||
if (array[mid] <= num && num < array[mid + 1]) {
|
||||
return mid
|
||||
} else if (num < array[mid]) {
|
||||
right = mid
|
||||
} else {
|
||||
left = mid + 1
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
data class CalcInfo(
|
||||
var max: Double,
|
||||
var min: Double,
|
||||
|
||||
@@ -248,8 +248,10 @@ class FacePayPresentation(
|
||||
// recognitionWeight = lastWeight
|
||||
lastFaceTrackId = compareResult.trackId
|
||||
val faceEntity = compareResult.faceEntity
|
||||
val userId = faceEntity.userName
|
||||
var userId = faceEntity.userName
|
||||
if (userId == null) return@Observer
|
||||
// TODO: 测试支付用户id
|
||||
userId = "1987710988425662466"
|
||||
faceRecSuccess(userId)
|
||||
})
|
||||
|
||||
@@ -601,6 +603,7 @@ class FacePayPresentation(
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
activity.showPayInfo(type = 1, isVip = true, memberInfo = memberInfo)
|
||||
activity.hidePayTab()
|
||||
binding.root.postDelayed({
|
||||
dismiss()
|
||||
}, 500)
|
||||
|
||||
Reference in New Issue
Block a user