Parcourir la source

feat: 修复打卡/能量接口 400/500 错误

- HealthCheckinController/FinanceCheckinController stats: @RequestAttribute userId 改为 required=false
- FinanceCheckinController create: 补充 checkinType 必填校验
- EnergyController overview: @RequestBody 改为 required=false + null 校验
Sisyphus il y a 2 mois
Parent
commit
9cbdc8ae0a

+ 4 - 1
cfc-backend/src/main/java/com/etotem/cfc/controller/EnergyController.java

@@ -52,7 +52,10 @@ public class EnergyController {
     @Operation(summary = "获取五维能量概览")
     @PostMapping("/overview")
     public Result<Map<String, Object>> getEnergyOverview(
-            @RequestBody Map<String, Object> params) {
+            @RequestBody(required = false) Map<String, Object> params) {
+        if (params == null) {
+            return Result.error("请求体不能为空");
+        }
         Long childId = params.get("childId") != null
                 ? Long.valueOf(params.get("childId").toString()) : null;
         if (childId == null) {

+ 1 - 1
cfc-backend/src/main/java/com/etotem/cfc/controller/HealthCheckinController.java

@@ -93,7 +93,7 @@ public class HealthCheckinController {
     @PostMapping("/stats")
     public Result<Map<String, Object>> stats(
             @RequestBody Map<String, Object> params,
-            @RequestAttribute("userId") Long userId) {
+            @RequestAttribute(value = "userId", required = false) Long userId) {
         Long childId = params.get("childId") != null
                 ? Long.valueOf(params.get("childId").toString()) : null;
         long total = healthCheckinService.countCheckins(childId);

+ 5 - 2
cfc-backend/src/main/java/com/etotem/cfc/controller/wealth/FinanceCheckinController.java

@@ -39,7 +39,7 @@ public class FinanceCheckinController {
     @PostMapping("/stats")
     public Result<Map<String, Object>> stats(
             @RequestBody Map<String, Object> params,
-            @RequestAttribute("userId") Long userId) {
+            @RequestAttribute(value = "userId", required = false) Long userId) {
         Long childId = params.get("childId") != null
                 ? Long.valueOf(params.get("childId").toString()) : null;
         Map<String, Object> stats = financeCheckinService.getCheckinStats(userId, childId);
@@ -50,7 +50,10 @@ public class FinanceCheckinController {
     @PostMapping("/create")
     public Result<FinanceCheckin> create(
             @RequestBody FinanceCheckin checkin,
-            @RequestAttribute("userId") Long userId) {
+            @RequestAttribute(value = "userId", required = false) Long userId) {
+        if (checkin.getCheckinType() == null || checkin.getCheckinType().trim().isEmpty()) {
+            return Result.error("checkinType不能为空");
+        }
         checkin.setUserId(userId);
         FinanceCheckin created = financeCheckinService.createCheckin(checkin);
         return Result.success(created);