| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import pandas as pd
- from tkinter import messagebox
- from flow_parser_base import FlowParserBase
- class BOCFlowParser(FlowParserBase):
- """中国银行流水解析器"""
-
- def parse(self, flow_file_path):
- """解析中国银行流水文件,返回标准化的流水数据"""
- try:
- flow_df = pd.read_excel(flow_file_path, dtype=str, header=8)
-
- flow_df.columns = flow_df.columns.str.strip()
-
- required_columns = [
- "交易类型[ Transaction Type ]",
- "交易日期[ Transaction Date ]",
- "交易时间[ Transaction time ]",
- "交易金额[ Trade Amount ]",
- "交易后余额[ After-transaction balance ]",
- "摘要[ Reference ]",
- "收款人名称[ Payee's Name ]",
- "收款人开户行名[ Beneficiary account bank ]",
- "付款人名称[ Payer's Name ]",
- "付款人开户行名[ Payer account bank ]"
- ]
-
- missing_fields = [k for k in required_columns if k not in flow_df.columns]
- if missing_fields:
- messagebox.showerror("错误", f"中国银行流水缺少必要列:{missing_fields}")
- return None
-
- standard_flow = []
- for _, row in flow_df.iterrows():
- transaction_type = str(row["交易类型[ Transaction Type ]"]).strip()
- transaction_date = str(row["交易日期[ Transaction Date ]"]).strip()
- transaction_time = str(row["交易时间[ Transaction time ]"]).strip()
- amount = pd.to_numeric(row["交易金额[ Trade Amount ]"], errors='coerce')
- balance = str(row["交易后余额[ After-transaction balance ]"]).strip()
- reference = str(row["摘要[ Reference ]"]).strip()
- payee_name = str(row["收款人名称[ Payee's Name ]"]).strip()
- payee_bank = str(row["收款人开户行名[ Beneficiary account bank ]"]).strip()
- payer_name = str(row["付款人名称[ Payer's Name ]"]).strip()
- payer_bank = str(row["付款人开户行名[ Payer account bank ]"]).strip()
-
- if pd.isna(amount) or amount == 0:
- continue
-
- if transaction_type == "往账":
- income = 0
- expense = abs(amount)
- opponent_name = payee_name
- opponent_bank = payee_bank
- elif transaction_type == "来账":
- income = abs(amount)
- expense = 0
- opponent_name = payer_name
- opponent_bank = payer_bank
- else:
- continue
-
- transaction_datetime = f"{transaction_date} {transaction_time}"
-
- standard_flow.append({
- "交易时间": transaction_datetime,
- "对方户名": opponent_name,
- "摘要": reference,
- "收入": income,
- "支出": expense,
- "对方开户机构": opponent_bank,
- "备注": opponent_bank,
- "余额": balance
- })
-
- return pd.DataFrame(standard_flow)
- except Exception as e:
- messagebox.showerror("错误", f"解析中国银行流水失败:{str(e)}")
- return None
-
- def get_bank_name(self):
- """返回银行名称"""
- return "中国银行"
|