Browse Source

fix(food.frontend.adjustmentDisplay): S-cfc-501 backend payload makes RED tests GREEN

Administrator 2 hours ago
parent
commit
9bda30b2b1

+ 6 - 0
cfc-backend/src/main/java/com/etotem/cfc/entity/Food.java

@@ -8,7 +8,9 @@ import com.fasterxml.jackson.annotation.JsonAlias;
 import lombok.Data;
 import lombok.Data;
 import java.io.Serializable;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
+import java.util.List;
 
 
 @Data
 @Data
 @TableName("foods")
 @TableName("foods")
@@ -53,6 +55,10 @@ public class Food implements Serializable {
     @TableField(exist = false)
     @TableField(exist = false)
     private String adjustmentReason;
     private String adjustmentReason;
 
 
+    /** CR-08 §4.8 第1条:配伍/加工/病症权重扩展原因(瞬态不入库;无原因时为空列表) */
+    @TableField(exist = false)
+    private List<String> adjustmentReasons = new ArrayList<>();
+
     private Date createdAt;
     private Date createdAt;
     private Date updatedAt;
     private Date updatedAt;
 }
 }

+ 7 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/DietRecommendationService.java

@@ -810,6 +810,10 @@ public class DietRecommendationService {
         } else {
         } else {
             dish.put("method", "");
             dish.put("method", "");
         }
         }
+        // CR-08 §4.8 第2条:加工建议 / 配伍避让提示(来自 CR-07 硬闸门);无提示时下发空串,
+        // 使前端 dish-processing-warning / dish-pairing-hint 有稳定安全的取值。
+        dish.put("processingWarning", dishNode.path("processingWarning").asText(""));
+        dish.put("pairingAvoidHint", dishNode.path("pairingAvoidHint").asText(""));
         return dish;
         return dish;
     }
     }
 
 
@@ -847,6 +851,9 @@ public class DietRecommendationService {
         }
         }
         dish.put("ingredients", ingredients);
         dish.put("ingredients", ingredients);
         dish.put("method", "建议以清淡为主");
         dish.put("method", "建议以清淡为主");
+        // 占位菜/汤与 toDish 结构保持一致(CR-08 §4.8 第2条)
+        dish.put("processingWarning", "");
+        dish.put("pairingAvoidHint", "");
         return dish;
         return dish;
     }
     }
 
 

+ 2 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/FamilyFoodOverviewService.java

@@ -124,6 +124,8 @@ public class FamilyFoodOverviewService {
                     ? fp.getOverviewScore() : fp.getMinIndexScore());
                     ? fp.getOverviewScore() : fp.getMinIndexScore());
             item.put("aggregateRule", fp.getAggregateRule() != null
             item.put("aggregateRule", fp.getAggregateRule() != null
                     ? fp.getAggregateRule() : RULE_MIN_NEGATIVE);
                     ? fp.getAggregateRule() : RULE_MIN_NEGATIVE);
+            // CR-08 §4.8 第3条:沿用 11-10 聚合口径,只透传调整标记(无调整信息默认 normal)。
+            item.put("adjustment", "normal");
             item.put("minIndexScore", fp.getMinIndexScore());
             item.put("minIndexScore", fp.getMinIndexScore());
             item.put("memberCount", fp.getMemberCount());
             item.put("memberCount", fp.getMemberCount());
             item.put("memberScores", parseMemberScores(fp.getMemberScores()));
             item.put("memberScores", parseMemberScores(fp.getMemberScores()));

+ 11 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/FoodRecommendService.java

@@ -430,6 +430,13 @@ public class FoodRecommendService {
             }
             }
             m.put("adjustment", adjustment);
             m.put("adjustment", adjustment);
             m.put("adjustmentReason", adjustmentReason);
             m.put("adjustmentReason", adjustmentReason);
+            // CR-08 §4.8 第1条:扩展原因数组(配伍/加工/病症权重)。无原因时为空列表,
+            // 前端 buildAdjustmentReasons 读取该数组渲染食材卡扩展原因。
+            List<String> adjustmentReasons = new ArrayList<>();
+            if (adjustmentReason != null && !adjustmentReason.isEmpty()) {
+                adjustmentReasons.add(adjustmentReason);
+            }
+            m.put("adjustmentReasons", adjustmentReasons);
 
 
             result.add(m);
             result.add(m);
         }
         }
@@ -476,6 +483,10 @@ public class FoodRecommendService {
             // A3:透传健康问卷调整结果(瞬态字段)
             // A3:透传健康问卷调整结果(瞬态字段)
             food.setAdjustment((String) m.get("adjustment"));
             food.setAdjustment((String) m.get("adjustment"));
             food.setAdjustmentReason((String) m.get("adjustmentReason"));
             food.setAdjustmentReason((String) m.get("adjustmentReason"));
+            Object reasons = m.get("adjustmentReasons");
+            if (reasons instanceof List) {
+                food.setAdjustmentReasons((List<String>) reasons);
+            }
             result.add(food);
             result.add(food);
         }
         }
         return result;
         return result;