Browse Source

feat(self-check): 新增 /status 和 /ignore 接口;/questions 支持 retake 参数

iwt 2 weeks ago
parent
commit
48675eb729

+ 37 - 3
cfc-backend/src/main/java/com/etotem/cfc/controller/family/FiveDimensionSelfCheckController.java

@@ -8,16 +8,20 @@ import com.etotem.cfc.entity.User;
 import com.etotem.cfc.mapper.UserMapper;
 import com.etotem.cfc.service.FiveDimensionSelfCheckService;
 import com.etotem.cfc.service.UnlockGateService;
+import com.etotem.cfc.util.ParamUtils;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 五维家庭自检问卷(P0-1)
@@ -37,12 +41,18 @@ public class FiveDimensionSelfCheckController {
     @Resource
     private UserMapper userMapper;
 
-    @Operation(summary = "获取自检问卷题目(15题静态题库)")
+    @Operation(summary = "获取自检问卷题目(首次固定 15 题;再次合并题库随机抽)")
     @PostMapping("/questions")
-    public Result<List<SelfCheckQuestionVO>> getQuestions(@RequestAttribute("userId") Long userId) {
+    public Result<List<SelfCheckQuestionVO>> getQuestions(
+            @RequestAttribute("userId") Long userId,
+            @RequestBody(required = false) Map<String, Object> body) {
         if (userId == null) {
             return Result.error("请先登录");
         }
+        Boolean retake = body != null && body.get("retake") != null && Boolean.TRUE.equals(body.get("retake"));
+        if (retake) {
+            return Result.success(selfCheckService.getQuestionsForRetake(userId));
+        }
         return Result.success(selfCheckService.getQuestions());
     }
 
@@ -98,4 +108,28 @@ public class FiveDimensionSelfCheckController {
             return Result.error(e.getMessage());
         }
     }
+
+    @Operation(summary = "获取自检状态(是否有记录、是否可检、距下次提醒天数)")
+    @PostMapping("/status")
+    public Result<Map<String, Object>> getStatus(@RequestAttribute("userId") Long userId) {
+        if (userId == null) {
+            return Result.error("请先登录");
+        }
+        return Result.success(selfCheckService.getStatus(userId));
+    }
+
+    @Operation(summary = "忽略本次自检提醒(重置 15 天计时)")
+    @PostMapping("/ignore")
+    public Result<Map<String, Object>> ignoreSelfCheck(@RequestBody(required = false) Map<String, Object> body,
+                                                       @RequestAttribute("userId") Long userId) {
+        if (userId == null) {
+            return Result.error("请先登录");
+        }
+        Long checkId = body != null ? ParamUtils.getLong(body.get("checkId")) : null;
+        Date ignoredAt = selfCheckService.ignoreSelfCheck(userId, checkId);
+        Map<String, Object> resp = new HashMap<>();
+        resp.put("nextRemindAt", new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(
+                new Date(ignoredAt.getTime() + 15L * 24 * 60 * 60 * 1000)));
+        return Result.success(resp);
+    }
 }