ccb_parser.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pandas as pd
  2. from tkinter import messagebox
  3. from flow_parser_base import FlowParserBase
  4. class CCBFlowParser(FlowParserBase):
  5. """建设银行流水解析器"""
  6. def parse(self, flow_file_path):
  7. """解析建行流水文件,返回标准化的流水数据"""
  8. try:
  9. flow_df = pd.read_excel(flow_file_path, dtype=str, header=9)
  10. flow_df.columns = flow_df.columns.str.strip()
  11. required_columns = ["交易时间", "对方户名", "摘要", "贷方发生额/元(收入)", "借方发生额/元(支取)", "对方开户机构", "备注", "余额"]
  12. missing_fields = [k for k in required_columns if k not in flow_df.columns]
  13. if missing_fields:
  14. messagebox.showerror("错误", f"建行流水缺少必要列:{missing_fields}")
  15. return None
  16. standard_flow = flow_df[required_columns].copy()
  17. standard_flow = standard_flow.rename(columns={
  18. "贷方发生额/元(收入)": "收入",
  19. "借方发生额/元(支取)": "支出"
  20. })
  21. standard_flow["收入"] = pd.to_numeric(standard_flow["收入"], errors='coerce').fillna(0)
  22. standard_flow["支出"] = pd.to_numeric(standard_flow["支出"], errors='coerce').fillna(0)
  23. return standard_flow
  24. except Exception as e:
  25. messagebox.showerror("错误", f"解析建行流水失败:{str(e)}")
  26. return None
  27. def get_bank_name(self):
  28. """返回银行名称"""
  29. return "建设银行"