迁移脚本的一些修复
This commit is contained in:
@@ -39,7 +39,7 @@ def _read_iccid_pairs(cards_csv: Path) -> list[tuple[str, str, bool]]:
|
||||
"""
|
||||
if not cards_csv.exists():
|
||||
raise FileNotFoundError(f"找不到 {cards_csv},请按 resources/README.md 准备")
|
||||
pairs: dict[str, tuple[str, bool]] = {}
|
||||
pairs: dict[str, tuple[str, str, bool]] = {}
|
||||
first_seen_line: dict[str, int] = {}
|
||||
errors: list[str] = []
|
||||
with cards_csv.open("r", encoding="utf-8-sig", newline="") as f:
|
||||
@@ -69,17 +69,19 @@ def _read_iccid_pairs(cards_csv: Path) -> list[tuple[str, str, bool]]:
|
||||
if i20 and i20[:19] != i19:
|
||||
errors.append(f"第 {line_no} 行 iccid_20 前 19 位必须等于 iccid_19: {i20!r}")
|
||||
continue
|
||||
if i19 in pairs:
|
||||
errors.append(f"第 {line_no} 行 iccid_19 与第 {first_seen_line[i19]} 行重复: {i19!r}")
|
||||
# 有 iccid_20 的卡用 iccid_20 做唯一键,避免同批次卡派生出相同 iccid_19 误报重复
|
||||
dedup_key = i20 if i20 else i19
|
||||
if dedup_key in pairs:
|
||||
errors.append(f"第 {line_no} 行 {'iccid_20' if i20 else 'iccid_19'} 与第 {first_seen_line[dedup_key]} 行重复: {dedup_key!r}")
|
||||
continue
|
||||
first_seen_line[i19] = line_no
|
||||
pairs[i19] = (i20, allow_i19_lookup)
|
||||
first_seen_line[dedup_key] = line_no
|
||||
pairs[dedup_key] = (i19, i20, allow_i19_lookup)
|
||||
if errors:
|
||||
preview = "\n".join(f" - {msg}" for msg in errors[:20])
|
||||
if len(errors) > 20:
|
||||
preview += f"\n - 其余 {len(errors) - 20} 个错误已省略"
|
||||
raise ValueError(f"{cards_csv} 存在无效 ICCID,请先修正后再扫描:\n{preview}")
|
||||
return [(i19, i20, allow_i19_lookup) for i19, (i20, allow_i19_lookup) in sorted(pairs.items())]
|
||||
return [v for _, v in sorted(pairs.items())]
|
||||
|
||||
|
||||
def main() -> int:
|
||||
@@ -104,13 +106,13 @@ def main() -> int:
|
||||
|
||||
dsn = mapping_loader.load_legacy_dsn(config_dir)
|
||||
with legacy_query.connect_readonly(dsn) as conn:
|
||||
card_metas, dup_iccid_19 = legacy_query.fetch_card_meta(conn, iccid_pairs)
|
||||
card_metas, dup_iccids = legacy_query.fetch_card_meta(conn, iccid_pairs)
|
||||
meal_ids = {m.current_meal_id for m in card_metas.values() if m.current_meal_id}
|
||||
meal_metas = legacy_query.fetch_meal_meta(conn, meal_ids)
|
||||
|
||||
if dup_iccid_19:
|
||||
print(f"警告:{len(dup_iccid_19)} 张卡的 iccid_19 在奇成 tbl_card 命中多条记录:")
|
||||
for x in sorted(dup_iccid_19):
|
||||
if dup_iccids:
|
||||
print(f"警告:{len(dup_iccids)} 张卡的 ICCID 在奇成 tbl_card 命中多条记录:")
|
||||
for x in sorted(dup_iccids):
|
||||
print(f" - {x}")
|
||||
print("这些卡 migrate_assets 阶段会写 errors.csv 阻断,请业务方人工确认。")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user