|
|
@@ -0,0 +1,136 @@
|
|
|
+package com.zxyj.controller.assessment;
|
|
|
+
|
|
|
+import com.zxyj.common.Result;
|
|
|
+import com.zxyj.entity.AssessmentAppointment;
|
|
|
+import com.zxyj.entity.AssessmentOrder;
|
|
|
+import com.zxyj.entity.User;
|
|
|
+import com.zxyj.mapper.UserMapper;
|
|
|
+import com.zxyj.service.AssessmentAppointmentService;
|
|
|
+import com.zxyj.service.AssessmentOrderService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Tag(name = "评估预约", description = "评估预约管理")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/assessment/appointment")
|
|
|
+public class AssessmentAppointmentController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AssessmentAppointmentService appointmentService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private AssessmentOrderService orderService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UserMapper userMapper;
|
|
|
+
|
|
|
+ @Operation(summary = "创建评估预约")
|
|
|
+ @PostMapping("/create")
|
|
|
+ public Result<Map<String, Object>> createAppointment(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, Object> body) {
|
|
|
+
|
|
|
+ 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 packageId = body.get("packageId") != null ? Long.valueOf(body.get("packageId").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;
|
|
|
+ Long totalPrice = body.get("totalPrice") != null ? Long.valueOf(body.get("totalPrice").toString()) : 0L;
|
|
|
+ String guideName = body.get("guideName") != null ? body.get("guideName").toString() : null;
|
|
|
+ String packageName = body.get("packageName") != null ? body.get("packageName").toString() : null;
|
|
|
+ Long discountAmount = body.get("discountAmount") != null ? Long.valueOf(body.get("discountAmount").toString()) : 0L;
|
|
|
+
|
|
|
+ User user = userMapper.selectById(userId);
|
|
|
+ if (user == null) return Result.error("用户不存在");
|
|
|
+
|
|
|
+ AssessmentAppointment appointment = appointmentService.createAppointment(
|
|
|
+ userId, childId, guideId, packageId, appointmentDate, appointmentTime, notes);
|
|
|
+
|
|
|
+ Long familyId = user.getFamilyId();
|
|
|
+ AssessmentOrder order = orderService.createOrder(
|
|
|
+ familyId, userId, childId, guideId, packageId,
|
|
|
+ guideName, packageName, totalPrice, discountAmount);
|
|
|
+
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("appointmentId", appointment.getId());
|
|
|
+ result.put("orderNo", order.getOrderNo());
|
|
|
+ result.put("actualPrice", order.getActualPrice());
|
|
|
+ result.put("status", order.getStatus());
|
|
|
+
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "取消预约")
|
|
|
+ @PostMapping("/cancel/{id}")
|
|
|
+ public Result<Boolean> cancelAppointment(@PathVariable Long id) {
|
|
|
+ boolean success = appointmentService.cancelAppointment(id);
|
|
|
+ return Result.success(success);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "我的预约列表(家长视角)")
|
|
|
+ @PostMapping("/my-list")
|
|
|
+ public Result<List<Map<String, Object>>> getMyAppointments(@RequestAttribute("userId") Long userId) {
|
|
|
+ List<AssessmentAppointment> appointments = appointmentService.getByUserId(userId);
|
|
|
+ List<Map<String, Object>> result = appointments.stream().map(this::toMap).collect(Collectors.toList());
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "成长规划师的预约列表")
|
|
|
+ @PostMapping("/guide-list")
|
|
|
+ public Result<List<Map<String, Object>>> getGuideAppointments(
|
|
|
+ @RequestAttribute("userId") Long userId,
|
|
|
+ @RequestAttribute("role") String role) {
|
|
|
+ if (!"teacher".equals(role)) {
|
|
|
+ return Result.error("只有成长规划师可以查看此列表");
|
|
|
+ }
|
|
|
+ List<AssessmentAppointment> appointments = appointmentService.getByGuideId(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("appointmentDate", appt.getAppointmentDate());
|
|
|
+ map.put("appointmentTime", appt.getAppointmentTime());
|
|
|
+ map.put("status", appt.getStatus());
|
|
|
+ map.put("statusText", getStatusText(appt.getStatus()));
|
|
|
+ map.put("notes", appt.getNotes());
|
|
|
+ map.put("createdAt", appt.getCreatedAt());
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStatusText(String status) {
|
|
|
+ if (status == null) return "未知";
|
|
|
+ switch (status) {
|
|
|
+ case "pending": return "待确认";
|
|
|
+ case "confirmed": return "已确认";
|
|
|
+ case "completed": return "已完成";
|
|
|
+ case "cancelled": return "已取消";
|
|
|
+ default: return "未知";
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|