|
|
@@ -1,10 +1,13 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.etotem.cfc.dto.IngredientRecommendation;
|
|
|
+import com.etotem.cfc.entity.DietPreferences;
|
|
|
import com.etotem.cfc.entity.DietRecommendation;
|
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.MealConfig;
|
|
|
+import com.etotem.cfc.mapper.DietPreferencesMapper;
|
|
|
import com.etotem.cfc.mapper.DietRecommendationMapper;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.MealConfigMapper;
|
|
|
@@ -24,6 +27,7 @@ import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.LinkedHashMap;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -83,6 +87,10 @@ public class DietRecommendationService {
|
|
|
@Resource
|
|
|
private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
|
+ /** 参与者忌口 / 过敏偏好(diet.mealPlan.generate 的排除项唯一数据源,SC-P-27 / SC-P-28)。 */
|
|
|
+ @Resource
|
|
|
+ private DietPreferencesMapper dietPreferencesMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 菜谱分享只读查询:按 id 获取菜谱详情,不做 familyId 归属校验(跨家庭可看)。
|
|
|
* 分享数据仅含菜谱/营养信息,无个人信息,只读展示所需字段。
|
|
|
@@ -204,8 +212,11 @@ public class DietRecommendationService {
|
|
|
|
|
|
// 4. AI 失败 / 熔断 / 超时 → 规则降级(同菜数规则造 D(N)+1 道)
|
|
|
List<String> ingredientNames = availableIngredientNames(familyId, date);
|
|
|
+ // degraded:该餐是否走「规则降级通用食谱」,供一日三餐聚合(diet.mealPlan.generate)透出降级标志
|
|
|
+ boolean degraded = false;
|
|
|
if (menuJson == null || menuJson.trim().isEmpty() || "{}".equals(menuJson.trim())) {
|
|
|
menuJson = buildFallbackMenu(familyId, date, participantCount, ingredientNames);
|
|
|
+ degraded = true;
|
|
|
}
|
|
|
|
|
|
// 5. 归一化(唯一硬保证点)+ 聚合营养
|
|
|
@@ -220,6 +231,7 @@ public class DietRecommendationService {
|
|
|
normalized = normalizeMenu(
|
|
|
buildFallbackMenu(familyId, date, participantCount, ingredientNames),
|
|
|
participantCount, ingredientNames);
|
|
|
+ degraded = true;
|
|
|
}
|
|
|
String normalizedMenuJson = safeWrite(normalized);
|
|
|
Map<String, Object> nutritionSummary = aggregateNutrition(normalized);
|
|
|
@@ -252,6 +264,7 @@ public class DietRecommendationService {
|
|
|
result.put("nutritionSummary", existRecord.getNutritionSummary());
|
|
|
result.put("participantCount", participantCount);
|
|
|
result.put("dishCount", dishCount);
|
|
|
+ result.put("degraded", degraded);
|
|
|
result.put("message", "食谱推荐已更新");
|
|
|
return result;
|
|
|
}
|
|
|
@@ -372,6 +385,152 @@ public class DietRecommendationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // ============================================================
|
|
|
+ // 一日三餐聚合生成(diet.mealPlan.generate / SC-P-27 / SC-P-28)
|
|
|
+ // ============================================================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 一日三餐聚合生成(diet.mealPlan.generate / SC-P-27 家庭食谱生成)。
|
|
|
+ *
|
|
|
+ * <p>一次生成早 / 午 / 晚三餐:逐餐复用 {@link #generateRecommendation} 全链路
|
|
|
+ * (AI → 规则降级 → 归一化 → 幂等落库),再按共餐人忌口/过敏并集
|
|
|
+ * {@link #resolveParticipantExclusions} 统一重算排除项 {@link #excludeRestrictedFromMenu},
|
|
|
+ * 三餐共用同一排除集,避免逐餐口径漂移。</p>
|
|
|
+ *
|
|
|
+ * <p><b>边界(SC-P-27)</b>:AI 不可用 / 无菌群报告数据 → 规则降级通用食谱,
|
|
|
+ * 以 {@code degraded=true} 透出;忌口/过敏命中的菜品自动剔除并以 {@code excludedItems}
|
|
|
+ * 清单透出(SC-P-27「忌口/过敏自动排除」+ SC-P-28「设忌口 → 食谱重算排除项」)。</p>
|
|
|
+ *
|
|
|
+ * @param familyId 家庭 ID
|
|
|
+ * @param request {@code date / participant_member_ids / selected_foods / nutrition_goals / view_key},
|
|
|
+ * 载荷口径同 §4.11 {@code /api/diet/recommendation/generate}
|
|
|
+ * @return {@code meals(breakfast/lunch/dinner) + nutritionSummary + degraded + excludedItems};
|
|
|
+ * 发生忌口冲突时另附 {@code conflictPrompt}
|
|
|
+ */
|
|
|
+ public Map<String, Object> generateDailyMealPlan(Long familyId, Map<String, Object> request) {
|
|
|
+ Map<String, Object> source = request == null ? Collections.<String, Object>emptyMap() : request;
|
|
|
+
|
|
|
+ String dateStr = asString(source.get("date"));
|
|
|
+ if (!hasText(dateStr)) {
|
|
|
+ dateStr = LocalDate.now().toString();
|
|
|
+ }
|
|
|
+ LocalDate date = LocalDate.parse(dateStr);
|
|
|
+ String viewKey = asString(source.get("view_key"));
|
|
|
+
|
|
|
+ // 共餐人:优先载荷 participant_member_ids(字符串 / 数组双形态),为空才回落 meal_config / 家庭成员
|
|
|
+ List<Long> participantIds = asIds(source.get("participant_member_ids"));
|
|
|
+ if (participantIds.isEmpty()) {
|
|
|
+ participantIds = resolveParticipantIds(source, familyId, date);
|
|
|
+ }
|
|
|
+ Collections.sort(participantIds);
|
|
|
+ String participantsJson = safeWrite(participantIds);
|
|
|
+
|
|
|
+ // 忌口/过敏并集(SC-P-27「忌口/过敏自动排除」+ SC-P-28)
|
|
|
+ List<String> exclusions = resolveParticipantExclusions(participantIds);
|
|
|
+
|
|
|
+ Map<String, Object> meals = new LinkedHashMap<>();
|
|
|
+ Map<String, Object> nutritionSummary = new LinkedHashMap<>();
|
|
|
+ nutritionSummary.put("calories", 0);
|
|
|
+ nutritionSummary.put("protein", 0);
|
|
|
+ nutritionSummary.put("carbs", 0);
|
|
|
+ nutritionSummary.put("fat", 0);
|
|
|
+ boolean degraded = false;
|
|
|
+ String conflictPrompt = "";
|
|
|
+
|
|
|
+ for (String mealType : Arrays.asList("breakfast", "lunch", "dinner")) {
|
|
|
+ Map<String, Object> single = new HashMap<>();
|
|
|
+ single.put("date", dateStr);
|
|
|
+ single.put("meal_type", mealType);
|
|
|
+ single.put("selected_foods", source.get("selected_foods"));
|
|
|
+ single.put("participant_member_ids", participantsJson);
|
|
|
+ single.put("nutrition_goals", source.get("nutrition_goals"));
|
|
|
+ single.put("view_key", viewKey);
|
|
|
+
|
|
|
+ Map<String, Object> generated = generateRecommendation(familyId, single);
|
|
|
+ degraded = degraded || Boolean.TRUE.equals(generated.get("degraded"));
|
|
|
+
|
|
|
+ Map<String, Object> filtered =
|
|
|
+ excludeRestrictedFromMenu(asString(generated.get("menu")), exclusions);
|
|
|
+ meals.put(mealType, filtered.get("menu"));
|
|
|
+ collectNutrition(filtered.get("menu"), nutritionSummary, 0);
|
|
|
+
|
|
|
+ Object prompt = filtered.get("conflictPrompt");
|
|
|
+ String text = prompt == null ? "" : String.valueOf(prompt);
|
|
|
+ if (hasText(text)) {
|
|
|
+ conflictPrompt = text;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ result.put("meals", meals);
|
|
|
+ result.put("nutritionSummary", nutritionSummary);
|
|
|
+ result.put("degraded", degraded);
|
|
|
+ result.put("excludedItems", exclusions);
|
|
|
+ if (hasText(conflictPrompt)) {
|
|
|
+ result.put("conflictPrompt", conflictPrompt);
|
|
|
+ }
|
|
|
+ result.put("participantCount", participantIds.isEmpty() ? 1 : participantIds.size());
|
|
|
+ result.put("date", dateStr);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 参与者忌口 / 过敏关键词并集(diet.mealPlan.generate / SC-P-27 + SC-P-28)。
|
|
|
+ *
|
|
|
+ * <p>来源 {@code diet_preferences.allergies / absoluteAvoid}:共餐人里任一成员有忌口,
|
|
|
+ * 全员食谱都要排除(过敏不过「只有一人不吃」的折中)。关键词按分隔符切分去空、保持首次出现顺序。</p>
|
|
|
+ *
|
|
|
+ * @param participantMemberIds 共餐成员 ID(family_members.id)
|
|
|
+ * @return 忌口/过敏关键词并集;无成员或无记录时返回空列表(不抛异常)
|
|
|
+ */
|
|
|
+ public List<String> resolveParticipantExclusions(List<Long> participantMemberIds) {
|
|
|
+ Set<String> union = new LinkedHashSet<>();
|
|
|
+ if (participantMemberIds == null || participantMemberIds.isEmpty()) {
|
|
|
+ return new ArrayList<>(union);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 用列名 QueryWrapper 而非 LambdaQueryWrapper:SFunction 依赖 MyBatis-Plus 的
|
|
|
+ // Lambda 缓存,脱离 Spring/MP 容器(纯契约单测)时无法解析列名;此处列名稳定,代价可控。
|
|
|
+ QueryWrapper<DietPreferences> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.in("family_member_id", participantMemberIds);
|
|
|
+ List<DietPreferences> prefs = dietPreferencesMapper.selectList(wrapper);
|
|
|
+ if (prefs != null) {
|
|
|
+ for (DietPreferences pref : prefs) {
|
|
|
+ if (pref == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ union.addAll(splitKeywords(pref.getAllergies()));
|
|
|
+ union.addAll(splitKeywords(pref.getAbsoluteAvoid()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("读取参与者忌口/过敏失败,按无排除项处理: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ return new ArrayList<>(union);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按忌口重算排除项(diet.mealPlan.generate / SC-P-28「设忌口/过敏 → 食谱重算排除项」)。
|
|
|
+ *
|
|
|
+ * <p>兼容两种菜单形态:{@code {"meals":[{name, ingredients}]}}(meals 元素即单道菜,前端直传)
|
|
|
+ * 与 {@code {"meals":[{type, dishes:[...]}]}}(归一化后落库形态,逐道过滤 dishes)。
|
|
|
+ * 忌口命中按「菜品名 + 食材名」子串匹配,命中的忌口关键词写入 {@code excludedItems}。</p>
|
|
|
+ *
|
|
|
+ * @param menuJson 菜单(JSON 字符串 / 已解析 Map),null / 非法 JSON 视为空菜单
|
|
|
+ * @param exclusions 忌口/过敏关键词({@link #resolveParticipantExclusions} 的并集)
|
|
|
+ * @return {@code {menu, excludedItems, conflictPrompt}};无冲突时 conflictPrompt 为空串
|
|
|
+ */
|
|
|
+ public Map<String, Object> excludeRestrictedFromMenu(Object menuJson, List<String> exclusions) {
|
|
|
+ Set<String> hitKeywords = new LinkedHashSet<>();
|
|
|
+ Object filtered = filterRestrictedMenu(menuJson, exclusions, hitKeywords);
|
|
|
+
|
|
|
+ Map<String, Object> result = new LinkedHashMap<>();
|
|
|
+ result.put("menu", filtered);
|
|
|
+ result.put("excludedItems", new ArrayList<>(hitKeywords));
|
|
|
+ result.put("conflictPrompt", buildConflictPrompt(filtered, hitKeywords));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
// ============================================================
|
|
|
// 内部辅助:view_key / 参数归一
|
|
|
// ============================================================
|
|
|
@@ -910,6 +1069,215 @@ public class DietRecommendationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // ============================================================
|
|
|
+ // 内部辅助:忌口过滤 / 排除清单(diet.mealPlan.generate)
|
|
|
+ // ============================================================
|
|
|
+
|
|
|
+ /** 忌口 / 过敏关键词切分:兼容中英文逗号、顿号、分号、斜杠与空白分隔。 */
|
|
|
+ private static List<String> splitKeywords(String raw) {
|
|
|
+ List<String> keys = new ArrayList<>();
|
|
|
+ if (!hasText(raw)) {
|
|
|
+ return keys;
|
|
|
+ }
|
|
|
+ for (String part : raw.split("[,,、;;/\\s]+")) {
|
|
|
+ if (hasText(part) && !keys.contains(part.trim())) {
|
|
|
+ keys.add(part.trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return keys;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 忌口命中判定:菜品名 + 食材名任一包含忌口关键词即命中(子串匹配,中文无需大小写归一)。
|
|
|
+ * 命中的忌口关键词写入 {@code hitKeywords}(供 excludedItems 透出)。
|
|
|
+ */
|
|
|
+ private static boolean isRestricted(Map<?, ?> dish, List<String> exclusions, Set<String> hitKeywords) {
|
|
|
+ if (exclusions == null || exclusions.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ List<String> texts = collectTexts(dish);
|
|
|
+ for (String keyword : exclusions) {
|
|
|
+ if (!hasText(keyword)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String key = keyword.trim();
|
|
|
+ for (String text : texts) {
|
|
|
+ if (text.contains(key)) {
|
|
|
+ hitKeywords.add(key);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 收集菜品的可匹配文本:菜名 + 各食材名(兼容 Map 形态与字符串数组形态的 ingredients)。 */
|
|
|
+ private static List<String> collectTexts(Map<?, ?> dish) {
|
|
|
+ List<String> texts = new ArrayList<>();
|
|
|
+ Object name = dish.get("name");
|
|
|
+ if (name != null && hasText(String.valueOf(name))) {
|
|
|
+ texts.add(String.valueOf(name));
|
|
|
+ }
|
|
|
+ Object ingredients = dish.get("ingredients");
|
|
|
+ if (ingredients instanceof List) {
|
|
|
+ for (Object item : (List<?>) ingredients) {
|
|
|
+ String value;
|
|
|
+ if (item instanceof Map) {
|
|
|
+ Object ingName = ((Map<?, ?>) item).get("name");
|
|
|
+ value = ingName == null ? "" : String.valueOf(ingName);
|
|
|
+ } else {
|
|
|
+ value = item == null ? "" : String.valueOf(item);
|
|
|
+ }
|
|
|
+ if (hasText(value) && !texts.contains(value)) {
|
|
|
+ texts.add(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return texts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 忌口过滤(两种菜单形态同收口):
|
|
|
+ * {@code {"meals":[{type,dishes:[...]}]}} 归一化落库形态逐道过滤 dishes 并保留餐结构;
|
|
|
+ * {@code {"meals":[{name,ingredients}]}} 前端直传形态下 meals 元素即单道菜,整条剔除。
|
|
|
+ * 菜单为 null / 非法 JSON 时返回空菜单 —— 保守起见不把未过滤原文透出(忌口菜可能就在其中)。
|
|
|
+ */
|
|
|
+ private Object filterRestrictedMenu(Object menuJson, List<String> exclusions, Set<String> hitKeywords) {
|
|
|
+ Map<String, Object> root;
|
|
|
+ if (menuJson == null) {
|
|
|
+ return emptyMenu();
|
|
|
+ }
|
|
|
+ if (menuJson instanceof Map) {
|
|
|
+ root = copyMap((Map<?, ?>) menuJson);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ JsonNode node = OBJECT_MAPPER.readTree(String.valueOf(menuJson));
|
|
|
+ root = toMap(node);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return emptyMenu();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Object mealsObj = root.get("meals");
|
|
|
+ if (!(mealsObj instanceof List)) {
|
|
|
+ return root;
|
|
|
+ }
|
|
|
+ List<Object> keptMeals = new ArrayList<>();
|
|
|
+ for (Object item : (List<?>) mealsObj) {
|
|
|
+ if (!(item instanceof Map)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<?, ?> meal = (Map<?, ?>) item;
|
|
|
+ if (meal.get("dishes") instanceof List) {
|
|
|
+ Map<String, Object> keptMeal = copyMap(meal);
|
|
|
+ List<Object> keptDishes = new ArrayList<>();
|
|
|
+ for (Object dish : (List<?>) meal.get("dishes")) {
|
|
|
+ if (dish instanceof Map && !isRestricted((Map<?, ?>) dish, exclusions, hitKeywords)) {
|
|
|
+ keptDishes.add(dish);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ keptMeal.put("dishes", keptDishes);
|
|
|
+ keptMeals.add(keptMeal);
|
|
|
+ } else if (!isRestricted(meal, exclusions, hitKeywords)) {
|
|
|
+ keptMeals.add(meal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Object> out = new LinkedHashMap<>(root);
|
|
|
+ out.put("meals", keptMeals);
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 忌口冲突提示(SC-P-28 边界):无冲突空串;全被剔除给出强提示;部分剔除告知已排除项。 */
|
|
|
+ private static String buildConflictPrompt(Object filtered, Set<String> hitKeywords) {
|
|
|
+ if (hitKeywords.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ String keys = String.join("、", hitKeywords);
|
|
|
+ if (isMenuEmpty(filtered)) {
|
|
|
+ return "全部菜品均命中忌口(" + keys + "),暂无可选菜品,请调整忌口设置或更换食材后重新生成";
|
|
|
+ }
|
|
|
+ return "已按忌口自动剔除(" + keys + "),相关菜品已从菜单移除,请确认剩余菜品是否满足全家需求";
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 菜单是否已无可食菜品:meals 为空,或所有餐的 dishes 为空且无「元素即菜」的保留项。 */
|
|
|
+ private static boolean isMenuEmpty(Object filtered) {
|
|
|
+ if (!(filtered instanceof Map)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ Object mealsObj = ((Map<?, ?>) filtered).get("meals");
|
|
|
+ if (!(mealsObj instanceof List) || ((List<?>) mealsObj).isEmpty()) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ for (Object item : (List<?>) mealsObj) {
|
|
|
+ if (!(item instanceof Map)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Map<?, ?> meal = (Map<?, ?>) item;
|
|
|
+ Object dishes = meal.get("dishes");
|
|
|
+ if (dishes instanceof List && !((List<?>) dishes).isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ Object name = meal.get("name");
|
|
|
+ if (name != null && hasText(String.valueOf(name))) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 空菜单骨架(与归一化输出同构,前端可直接渲染空态)。 */
|
|
|
+ private static Map<String, Object> emptyMenu() {
|
|
|
+ Map<String, Object> empty = new LinkedHashMap<>();
|
|
|
+ empty.put("meals", new ArrayList<Object>());
|
|
|
+ return empty;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** Map 浅拷贝并统一 key 为 String(JsonNode / 泛型 Map 转换后保持可写结构)。 */
|
|
|
+ private static Map<String, Object> copyMap(Map<?, ?> source) {
|
|
|
+ Map<String, Object> copy = new LinkedHashMap<>();
|
|
|
+ if (source != null) {
|
|
|
+ for (Map.Entry<?, ?> entry : source.entrySet()) {
|
|
|
+ copy.put(String.valueOf(entry.getKey()), entry.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return copy;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** JsonNode → Map(Jackson 自带转换,保持字段原值,无需二次归一化)。 */
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private static Map<String, Object> toMap(JsonNode node) {
|
|
|
+ Map<String, Object> map = OBJECT_MAPPER.convertValue(node, Map.class);
|
|
|
+ return map == null ? new LinkedHashMap<>() : map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 三餐营养汇总:递归收集菜品级 calories / 宏量营养素,兼容「meals→dishes」与「meals 元素即菜」两形态。
|
|
|
+ * 深度上限 6,避免异常自引用结构导致死循环。
|
|
|
+ */
|
|
|
+ private static void collectNutrition(Object node, Map<String, Object> summary, int depth) {
|
|
|
+ if (node == null || depth > 6) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (node instanceof List) {
|
|
|
+ for (Object item : (List<?>) node) {
|
|
|
+ collectNutrition(item, summary, depth + 1);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!(node instanceof Map)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<?, ?> map = (Map<?, ?>) node;
|
|
|
+ if (map.containsKey("calories") || map.containsKey("protein")
|
|
|
+ || map.containsKey("carbs") || map.containsKey("fat")) {
|
|
|
+ for (String key : Arrays.asList("calories", "protein", "carbs", "fat")) {
|
|
|
+ summary.put(key, asInt(summary.get(key)) + asInt(map.get(key)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ collectNutrition(map.get("dishes"), summary, depth + 1);
|
|
|
+ collectNutrition(map.get("meals"), summary, depth + 1);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 菜数规则唯一常量源(CR-C / D3·D4)。
|
|
|
* 仅 lunch/dinner 适用;N<=0 兜底 1;D(N)=4+max(0,N-3);汤恒 1 且不计入菜数。
|