|
@ -11,6 +11,7 @@ import com.mathvision.diet.domian.RuleItemDTO; |
|
|
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.apache.commons.lang3.tuple.Triple; |
|
|
import org.apache.commons.lang3.tuple.Triple; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
@ -243,6 +244,38 @@ public class MenuReportService { |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public JSONObject sugar(String crow, List<MenuDish> dishes) { |
|
|
|
|
|
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<Long, BigDecimal> salt = dishes.stream().collect(Collectors.groupingBy(MenuDish::getDay)).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, |
|
|
|
|
|
entry -> entry.getValue().stream().flatMap(dish -> dish.getIngredient().stream().filter(item -> item.getValue().containsKey(crow) && item.getValue().get(crow).doubleValue() > 0 && ingredientMap.containsKey(item.getKey()))) |
|
|
|
|
|
.flatMap(x -> ingredientMap.get(x.getKey()).getNutrient().entrySet().stream().map(n -> Pair.of(n.getKey(), n.getValue().multiply(x.getValue().get(crow)).divide(new BigDecimal(100), RoundingMode.HALF_UP)))) |
|
|
|
|
|
.filter(x -> StringUtils.equalsIgnoreCase("sodium", x.getKey())) |
|
|
|
|
|
.map(x -> x.getValue().multiply(new BigDecimal("0.0025"))) |
|
|
|
|
|
.reduce(BigDecimal :: add) |
|
|
|
|
|
.orElse(BigDecimal.ZERO))); |
|
|
|
|
|
|
|
|
|
|
|
Map<Long, BigDecimal> sugar = dishes.stream().collect(Collectors.groupingBy(MenuDish::getDay)).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, |
|
|
|
|
|
entry -> entry.getValue().stream().flatMap(dish -> dish.getIngredient().stream().filter(item -> item.getValue().containsKey(crow) && item.getValue().get(crow).doubleValue() > 0 && ingredientMap.containsKey(item.getKey())) |
|
|
|
|
|
.map(x -> Pair.of(ingredientMap.get(x.getKey()), x.getValue())) |
|
|
|
|
|
.filter(x -> StringUtils.equals("糖类", x.getKey().getType())) |
|
|
|
|
|
.map(x -> x.getValue().values().stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO)) |
|
|
|
|
|
).reduce(BigDecimal::add).orElse(BigDecimal.ZERO))); |
|
|
|
|
|
|
|
|
|
|
|
Map<Long, BigDecimal> oil = dishes.stream().collect(Collectors.groupingBy(MenuDish::getDay)).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, |
|
|
|
|
|
entry -> entry.getValue().stream().flatMap(dish -> dish.getIngredient().stream().filter(item -> item.getValue().containsKey(crow) && item.getValue().get(crow).doubleValue() > 0 && ingredientMap.containsKey(item.getKey())) |
|
|
|
|
|
.map(x -> Pair.of(ingredientMap.get(x.getKey()), x.getValue())) |
|
|
|
|
|
.filter(x -> StringUtils.equals("烹调油", x.getKey().getType())) |
|
|
|
|
|
.map(x -> x.getValue().values().stream().reduce(BigDecimal::add).orElse(BigDecimal.ZERO)) |
|
|
|
|
|
).reduce(BigDecimal::add).orElse(BigDecimal.ZERO))); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject result = new JSONObject(); |
|
|
|
|
|
result.put("crow", crow); |
|
|
|
|
|
result.put("salt", salt); |
|
|
|
|
|
result.put("sugar", sugar); |
|
|
|
|
|
result.put("oil", oil); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private JSONObject toEnergyContent(BigDecimal total, String key, BigDecimal value, Range<Integer> standard) { |
|
|
private JSONObject toEnergyContent(BigDecimal total, String key, BigDecimal value, Range<Integer> standard) { |
|
|
BigDecimal percentage = total.intValue() == 0 ? BigDecimal.ZERO : value.divide(total, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); |
|
|
BigDecimal percentage = total.intValue() == 0 ? BigDecimal.ZERO : value.divide(total, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); |
|
|
percentage = percentage.setScale(2, RoundingMode.HALF_UP); |
|
|
percentage = percentage.setScale(2, RoundingMode.HALF_UP); |
|
|