fix: support bilingual Booking Excel headers

This commit is contained in:
Wyndham ARR
2026-08-11 15:29:42 +08:00
parent ca3e8e18fa
commit c947230471
15 changed files with 366 additions and 30 deletions

View File

@@ -14,7 +14,7 @@ from typing import Iterable, Mapping, Optional
PROCESSOR_NAME = "booking-excel-importer"
PROCESSOR_VERSION = "2.0.0"
PROCESSOR_VERSION = "2.1.0"
RESULT_SCHEMA_VERSION = "1.0"
XLSX_MIME = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
MAX_UPLOAD_BYTES = 25 * 1024 * 1024
@@ -183,21 +183,28 @@ def _normalized_header(value: object) -> str:
return re.sub(r"[\s._\-/\\:()]+", "", normalized)
HEADER_LABELS = {
"tour_code": (
"Tour Code",
"Group Code",
"Gourp Code",
"团号",
"团队代码",
"Tour Code / 主团号",
),
"hotel": (
"โรงแรม",
"วางข้อมูลที่นี่ / 酒店明细",
"Raw Hotel Detail / วางข้อมูลที่นี่ / 酒店明细",
),
}
# Keep the approved source labels readable while applying one exact normalized
# comparison to every workbook header. This is deliberately not substring or
# fuzzy matching: an unrecognized supplier change must fail safely.
HEADER_ALIASES = {
"tour_code": frozenset(
{
"TOURCODE",
"GROUPCODE",
"GOURPCODE",
"团号",
"团队代码",
}
),
"hotel": frozenset(
{
"โรงแรม",
}
),
key: frozenset(_normalized_header(label) for label in labels)
for key, labels in HEADER_LABELS.items()
}
ROOM_BRACKET_PATTERN = re.compile(
@@ -305,7 +312,7 @@ def _header_columns(cells: Iterable[object]) -> dict[str, int] | None:
if any(len(matches[key]) != 1 for key in matches):
raise BookingExcelError(
"BOOKING_EXCEL_HEADERS_AMBIGUOUS",
"Excel 表头重复,无法确定 Tour Code 或โรงแรม",
"Excel 表头重复,无法唯一确定 Tour Code/主团号或酒店明细",
)
return {key: values[0] for key, values in matches.items()}
@@ -643,7 +650,7 @@ def parse_excel_bytes(payload: bytes) -> ExcelDocument:
if not data_sheets:
raise BookingExcelError(
"BOOKING_EXCEL_HEADERS_MISSING",
"Excel 中未找到同时包含 Tour Code 和โรงแรม的工作表",
"Excel 中未找到同时包含 Tour Code/主团号和酒店明细的工作表",
)
if not rows:
raise BookingExcelError(