|
@@ -275,6 +275,50 @@ public class FoodRecommendService {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按报告获取戒备食材(该报告当次检测的推荐指数 < 0 食材)。
|
|
|
|
|
+ * 优先从 foods 表读取(正常确认流程按报告写入),
|
|
|
|
|
+ * 若 foods 表无负分数据,回退到 report_food_suitability(审核路径写入)。
|
|
|
|
|
+ * 返回结构与当前戒备接口一致(兼容前端 FoodRecommendIndex 映射)。
|
|
|
|
|
+ */
|
|
|
|
|
+ public List<FoodRecommendIndex> getCautionFoodsByReport(Long reportId) {
|
|
|
|
|
+ List<FoodRecommendIndex> result = new ArrayList<>();
|
|
|
|
|
+ if (reportId == null) return result;
|
|
|
|
|
+
|
|
|
|
|
+ // 优先 foods 表(确认流程写入,携带 report_id)
|
|
|
|
|
+ List<Food> reportFoods = foodService.listByReportId(reportId);
|
|
|
|
|
+ for (Food food : reportFoods) {
|
|
|
|
|
+ if (food.getScore() != null && food.getScore() < 0) {
|
|
|
|
|
+ FoodRecommendIndex idx = new FoodRecommendIndex();
|
|
|
|
|
+ idx.setFoodId(food.getId());
|
|
|
|
|
+ idx.setFoodName(food.getName());
|
|
|
|
|
+ idx.setIndexScore(food.getScore());
|
|
|
|
|
+ idx.setHealthReportId(reportId);
|
|
|
|
|
+ result.add(idx);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // foods 无负分数据:回退 report_food_suitability(审核路径只写这张表)
|
|
|
|
|
+ if (result.isEmpty()) {
|
|
|
|
|
+ List<ReportFoodSuitability> fallback = reportFoodSuitabilityMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<ReportFoodSuitability>()
|
|
|
|
|
+ .eq(ReportFoodSuitability::getReportId, reportId)
|
|
|
|
|
+ .lt(ReportFoodSuitability::getScore, 0)
|
|
|
|
|
+ .orderByAsc(ReportFoodSuitability::getScore));
|
|
|
|
|
+ for (ReportFoodSuitability rfs : fallback) {
|
|
|
|
|
+ FoodRecommendIndex idx = new FoodRecommendIndex();
|
|
|
|
|
+ idx.setFoodId(rfs.getFoodId());
|
|
|
|
|
+ idx.setFoodName(rfs.getFoodName());
|
|
|
|
|
+ idx.setIndexScore(rfs.getScore());
|
|
|
|
|
+ idx.setHealthReportId(reportId);
|
|
|
|
|
+ result.add(idx);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ result.sort(Comparator.comparing(FoodRecommendIndex::getIndexScore));
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 获取戒备食材趋势数据:返回每个食材的 indexScore 历史序列(最近N条变更记录)
|
|
* 获取戒备食材趋势数据:返回每个食材的 indexScore 历史序列(最近N条变更记录)
|
|
|
* 每个元素: { foodId, foodName, currentScore, trend: [reportDate, score], changeDir: "up"|"down"|"flat" }
|
|
* 每个元素: { foodId, foodName, currentScore, trend: [reportDate, score], changeDir: "up"|"down"|"flat" }
|