Sfoglia il codice sorgente

feat(api): 重构 AppointmentController 接入 DanAssessmentExecutionService 双角色模型

Ultraworked with Sisyphus

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Sisyphus 2 mesi fa
parent
commit
18931ceada

+ 41 - 14
cfc-backend/src/main/java/com/etotem/cfc/controller/assessment/AssessmentAppointmentController.java

@@ -2,13 +2,13 @@ package com.etotem.cfc.controller.assessment;
 
 import com.etotem.cfc.common.Result;
 import com.etotem.cfc.entity.AssessmentAppointment;
-import com.etotem.cfc.entity.AssessmentExecution;
 import com.etotem.cfc.entity.AssessmentQuota;
+import com.etotem.cfc.entity.DanAssessmentExecution;
 import com.etotem.cfc.entity.User;
 import com.etotem.cfc.mapper.UserMapper;
 import com.etotem.cfc.service.AssessmentAppointmentService;
-import com.etotem.cfc.service.AssessmentExecutionService;
 import com.etotem.cfc.service.AssessmentQuotaService;
+import com.etotem.cfc.service.DanAssessmentExecutionService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.web.bind.annotation.*;
@@ -31,12 +31,12 @@ public class AssessmentAppointmentController {
     private AssessmentQuotaService quotaService;
 
     @Resource
-    private AssessmentExecutionService executionService;
+    private DanAssessmentExecutionService danAssessmentExecutionService;
 
     @Resource
     private UserMapper userMapper;
 
-    @Operation(summary = "创建评估预约")
+    @Operation(summary = "创建评估预约(含新执行记录)")
     @PostMapping("/create")
     public Result<Map<String, Object>> createAppointment(
             @RequestAttribute("userId") Long userId,
@@ -44,6 +44,7 @@ public class AssessmentAppointmentController {
 
         Long childId = body.get("childId") != null ? Long.valueOf(body.get("childId").toString()) : null;
         Long guideId = body.get("guideId") != null ? Long.valueOf(body.get("guideId").toString()) : null;
+        Long assessorId = body.get("assessorId") != null ? Long.valueOf(body.get("assessorId").toString()) : null;
         String appointmentDate = body.get("appointmentDate") != null ? body.get("appointmentDate").toString() : null;
         String appointmentTime = body.get("appointmentTime") != null ? body.get("appointmentTime").toString() : null;
         String notes = body.get("notes") != null ? body.get("notes").toString() : null;
@@ -52,6 +53,9 @@ public class AssessmentAppointmentController {
         if (childId == null || quotaId == null) {
             return Result.error("childId和quotaId不能为空");
         }
+        if (assessorId == null && guideId == null) {
+            return Result.error("assessorId或guideId必须提供一个");
+        }
 
         User user = userMapper.selectById(userId);
         if (user == null) return Result.error("用户不存在");
@@ -62,11 +66,25 @@ public class AssessmentAppointmentController {
             return Result.error("额度不足或已过期");
         }
 
-        AssessmentAppointment appointment = appointmentService.createAppointment(
-                userId, childId, guideId, null, appointmentDate, appointmentTime, notes);
+        // 获取额度信息(含 familyId, productOrderId)
+        AssessmentQuota quota = quotaService.getById(quotaId);
+        if (quota == null) return Result.error("额度记录不存在");
 
-        // 创建执行记录
-        AssessmentExecution exec = executionService.create(quotaId, childId, appointment.getId());
+        // 创建预约
+        AssessmentAppointment appointment = appointmentService.createAppointment(
+                userId, childId, guideId, assessorId, null, appointmentDate, appointmentTime, notes);
+
+        // 创建新执行记录(dan_assessment_executions,含 assessor 角色)
+        Long finalAssessorId = assessorId != null ? assessorId : guideId;
+        DanAssessmentExecution exec = danAssessmentExecutionService.createExecution(
+                quota.getProductOrderId(), // assessmentOrderId 复用 shop productOrderId
+                childId,
+                quota.getFamilyId(),
+                quotaId,
+                finalAssessorId,
+                null, // plannerId(可选)
+                appointment.getId()
+        );
 
         Map<String, Object> result = new HashMap<>();
         result.put("appointmentId", appointment.getId());
@@ -76,17 +94,16 @@ public class AssessmentAppointmentController {
         return Result.success(result);
     }
 
-    @Operation(summary = "确认预约")
+    @Operation(summary = "确认预约(由指派的测评师确认)")
     @PostMapping("/confirm/{id}")
     public Result<Boolean> confirmAppointment(
             @RequestAttribute("userId") Long userId,
-            @RequestAttribute("role") String role,
             @PathVariable Long id) {
-        if (!"teacher".equals(role)) {
-            return Result.error("只有成长规划师可以确认预约");
-        }
         boolean success = appointmentService.confirmAppointment(id, userId);
-        return Result.success(success);
+        if (!success) {
+            return Result.error("确认失败,您不是被指派的测评师");
+        }
+        return Result.success(true);
     }
 
     @Operation(summary = "取消预约")
@@ -117,11 +134,21 @@ public class AssessmentAppointmentController {
         return Result.success(result);
     }
 
+    @Operation(summary = "测评师的预约列表")
+    @PostMapping("/assessor-list")
+    public Result<List<Map<String, Object>>> getAssessorAppointments(
+            @RequestAttribute("userId") Long userId) {
+        List<AssessmentAppointment> appointments = appointmentService.getByAssessorId(userId);
+        List<Map<String, Object>> result = appointments.stream().map(this::toMap).collect(Collectors.toList());
+        return Result.success(result);
+    }
+
     private Map<String, Object> toMap(AssessmentAppointment appt) {
         Map<String, Object> map = new HashMap<>();
         map.put("id", appt.getId());
         map.put("childId", appt.getChildId());
         map.put("guideId", appt.getGuideId());
+        map.put("assessorId", appt.getAssessorId());
         map.put("appointmentDate", appt.getAppointmentDate());
         map.put("appointmentTime", appt.getAppointmentTime());
         map.put("status", appt.getStatus());