|
|
@@ -234,24 +234,17 @@ public class DietRecommendationService {
|
|
|
menuJson = aiGateway.generateMenu(selectedFoodsJson, participantsJson, dateStr, dishCount);
|
|
|
}
|
|
|
|
|
|
- // 4. AI 失败 / 熔断 / 超时 → 规则降级(同菜数规则造 D(N)+1 道)
|
|
|
+ // 4. 不再做规则兜底:AI 失败/空结果/非法结构一律显式报错,便于定位问题。
|
|
|
+ // (产品决策 2026-11-28:宁可生成失败提示给用户,也不静默产出"营养餐/营养汤"假菜单)
|
|
|
List<String> ingredientNames = availableIngredientNames(familyId, date);
|
|
|
if (menuJson == null || menuJson.trim().isEmpty() || "{}".equals(menuJson.trim())) {
|
|
|
- menuJson = buildFallbackMenu(familyId, date, participantCount, ingredientNames, personalFoodNames, variationSeed);
|
|
|
+ throw new IllegalArgumentException("食谱生成失败:AI 未返回菜单(服务不可用或超时),请稍后重试");
|
|
|
}
|
|
|
|
|
|
- // 5. 归一化(唯一硬保证点)+ 聚合营养
|
|
|
+ // 5. 归一化 + 结构校验(不再降级)
|
|
|
Map<String, Object> normalized = normalizeMenu(menuJson, participantCount, ingredientNames);
|
|
|
- // CR-3 / AC-24·26·27:LangGraph 在 LLM 无 JSON / 异常时返回 HTTP 200 的 {"meals": []},
|
|
|
- // 非法 JSON 也会被 normalizeMenu 的异常兜底吞掉,二者都产出空菜单;
|
|
|
- // 步骤 4 只判 null / 空串 / "{}" 会漏掉这两种形态。
|
|
|
- // 归一化后再校验一次结构可用性,不足则复用规则降级(绝不重新调用 aiGateway,禁止整份重试 AI)。
|
|
|
- // 于是 AI 正常 / 熔断降级 / 空·非法输出 三条路径最终落库均为 D(N) 菜 + 1 汤;
|
|
|
- // regenerate 复用本方法(L283),同样受保护。
|
|
|
if (!hasUsableLunchDinner(normalized)) {
|
|
|
- normalized = normalizeMenu(
|
|
|
- buildFallbackMenu(familyId, date, participantCount, ingredientNames, personalFoodNames, variationSeed),
|
|
|
- participantCount, ingredientNames);
|
|
|
+ throw new IllegalArgumentException("食谱生成失败:AI 返回的菜单结构不完整(午餐/晚餐缺菜),请稍后重试");
|
|
|
}
|
|
|
String normalizedMenuJson = safeWrite(normalized);
|
|
|
Map<String, Object> nutritionSummary = aggregateNutrition(normalized);
|