Browse Source

fix: 测评方案列表familyId三路回退(查询参数/JSON body/JWT)修复缺参500

Xiaogang Liao 3 weeks ago
parent
commit
f1bd63bb6b

+ 22 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/assessment/AssessmentReportController.java

@@ -21,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.concurrent.CompletableFuture;
 import java.util.List;
@@ -60,9 +61,28 @@ public class AssessmentReportController {
     @Operation(summary = "获取用户已生成的测评方案列表")
     @PostMapping("/plans/list")
     public Result<List<TaskPlanInstance>> getMyPlans(
-            @RequestParam("familyId") Long familyId,
-            @RequestParam(value = "childId", required = false) Long childId) {
+            @RequestParam(value = "familyId", required = false) Long familyId,
+            @RequestParam(value = "childId", required = false) Long childId,
+            @RequestBody(required = false) Map<String, Object> body,
+            HttpServletRequest request) {
         try {
+            // 参数兼容:优先查询参数,其次 JSON body,最后回退 JWT 注入的 familyId
+            if (familyId == null && body != null && body.get("familyId") != null) {
+                familyId = ((Number) body.get("familyId")).longValue();
+            }
+            if (childId == null && body != null && body.get("childId") != null) {
+                childId = ((Number) body.get("childId")).longValue();
+            }
+            if (familyId == null) {
+                Object attr = request.getAttribute("familyId");
+                if (attr instanceof Number) {
+                    familyId = ((Number) attr).longValue();
+                }
+            }
+            if (familyId == null) {
+                return Result.error("缺少familyId参数且无法从登录态获取家庭信息");
+            }
+
             // 如果传了 childId,只查该孩子的方案;否则查整个家庭的方案
             List<TaskPlanInstance> plans;
             if (childId != null) {