Bladeren bron

feat(assessment.planner.select): S-cfc-369 测评预约创建前校验所选规划师 ∈ 家庭已绑定T列表(SC-P-32 未绑定提示先绑定)

- AssessmentAppointmentController: 注入 GuideFamilyService;createAppointment 未指定规划师/评估师
  或所选 guideId 不在家庭绑定列表 → 返回「请先绑定规划师」,且不消耗额度、不创建预约
- AssessmentAppointmentService: 新增 requireBoundPlanner(guideId, familyId)(复用
  GuideFamilyService.isBound 家庭维度反查,区别于规划师侧 GuideFamilyAccessGuard)
- AssessmentPlannerSelectContractTest 7红转绿
Sisyphus 1 dag geleden
bovenliggende
commit
4c0ff6729

+ 20 - 1
cfc-backend/src/main/java/com/etotem/cfc/controller/assessment/AssessmentAppointmentController.java

@@ -9,6 +9,7 @@ import com.etotem.cfc.mapper.UserMapper;
 import com.etotem.cfc.service.AssessmentAppointmentService;
 import com.etotem.cfc.service.AssessmentQuotaService;
 import com.etotem.cfc.service.DanAssessmentExecutionService;
+import com.etotem.cfc.service.GuideFamilyService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.web.bind.annotation.*;
@@ -38,6 +39,9 @@ public class AssessmentAppointmentController {
     @Resource
     private UserMapper userMapper;
 
+    @Resource
+    private GuideFamilyService guideFamilyService;
+
     @Operation(summary = "创建评估预约(含新执行记录)")
     @PostMapping("/create")
     public Result<Map<String, Object>> createAppointment(
@@ -56,8 +60,23 @@ public class AssessmentAppointmentController {
         if (memberId == null || quotaId == null) {
             return Result.error("memberId和quotaId不能为空");
         }
+        // 契约 assessment.planner.select(SC-P-32 / API_REFERENCE §4.10『预约前需规划师绑定』):
+        // 家长侧选规划师 = 所选规划师(guideId)必须属于家庭已绑定 T 列表;未绑定 → 提示先绑定。
         if (assessorId == null && guideId == null) {
-            return Result.error("assessorId或guideId必须提供一个");
+            return Result.error("请先绑定规划师");
+        }
+        if (guideId != null) {
+            // 家庭维度反查:复用绑定 T 列表数据源(POST /api/bind/guides)的 isBound 校验,
+            // 与规划师侧守卫(GuideFamilyAccessGuard.checkBinding)方向区分。
+            AssessmentQuota quotaForBind = quotaService.getById(quotaId);
+            if (quotaForBind != null) {
+                // 额度可解析出家庭 → 校验所选规划师 ∈ 家庭已绑定列表;
+                // 额度无法解析(getById=null)则交由后续额度校验流程兜底,不在此阻断。
+                Long familyIdForBind = quotaForBind.getFamilyId();
+                if (!appointmentService.requireBoundPlanner(guideId, familyIdForBind)) {
+                    return Result.error("请先绑定规划师");
+                }
+            }
         }
 
         User user = userMapper.selectById(userId);

+ 18 - 0
cfc-backend/src/main/java/com/etotem/cfc/service/AssessmentAppointmentService.java

@@ -24,6 +24,24 @@ public class AssessmentAppointmentService extends ServiceImpl<AssessmentAppointm
     @Resource
     private EnergyService energyService;
 
+    @Resource
+    private GuideFamilyService guideFamilyService;
+
+    /**
+     * 契约 assessment.planner.select(SC-P-32 测评选规划师 → 绑定的 T 列表):
+     * 家长侧选规划师时,所选规划师(guideId)必须属于该家庭已绑定的 T 列表。
+     * 家庭维度反查绑定(区别于规划师侧 {@link GuideFamilyAccessGuard#checkBinding} 的
+     * guide 维度守卫,方向相反)。
+     *
+     * @return true 表示规划师已绑定到该家庭(可指定);false 表示未绑定(应提示先绑定)
+     */
+    public boolean requireBoundPlanner(Long guideId, Long familyId) {
+        if (guideId == null || familyId == null) {
+            return false;
+        }
+        return guideFamilyService.isBound(guideId, familyId);
+    }
+
     public AssessmentAppointment createAppointment(Long userId, Long memberId, Long guideId,
                                                    Long assessorId, Long packageId, String appointmentDate, String appointmentTime, String notes) {
         // 2026-10-23 新口径:测评预约不是特殊功能,不设 BASIC 会员配额(原 ASSESSMENT_QUOTA 硬门禁已移除,迁移 382)