|
|
@@ -45,14 +45,29 @@ public class FoodRecommendService {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 从 foods 表读取最新报告关联的食材推荐(正常确认流程写入 foods 表)
|
|
|
+ // 优先从 foods 表读取(正常确认流程写入 foods 表);
|
|
|
+ // 若 foods 表无数据(审核路径只写 report_food_suitability),回退到 report_food_suitability
|
|
|
List<Food> reportFoods = foodService.listByReportId(report.getId());
|
|
|
-
|
|
|
if (reportFoods.isEmpty()) {
|
|
|
- foodRecommendIndexMapper.delete(new LambdaQueryWrapper<FoodRecommendIndex>()
|
|
|
- .eq(FoodRecommendIndex::getUserId, userId));
|
|
|
- log.info("报告{}无食材推荐数据,已清除用户{}的推荐指数", report.getId(), userId);
|
|
|
- return;
|
|
|
+ List<ReportFoodSuitability> fallback = reportFoodSuitabilityMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<ReportFoodSuitability>()
|
|
|
+ .eq(ReportFoodSuitability::getReportId, report.getId()));
|
|
|
+ if (fallback.isEmpty()) {
|
|
|
+ foodRecommendIndexMapper.delete(new LambdaQueryWrapper<FoodRecommendIndex>()
|
|
|
+ .eq(FoodRecommendIndex::getUserId, userId));
|
|
|
+ log.info("报告{}无食材推荐数据,已清除用户{}的推荐指数", report.getId(), userId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 回退:将 report_food_suitability 映射为 Food 列表后继续处理
|
|
|
+ reportFoods = new ArrayList<>();
|
|
|
+ for (ReportFoodSuitability rfs : fallback) {
|
|
|
+ Food f = new Food();
|
|
|
+ f.setId(rfs.getFoodId() != null ? rfs.getFoodId() : 0L);
|
|
|
+ f.setName(rfs.getFoodName());
|
|
|
+ f.setCategory(rfs.getCategory());
|
|
|
+ f.setScore(rfs.getScore());
|
|
|
+ reportFoods.add(f);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
List<FoodRecommendIndex> existingIndices = foodRecommendIndexMapper.selectList(
|