|
|
@@ -0,0 +1,68 @@
|
|
|
+import pandas as pd
|
|
|
+from tkinter import messagebox
|
|
|
+from flow_parser_base import FlowParserBase
|
|
|
+
|
|
|
+
|
|
|
+class ABCFlowParser(FlowParserBase):
|
|
|
+ """农业银行流水解析器"""
|
|
|
+
|
|
|
+ def parse(self, flow_file_path):
|
|
|
+ """解析农行流水文件,返回标准化的流水数据"""
|
|
|
+ try:
|
|
|
+ flow_df = pd.read_excel(flow_file_path, dtype=str, header=2)
|
|
|
+
|
|
|
+ flow_df.columns = flow_df.columns.str.strip()
|
|
|
+
|
|
|
+ required_columns = ["交易时间", "收入金额", "支出金额", "账户余额", "对方账号", "对方户名", "对方开户行", "摘要"]
|
|
|
+
|
|
|
+ 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
|
|
|
+
|
|
|
+ filtered_df = flow_df.copy()
|
|
|
+ filtered_df = filtered_df[filtered_df["交易时间"].str.contains(r"\d{4}-\d{2}-\d{2}", na=False)]
|
|
|
+
|
|
|
+ filtered_df["交易时间"] = pd.to_datetime(filtered_df["交易时间"], errors='coerce')
|
|
|
+ filtered_df = filtered_df.sort_values("交易时间", ascending=True)
|
|
|
+
|
|
|
+ standard_flow = []
|
|
|
+ for _, row in filtered_df.iterrows():
|
|
|
+ transaction_time = row["交易时间"]
|
|
|
+ income_amount = pd.to_numeric(row["收入金额"], errors='coerce')
|
|
|
+ expense_amount = pd.to_numeric(row["支出金额"], errors='coerce')
|
|
|
+ balance = str(row["账户余额"]).strip()
|
|
|
+ opponent_account = str(row["对方账号"]).strip()
|
|
|
+ opponent_name = str(row["对方户名"]).strip()
|
|
|
+ opponent_bank = str(row["对方开户行"]).strip()
|
|
|
+ summary = str(row["摘要"]).strip()
|
|
|
+
|
|
|
+ income = income_amount if pd.notna(income_amount) and income_amount > 0 else 0
|
|
|
+ expense = expense_amount if pd.notna(expense_amount) and expense_amount > 0 else 0
|
|
|
+
|
|
|
+ if summary == "费用外收":
|
|
|
+ summary = "手续费"
|
|
|
+ opponent_name = "手续费"
|
|
|
+ opponent_bank = "手续费"
|
|
|
+
|
|
|
+ transaction_time_str = transaction_time.strftime("%Y-%m-%d %H:%M:%S") if pd.notna(transaction_time) else ""
|
|
|
+
|
|
|
+ standard_flow.append({
|
|
|
+ "交易时间": transaction_time_str,
|
|
|
+ "对方户名": opponent_name,
|
|
|
+ "摘要": summary,
|
|
|
+ "收入": 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 "农业银行"
|