from __future__ import annotations

from pathlib import Path

from openpyxl import load_workbook


ROOT = Path(__file__).resolve().parents[1]
FILES = [
    "订单状态流转_链路流程线整理.xlsx",
    "SaaS_E2E测试用例_单Sheet用例测试列表.xlsx",
]
KEYWORDS = ["子单申诉", "申诉", "处罚", "赔偿", "驳回", "同意"]


def text(value) -> str:
    return str(value or "").replace("\n", " ").strip()


def main() -> None:
    for filename in FILES:
        wb = load_workbook(ROOT / filename, read_only=True, data_only=True)
        for ws in wb.worksheets:
            headers = {str(ws.cell(1, col).value or ""): col for col in range(1, ws.max_column + 1)}
            id_col = headers.get("用例编号") or headers.get("链路编号")
            if not id_col:
                continue
            for row in range(2, ws.max_row + 1):
                cells = [text(ws.cell(row, col).value) for col in range(1, min(ws.max_column, 12) + 1)]
                joined = " ".join(cells)
                if any(key in joined for key in KEYWORDS):
                    print(filename, ws.title, row, "\t".join(cells[:11]), sep="\t")


if __name__ == "__main__":
    main()
