소스 검색

feat(doa): 新增DoaController(/api/doa 七接口)

Sisyphus 1 주 전
부모
커밋
c912aac571
1개의 변경된 파일117개의 추가작업 그리고 0개의 파일을 삭제
  1. 117 0
      cfc-backend/src/main/java/com/etotem/cfc/controller/DoaController.java

+ 117 - 0
cfc-backend/src/main/java/com/etotem/cfc/controller/DoaController.java

@@ -0,0 +1,117 @@
+package com.etotem.cfc.controller;
+
+import com.etotem.cfc.common.Result;
+import com.etotem.cfc.entity.DoaStage;
+import com.etotem.cfc.entity.DoaWeek;
+import com.etotem.cfc.service.DoaService;
+import com.etotem.cfc.util.ParamUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 家庭目标(DOA)REST 接口。
+ * 认证属性 familyId/userId 由 JwtInterceptor 写入。
+ */
+@RestController
+@RequestMapping("/api/doa")
+public class DoaController {
+
+    @Resource
+    private DoaService doaService;
+
+    /** 创建阶段:memberId 为空表示当前登录成员自己,goals 1-3 个 */
+    @PostMapping("/stage/create")
+    public Result<Long> createStage(@RequestBody Map<String, Object> params,
+                                    @RequestAttribute(value = "familyId", required = false) Long familyId,
+                                    @RequestAttribute(value = "userId", required = false) Long userId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        Long memberId = params.get("memberId") != null
+                ? Long.valueOf(params.get("memberId").toString()) : null;
+        String title = params.get("title") != null ? params.get("title").toString() : null;
+        Integer durationWeeks = params.get("durationWeeks") != null
+                ? Integer.parseInt(params.get("durationWeeks").toString()) : null;
+        List<Map<String, Object>> goals = params.get("goals") instanceof List
+                ? (List<Map<String, Object>>) params.get("goals") : null;
+        return doaService.createStage(memberId, userId, familyId, title, durationWeeks, goals);
+    }
+
+    /** 家庭总览:各成员当前 active 阶段 */
+    @PostMapping("/overview")
+    public Result<List<Map<String, Object>>> overview(@RequestAttribute(value = "familyId", required = false) Long familyId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        return Result.success(doaService.getFamilyOverview(familyId));
+    }
+
+    /** 阶段详情:stage + goals + weeks + memberUserId */
+    @PostMapping("/stage/detail")
+    public Result<DoaStage> stageDetail(@RequestBody Map<String, Object> params,
+                                        @RequestAttribute(value = "familyId", required = false) Long familyId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        Long stageId = ParamUtils.getLong(params.get("stageId"));
+        return doaService.getStageDetail(stageId, familyId);
+    }
+
+    /** 取消阶段:仅 active 可取消(本人或代管不能登录成员) */
+    @PostMapping("/stage/cancel")
+    public Result<Void> cancelStage(@RequestBody Map<String, Object> params,
+                                    @RequestAttribute(value = "familyId", required = false) Long familyId,
+                                    @RequestAttribute(value = "userId", required = false) Long userId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        Long stageId = ParamUtils.getLong(params.get("stageId"));
+        return doaService.cancelStage(stageId, userId, familyId);
+    }
+
+    /** 提交周计划(A表) */
+    @PostMapping("/week/plan")
+    public Result<Void> submitPlan(@RequestBody Map<String, Object> params,
+                                   @RequestAttribute(value = "familyId", required = false) Long familyId,
+                                   @RequestAttribute(value = "userId", required = false) Long userId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        Long weekId = ParamUtils.getLong(params.get("weekId"));
+        String plan = params.get("plan") != null ? params.get("plan").toString() : "";
+        return doaService.submitWeekPlan(weekId, plan, userId, familyId);
+    }
+
+    /** 提交周复盘(B表五问) */
+    @PostMapping("/week/review")
+    public Result<Void> submitReview(@RequestBody Map<String, Object> params,
+                                     @RequestAttribute(value = "familyId", required = false) Long familyId,
+                                     @RequestAttribute(value = "userId", required = false) Long userId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        Long weekId = ParamUtils.getLong(params.get("weekId"));
+        Map<String, String> review = new HashMap<>();
+        review.put("achieved", params.get("achieved") != null ? params.get("achieved").toString() : null);
+        review.put("experience", params.get("experience") != null ? params.get("experience").toString() : null);
+        review.put("worked", params.get("worked") != null ? params.get("worked").toString() : null);
+        review.put("improve", params.get("improve") != null ? params.get("improve").toString() : null);
+        review.put("nextChallenge", params.get("nextChallenge") != null ? params.get("nextChallenge").toString() : null);
+        return doaService.submitWeekReview(weekId, review, userId, familyId);
+    }
+
+    /** 周记录列表(按阶段查) */
+    @PostMapping("/week/list")
+    public Result<List<DoaWeek>> weekList(@RequestBody Map<String, Object> params,
+                                          @RequestAttribute(value = "familyId", required = false) Long familyId) {
+        if (familyId == null) {
+            return Result.noFamily("请先创建或加入家庭");
+        }
+        Long stageId = ParamUtils.getLong(params.get("stageId"));
+        return Result.success(doaService.listWeeks(stageId, familyId));
+    }
+}