|
|
@@ -1396,15 +1396,23 @@ public class HealthReportController {
|
|
|
|
|
|
@Operation(summary = "获取食材推荐列表")
|
|
|
@PostMapping("/foods")
|
|
|
- public Result<List<Food>> listFoods(@RequestBody(required = false) Map<String, Object> params) {
|
|
|
- if (params == null) {
|
|
|
- return Result.success(java.util.Collections.emptyList());
|
|
|
- }
|
|
|
- Long reportId = ParamUtils.getLong(params.get("reportId"));
|
|
|
- if (reportId == null) {
|
|
|
- return Result.success(java.util.Collections.emptyList());
|
|
|
+ public Result<List<Food>> listFoods(@RequestBody(required = false) Map<String, Object> params,
|
|
|
+ @RequestAttribute(value = "userId", required = false) Long userId) {
|
|
|
+ Long reportId = params != null ? ParamUtils.getLong(params.get("reportId")) : null;
|
|
|
+ List<Food> foods;
|
|
|
+ if (reportId != null) {
|
|
|
+ // 指定报告:返回该报告的食材推荐
|
|
|
+ foods = foodService.listByReportId(reportId);
|
|
|
+ } else {
|
|
|
+ // 未指定报告:返回当前用户最新报告的食材推荐(当前最适合)
|
|
|
+ Long uid = userId != null ? userId : -1L;
|
|
|
+ HealthReport latest = healthReportService.getLatestReport(uid);
|
|
|
+ if (latest == null) {
|
|
|
+ foods = java.util.Collections.emptyList();
|
|
|
+ } else {
|
|
|
+ foods = foodService.listByReportId(latest.getId());
|
|
|
+ }
|
|
|
}
|
|
|
- List<Food> foods = foodService.listByReportId(reportId);
|
|
|
return Result.success(foods);
|
|
|
}
|
|
|
|