package com.tourguide.modules.order.dto; import com.tourguide.modules.order.entity.TourOrder; import java.time.LocalDateTime; import java.util.Collections; import java.util.List; /** 导游端订单列表与详情返回对象,仅暴露导游工作台需要的订单信息。 */ public class GuideOrderResponse { private final Long id; private final String orderNo; private final String scenicName; private final String scenicShortName; private final String meetingPointName; private final String serviceName; private final Integer durationMinutes; private final Integer quantity; private final String status; private final LocalDateTime receiveTime; private final LocalDateTime receiveStartTime; private final LocalDateTime lectureStartTime; private final LocalDateTime lectureEndTime; private final LocalDateTime completedAt; private final String customerPhone; private final List customers; private GuideOrderResponse(TourOrder order) { this.id = order.getId(); this.orderNo = order.getOrderNo(); this.scenicName = order.getScenicName(); this.scenicShortName = shortScenicName(order.getScenicName()); this.meetingPointName = order.getMeetingPointName(); this.serviceName = serviceName(order); this.durationMinutes = durationMinutes(order.getOrderType()); this.quantity = order.getPeopleCount() == null ? 0 : order.getPeopleCount(); this.status = guideStatus(order.getStatus()); this.receiveTime = firstPresent(order.getAcceptedAt(), order.getPlacedAt(), order.getCreatedAt()); this.receiveStartTime = this.receiveTime; this.lectureStartTime = firstPresent(order.getServiceStartedAt(), order.getArrivedAt()); this.lectureEndTime = order.getCompletedAt(); this.completedAt = order.getCompletedAt(); this.customerPhone = order.getVisitorMobile(); this.customers = Collections.singletonList(new Customer( 1, order.getVisitorMobile(), this.quantity, firstPresent(order.getAcceptedAt(), order.getPlacedAt(), order.getCreatedAt()))); } public static GuideOrderResponse from(TourOrder order) { return new GuideOrderResponse(order); } private static String guideStatus(String orderStatus) { if ("IN_SERVICE".equals(orderStatus)) { return "serving"; } if ("COMPLETED".equals(orderStatus)) { return "completed"; } if ("CANCELLED".equals(orderStatus) || "REFUNDED".equals(orderStatus)) { return "canceled"; } return "accepted"; } private static String serviceName(TourOrder order) { if (order.getPackageName() != null && !order.getPackageName().trim().isEmpty()) { return order.getPackageName(); } if ("GROUP_PREMIUM".equals(order.getOrderType())) { return "拼团 · 精讲"; } if ("PRIVATE_QUICK".equals(order.getOrderType())) { return "包团 · 快讲"; } if ("PRIVATE_PREMIUM".equals(order.getOrderType())) { return "包团 · 精讲"; } return "拼团 · 快讲"; } private static Integer durationMinutes(String orderType) { if ("GROUP_PREMIUM".equals(orderType) || "PRIVATE_PREMIUM".equals(orderType)) { return 60; } return 30; } private static String shortScenicName(String scenicName) { if (scenicName == null || scenicName.trim().isEmpty()) { return ""; } return scenicName.replace("景区", ""); } private static LocalDateTime firstPresent(LocalDateTime first, LocalDateTime second) { return first == null ? second : first; } private static LocalDateTime firstPresent(LocalDateTime first, LocalDateTime second, LocalDateTime third) { return firstPresent(firstPresent(first, second), third); } public Long getId() { return id; } public String getOrderNo() { return orderNo; } public String getScenicName() { return scenicName; } public String getScenicShortName() { return scenicShortName; } public String getMeetingPointName() { return meetingPointName; } public String getServiceName() { return serviceName; } public Integer getDurationMinutes() { return durationMinutes; } public Integer getQuantity() { return quantity; } public String getStatus() { return status; } public LocalDateTime getReceiveTime() { return receiveTime; } public LocalDateTime getReceiveStartTime() { return receiveStartTime; } public LocalDateTime getLectureStartTime() { return lectureStartTime; } public LocalDateTime getLectureEndTime() { return lectureEndTime; } public LocalDateTime getCompletedAt() { return completedAt; } public String getCustomerPhone() { return customerPhone; } public List getCustomers() { return customers; } public static class Customer { private final int no; private final String phone; private final int people; private final LocalDateTime time; public Customer(int no, String phone, int people, LocalDateTime time) { this.no = no; this.phone = phone; this.people = people; this.time = time; } public int getNo() { return no; } public String getPhone() { return phone; } public int getPeople() { return people; } public LocalDateTime getTime() { return time; } } }