|
@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.google.common.collect.Lists; |
|
|
import com.google.common.collect.Maps; |
|
|
import com.google.common.collect.Maps; |
|
|
import com.google.common.collect.Range; |
|
|
import com.google.common.collect.Range; |
|
|
|
|
|
import com.mathvision.diet.domian.MealType; |
|
|
import com.mathvision.diet.domian.MeasurementType; |
|
|
import com.mathvision.diet.domian.MeasurementType; |
|
|
import com.mathvision.diet.domian.MenuDishItemDTO; |
|
|
import com.mathvision.diet.domian.MenuDishItemDTO; |
|
|
import com.mathvision.diet.domian.RuleItemDTO; |
|
|
import com.mathvision.diet.domian.RuleItemDTO; |
|
@ -36,8 +37,11 @@ public class MenuReportService { |
|
|
@Resource |
|
|
@Resource |
|
|
IngredientService ingredientService; |
|
|
IngredientService ingredientService; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
|
VenderService venderService; |
|
|
|
|
|
|
|
|
public JSONObject nutrition(Menu menu, long day, String crow, List<MenuDish> dishes) { |
|
|
public JSONObject nutrition(Menu menu, long day, String crow, List<MenuDish> dishes) { |
|
|
Nutrition nutrition = nutritionService.get(menu.getNutrient()); |
|
|
Nutrition nutrition = getNutrition(menu); |
|
|
BigDecimal overflow = nutrition.getOverflow(); |
|
|
BigDecimal overflow = nutrition.getOverflow(); |
|
|
Map<String, Map<String, BigDecimal>> itemStandard = nutrition.getIngredient().getOrDefault(crow, new HashMap<>()); |
|
|
Map<String, Map<String, BigDecimal>> itemStandard = nutrition.getIngredient().getOrDefault(crow, new HashMap<>()); |
|
|
Map<String, Ingredient> ingredientMap = ingredientService.getFullByKeys(dishes.stream().filter(x -> CollectionUtils.isNotEmpty(x.getIngredient())).flatMap(x -> x.getIngredient().stream().map(MenuDishItemDTO::getKey)).collect(Collectors.toSet())).stream().collect(Collectors.toMap(Ingredient::getKey, v -> v)); |
|
|
Map<String, Ingredient> ingredientMap = ingredientService.getFullByKeys(dishes.stream().filter(x -> CollectionUtils.isNotEmpty(x.getIngredient())).flatMap(x -> x.getIngredient().stream().map(MenuDishItemDTO::getKey)).collect(Collectors.toSet())).stream().collect(Collectors.toMap(Ingredient::getKey, v -> v)); |
|
@ -148,7 +152,7 @@ public class MenuReportService { |
|
|
|
|
|
|
|
|
public JSONObject types(Menu menu, String crow, List<MenuDish> dishes) { |
|
|
public JSONObject types(Menu menu, String crow, List<MenuDish> dishes) { |
|
|
dishes = dishes.stream().filter(menuDish -> menuDish.getIngredient().stream().anyMatch(item -> item.getValue().containsKey(crow))).collect(Collectors.toList()); |
|
|
dishes = dishes.stream().filter(menuDish -> menuDish.getIngredient().stream().anyMatch(item -> item.getValue().containsKey(crow))).collect(Collectors.toList()); |
|
|
Nutrition nutrition = nutritionService.get(menu.getNutrient()); |
|
|
Nutrition nutrition = getNutrition(menu); |
|
|
|
|
|
|
|
|
List<RuleItemDTO> dayStandard = nutrition.getFoodCategoryDay(); |
|
|
List<RuleItemDTO> dayStandard = nutrition.getFoodCategoryDay(); |
|
|
List<RuleItemDTO> weekStandard = nutrition.getFoodCategoryWeek(); |
|
|
List<RuleItemDTO> weekStandard = nutrition.getFoodCategoryWeek(); |
|
@ -287,6 +291,30 @@ public class MenuReportService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Nutrition getNutrition(Menu menu) { |
|
|
|
|
|
Nutrition nutrition = nutritionService.get(menu.getNutrient()); |
|
|
|
|
|
if (CollectionUtils.isNotEmpty(menu.getMeals())) { |
|
|
|
|
|
if (MealType.values().length > menu.getMeals().size()) { |
|
|
|
|
|
VenderConfig config = venderService.queryConfig(menu.getVender()); |
|
|
|
|
|
BigDecimal scale = menu.getMeals().stream().map(MealType::toType).distinct().map(x -> { |
|
|
|
|
|
switch (x) { |
|
|
|
|
|
case breakfast: return config.getBreakfast(); |
|
|
|
|
|
case lunch: return config.getLunch(); |
|
|
|
|
|
case dinner: return config.getDinner(); |
|
|
|
|
|
default: return BigDecimal.ZERO; |
|
|
|
|
|
} |
|
|
|
|
|
}).reduce(BigDecimal::add).orElse(BigDecimal.ZERO); |
|
|
|
|
|
|
|
|
|
|
|
if (scale.intValue() < 100) { |
|
|
|
|
|
Map<String, Map<String, Map<String, BigDecimal>>> ingredient = nutrition.getIngredient(); |
|
|
|
|
|
ingredient.forEach((crow, value) -> value.forEach((nutrient, items) -> items.forEach((k, v) -> ingredient.get(crow).get(nutrient).put(k, v.multiply(scale).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP))))); |
|
|
|
|
|
nutrition.setIngredient(ingredient); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return nutrition; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private static BigDecimal calculatePercentage(BigDecimal value, BigDecimal base) { |
|
|
private static BigDecimal calculatePercentage(BigDecimal value, BigDecimal base) { |
|
|
BigDecimal percentage = value.subtract(base).divide(base, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); |
|
|
BigDecimal percentage = value.subtract(base).divide(base, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); |
|
|
return percentage.setScale(2, RoundingMode.HALF_UP); |
|
|
return percentage.setScale(2, RoundingMode.HALF_UP); |
|
|