2.7 KiB
2.7 KiB
Kiến Trúc Booking Service
Tài liệu kiến trúc cho Booking Service.
Tổng Quan Kiến Trúc
graph TB
subgraph "Tầng API"
SC[StaffController]
RC[ResourceController]
AC[AppointmentController]
end
subgraph "Tầng Domain"
SS[StaffSchedule]
R[Resource]
A[Appointment]
end
subgraph "Infrastructure"
DB[(PostgreSQL)]
REPO[Repositories]
end
SC --> SS
RC --> R
AC --> A
A --> SS
A --> R
SS --> DB
R --> DB
A --> DB
style A fill:#50c878,stroke:#2d8659,color:#fff
style R fill:#3498db,stroke:#2980b9,color:#fff
Database Schema
erDiagram
staff_schedules {
uuid id PK
uuid staff_id FK
uuid shop_id FK
int day_of_week
time start_time
time end_time
}
resources {
uuid id PK
uuid shop_id FK
varchar name
varchar resource_type
int capacity
}
appointments {
uuid id PK
uuid shop_id FK
uuid customer_id FK
uuid staff_id FK
uuid resource_id FK
uuid service_id FK
timestamp start_time
timestamp end_time
varchar status
}
staff_schedules ||--o{ appointments : assigned
resources ||--o{ appointments : booked
Appointment State Machine
stateDiagram-v2
[*] --> Scheduled: Đặt
Scheduled --> Confirmed: Xác Nhận
Scheduled --> Cancelled: Hủy
Confirmed --> InProgress: Check-in
InProgress --> Completed: Hoàn Tất
Confirmed --> NoShow: Không Đến
Confirmed --> Cancelled: Hủy
Thuật Toán Tìm Slot
flowchart TD
START[Yêu Cầu Tìm Slot] --> GET_STAFF[Lấy Lịch Nhân Viên]
GET_STAFF --> GET_RESOURCE[Lấy Khả Dụng Tài Nguyên]
GET_RESOURCE --> GET_APPTS[Lấy Cuộc Hẹn Đã Đặt]
GET_APPTS --> INTERSECT[Tính Giao Tập Hợp]
INTERSECT --> REMOVE[Loại Bỏ Slot Đã Đặt]
REMOVE --> SLOTS[Trả Về Slot Khả Dụng]
Tích Hợp Với Order Service
sequenceDiagram
participant Order as Order Service
participant Strategy as ServiceStrategy
participant Booking as Booking Service
Order->>Strategy: ValidateAsync(item)
Strategy->>Booking: Kiểm Tra Slot Khả Dụng
Booking-->>Strategy: Khả Dụng
Order->>Strategy: ExecuteAsync(item)
Strategy->>Booking: Tạo Cuộc Hẹn
Booking-->>Strategy: Cuộc Hẹn Đã Tạo