feat: 完善批量导入逻辑,8步冒烟全绿

This commit is contained in:
simonkoson
2026-05-19 20:05:15 +08:00
parent 14c9841b35
commit f4661863a7
4 changed files with 264 additions and 4 deletions
+4 -3
View File
@@ -10,6 +10,7 @@ Excel 解析服务 — 批量导入核心逻辑
- Phase 2 不支持重播行(is_rerun=是 → 报错标记为失败行)
"""
import io
import uuid
from datetime import date
from typing import Any
@@ -121,8 +122,9 @@ class ExcelService:
def import_episodes(self, file_content: bytes) -> dict:
"""解析 Excel,批量导入 episodes。返回 ImportResult 结构。"""
# 1. 读取 Excel
df = pd.read_excel(file_content, engine="openpyxl")
# 1. 读取 Excelpandas 2.x 要求 file-like object,用 BytesIO 包装 bytes
file_like = io.BytesIO(file_content)
df = pd.read_excel(file_like, engine="openpyxl")
rows = df.to_dict(orient="records")
# 2. 解析 air_date 并提取年份
@@ -239,7 +241,6 @@ def generate_error_excel(errors: list[dict]) -> bytes:
row_data = [err["row_number"], err["reason"]] + list(err["raw_data"].values())
ws.append(row_data)
wb.add_named_style("error_header")
output = io.BytesIO()
wb.save(output)
output.seek(0)