增加支付接口相关逻辑
This commit is contained in:
@@ -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.UserNutrition
|
||||
import com.sw.dualscreen.model.response.UserNutritionData
|
||||
import timber.log.Timber
|
||||
import kotlin.math.max
|
||||
@@ -16,62 +17,109 @@ object UserNutritionUtils {
|
||||
/**
|
||||
* 计算热量信息
|
||||
*/
|
||||
fun calculateNutrition(
|
||||
fun calculateNutrition2(
|
||||
foodInfo: FoodInfo,
|
||||
userModel: UserNutritionData,
|
||||
nutrition: UserNutrition,
|
||||
weight: Double,
|
||||
dinnerType: String
|
||||
): CalcResultInfo {
|
||||
|
||||
// 初始化变量
|
||||
var foodKcal = 0.0
|
||||
var totalKcal = 0.0
|
||||
var (vegetable, meat, fruits, grain) = List(4) { 0.0 }
|
||||
var (calorie, grain, fruitsVegetables, meatEggs) = List(4) { 0.0 }
|
||||
|
||||
// 处理食物信息
|
||||
foodKcal = calculateValue(foodInfo.stFoodInfoMaterial?.energyKcal, weight)
|
||||
Timber.d("calculateNutrition foodKcal = ${foodKcal}, energyKcal = ${foodInfo.stFoodInfoMaterial?.energyKcal}, weight = $weight")
|
||||
grain = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.grainValue(), weight)
|
||||
fruits = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.fruitsValue(), weight)
|
||||
vegetable = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.vegetableValue(), weight)
|
||||
meat = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.meatValue(), weight)
|
||||
calorie = calculateValue(foodInfo.calorie, weight)
|
||||
grain = calculateValue(foodInfo.stapleFood, weight)
|
||||
fruitsVegetables = calculateValue(foodInfo.fruitsVegetables, weight)
|
||||
meatEggs = calculateValue(foodInfo.meatEggs, weight)
|
||||
|
||||
// 合并用户数据
|
||||
grain += userModel.stFoodInfoPagoda?.grainValue() ?: 0.0
|
||||
calorie += nutrition.calorie ?: 0.0
|
||||
grain += nutrition.stapleFood ?: 0.0
|
||||
fruitsVegetables += nutrition.fruitsVegetables ?: 0.0
|
||||
meatEggs += nutrition.meatEggs ?: 0.0
|
||||
|
||||
fruits += userModel.stFoodInfoPagoda?.fruitsValue() ?: 0.0
|
||||
vegetable = vegetable.plus(userModel.stFoodInfoPagoda?.vegetableValue() ?: 0.0)
|
||||
meat += userModel.stFoodInfoPagoda?.meatValue() ?: 0.0
|
||||
|
||||
totalKcal = foodKcal + userModel.energyValue()
|
||||
Timber.d("calculateNutrition totalKcal = ${totalKcal}, energyValue = ${userModel.energyValue()}")
|
||||
if (totalKcal < 0){
|
||||
totalKcal = 0.0
|
||||
}
|
||||
totalKcal = max(calorie, 0.0)
|
||||
// 判断当餐最大热量
|
||||
val maxKcal =
|
||||
userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
|
||||
Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
|
||||
val pagoda = userModel.stFoodInfoPagoda
|
||||
val fruitsInfo = parseRecommend(pagoda?.fruitsRecommend, fruits)
|
||||
val vegetableInfo = parseRecommend(pagoda?.vegetableRecommend, vegetable)
|
||||
//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(pagoda?.grainRecommend, grain),
|
||||
fruits = CalcInfo( // 果蔬 = 水果+蔬菜
|
||||
max = fruitsInfo.max + vegetableInfo.max,
|
||||
min = fruitsInfo.min + vegetableInfo.min,
|
||||
current = fruitsInfo.current + vegetableInfo.current
|
||||
),
|
||||
meat = parseRecommend(pagoda?.meatRecommend, meat)
|
||||
grain = parseRecommend(grainRecommend, grain),
|
||||
fruits = parseRecommend(fruitsRecommend, fruitsVegetables),
|
||||
meat = parseRecommend(meatRecommend, meatEggs)
|
||||
)
|
||||
return calcResult
|
||||
}
|
||||
|
||||
// fun calculateNutrition(
|
||||
// foodInfo: FoodInfo,
|
||||
// userModel: UserNutritionData,
|
||||
//// userModel: UserNutrition,
|
||||
// weight: Double,
|
||||
// dinnerType: String
|
||||
// ): CalcResultInfo {
|
||||
//
|
||||
// // 初始化变量
|
||||
// var foodKcal = 0.0
|
||||
// var totalKcal = 0.0
|
||||
// var (vegetable, meat, fruits, grain) = List(4) { 0.0 }
|
||||
//
|
||||
// // 处理食物信息
|
||||
// foodKcal = calculateValue(foodInfo.stFoodInfoMaterial?.energyKcal, weight)
|
||||
// Timber.d("calculateNutrition foodKcal = ${foodKcal}, energyKcal = ${foodInfo.stFoodInfoMaterial?.energyKcal}, weight = $weight")
|
||||
// grain = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.grainValue(), weight)
|
||||
// fruits = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.fruitsValue(), weight)
|
||||
// vegetable = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.vegetableValue(), weight)
|
||||
// meat = calculateValue(foodInfo.stFoodInfoPagodaAPPVO?.meatValue(), weight)
|
||||
//
|
||||
// // 合并用户数据
|
||||
// grain += userModel.stFoodInfoPagoda?.grainValue() ?: 0.0
|
||||
//
|
||||
// fruits += userModel.stFoodInfoPagoda?.fruitsValue() ?: 0.0
|
||||
// vegetable = vegetable.plus(userModel.stFoodInfoPagoda?.vegetableValue() ?: 0.0)
|
||||
// meat += userModel.stFoodInfoPagoda?.meatValue() ?: 0.0
|
||||
//
|
||||
// totalKcal = foodKcal + userModel.energyValue()
|
||||
// Timber.d("calculateNutrition totalKcal = ${totalKcal}, energyValue = ${userModel.energyValue()}")
|
||||
// if (totalKcal < 0) {
|
||||
// totalKcal = 0.0
|
||||
// }
|
||||
// // 判断当餐最大热量
|
||||
// val maxKcal =
|
||||
// userModel.totalEnergyCalculateScoreValue() * calculateDinnerTypeRatio(dinnerType) / 10
|
||||
// Timber.d("calculateNutrition maxKcal = ${maxKcal}, CalculateScoreValue = ${userModel.totalEnergyCalculateScoreValue()}")
|
||||
// val pagoda = userModel.stFoodInfoPagoda
|
||||
// val fruitsInfo = parseRecommend(pagoda?.fruitsRecommend, fruits)
|
||||
// val vegetableInfo = parseRecommend(pagoda?.vegetableRecommend, vegetable)
|
||||
// val calcResult = CalcResultInfo(
|
||||
// totalKcal = CalcInfo(
|
||||
// max = maxKcal,
|
||||
// min = 0.0,
|
||||
// current = totalKcal
|
||||
// ),
|
||||
// grain = parseRecommend(pagoda?.grainRecommend, grain),
|
||||
// fruits = CalcInfo( // 果蔬 = 水果+蔬菜
|
||||
// max = fruitsInfo.max + vegetableInfo.max,
|
||||
// min = fruitsInfo.min + vegetableInfo.min,
|
||||
// current = fruitsInfo.current + vegetableInfo.current
|
||||
// ),
|
||||
// meat = parseRecommend(pagoda?.meatRecommend, meat)
|
||||
// )
|
||||
// return calcResult
|
||||
// }
|
||||
|
||||
fun parseRecommend(recommend: String?, current: Double): CalcInfo {
|
||||
var newCurrent = if (current < 0) 0.0 else current
|
||||
if (TextUtils.isEmpty(recommend) || !recommend!!.contains("-")) {
|
||||
|
||||
Reference in New Issue
Block a user