|
@ -9,6 +9,7 @@ import com.mathvision.diet.domian.MenuDishItemDTO; |
|
|
import com.mathvision.diet.entity.*; |
|
|
import com.mathvision.diet.entity.*; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
import org.apache.commons.collections4.CollectionUtils; |
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
import org.apache.commons.lang3.tuple.Pair; |
|
|
import org.apache.commons.lang3.tuple.Pair; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
@ -134,7 +135,8 @@ public class MenuReportService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public JSONObject types(Menu menu, 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()); |
|
|
Nutrition nutrition = nutritionService.get(menu.getNutrient()); |
|
|
Nutrition nutrition = nutritionService.get(menu.getNutrient()); |
|
|
Map<String, BigDecimal> dayStandard = nutrition.getFoodCategoryDay(); |
|
|
Map<String, BigDecimal> dayStandard = nutrition.getFoodCategoryDay(); |
|
|
Map<String, BigDecimal> weekStandard = nutrition.getFoodCategoryWeek(); |
|
|
Map<String, BigDecimal> weekStandard = nutrition.getFoodCategoryWeek(); |
|
@ -171,11 +173,22 @@ public class MenuReportService { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
result.put("crow", crow); |
|
|
result.put("dayRule", dayRule); |
|
|
result.put("dayRule", dayRule); |
|
|
result.put("weekRule", weekRule); |
|
|
result.put("weekRule", weekRule); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JSONObject poly(String crow, List<MenuDish> dishes) { |
|
|
|
|
|
dishes = dishes.stream().filter(menuDish -> menuDish.getIngredient().stream().anyMatch(item -> item.getValue().containsKey(crow))).collect(Collectors.toList()); |
|
|
|
|
|
Map<String, List<MenuDish>> data = dishes.stream().collect(Collectors.groupingBy(MenuDish::getPoly)); |
|
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
result.put("crow", crow); |
|
|
|
|
|
result.put("0", data.entrySet().stream().map(x -> Pair.of(x.getKey(), x.getValue().size())).collect(Collectors.toMap(Pair::getKey, Pair::getValue))); |
|
|
|
|
|
dishes.stream().collect(Collectors.groupingBy(MenuDish::getDay, Collectors.groupingBy(MenuDish::getPoly))).forEach((k, v) -> result.put(k.toString(), v.entrySet().stream().map(x -> Pair.of(x.getKey(), x.getValue().size())).collect(Collectors.toMap(Pair::getKey, Pair::getValue)))); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public JSONObject energy(long day, String crow, List<MenuDish> dishes) { |
|
|
public JSONObject energy(long day, String crow, List<MenuDish> dishes) { |
|
|
List<String> allConcerned= Lists.newArrayList("energy", "protein", "fat", "carbs"); |
|
|
List<String> allConcerned= Lists.newArrayList("energy", "protein", "fat", "carbs"); |
|
|
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)); |
|
|