Browse Source

fix(health): 健康报告列表仅返回最近3条 - 小程序健康页只展示3条,避免多余数据传输

Xiaogang Liao 1 tháng trước cách đây
mục cha
commit
94199485a6

+ 14 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/HealthReportController.java

@@ -270,16 +270,28 @@ public class HealthReportController {
         Long memberId = ParamUtils.getLong(params.get("memberId"), currentMemberId);
         if (memberId != null) {
             List<HealthReport> reports = healthReportService.getUserReports(memberId);
-            return Result.success(reports);
+            // 小程序健康页仅展示最近 3 条,后台只返回 3 条,避免前端截断与多余数据传输
+            return Result.success(limitLatest(reports, 3));
         }
         // 未指定 memberId 时,回退到家庭报告列表
         if (familyId != null) {
             List<HealthReport> reports = healthReportService.getFamilyReports(familyId);
-            return Result.success(reports);
+            // 同上,仅返回最近 3 条
+            return Result.success(limitLatest(reports, 3));
         }
         return Result.error("memberId不能为空");
     }
 
+    /**
+     * 截取列表前 N 条(列表已按报告日期倒序,取最近 N 条)
+     */
+    private List<HealthReport> limitLatest(List<HealthReport> reports, int max) {
+        if (reports == null || reports.size() <= max) {
+            return reports;
+        }
+        return new ArrayList<>(reports.subList(0, max));
+    }
+
     @Operation(summary = "获取全家健康报告列表(方案页选择用)")
     @PostMapping("/reports/family")
     public Result<List<HealthReport>> listFamilyReports(