Add snapshot of booking-window rules to train schedules and update related logic

This commit is contained in:
Marshal
2026-07-03 18:45:45 +00:00
parent 0ac5adcee9
commit 8db19dfacf
5 changed files with 142 additions and 8 deletions

View File

@@ -111,6 +111,27 @@ export class TrainSchedule extends BaseEntity {
@Column({ name: 'booking_cycle_no', type: 'int', default: 0 })
bookingCycleNo!: number;
// ── Booking-window rule snapshot ──────────────────────────────────────────
// The scheduling rule this train was created with, frozen at creation. A later
// global-rules edit applies only to FUTURE schedules — an already-open schedule
// keeps its base rule. The batch board derives its display windows (open time +
// reopen cycles) from THIS snapshot, never from the live global config. NULL on
// legacy rows created before the snapshot existed (board falls back to live cfg).
@Column({ name: 'rule_window_open_hour', type: 'int', nullable: true })
ruleWindowOpenHour?: number | null;
@Column({ name: 'rule_window_duration_hours', type: 'numeric', precision: 6, scale: 4, nullable: true })
ruleWindowDurationHours?: number | null;
@Column({ name: 'rule_reopen_delay_minutes', type: 'int', nullable: true })
ruleReopenDelayMinutes?: number | null;
@Column({ name: 'rule_import_window_lead_days', type: 'int', nullable: true })
ruleImportWindowLeadDays?: number | null;
@Column({ name: 'rule_export_booking_lead_hours', type: 'int', nullable: true })
ruleExportBookingLeadHours?: number | null;
@OneToMany(() => TrainScheduleBooking, (scheduleBooking) => scheduleBooking.trainSchedule)
scheduleBookings?: TrainScheduleBooking[];
}