| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import pandas as pd
- from tkinter import messagebox
- from flow_parser_base import FlowParserBase
- class WeChatFlowParser(FlowParserBase):
- """微众银行流水解析器"""
-
- def parse(self, flow_file_path):
- """解析微众银行流水文件,返回标准化的流水数据"""
- try:
- flow_df = pd.read_excel(flow_file_path, dtype=str, header=1)
-
- 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
-
- flow_df["交易时间"] = pd.to_datetime(flow_df["交易时间"], errors='coerce')
- flow_df = flow_df.sort_values("交易时间", ascending=True)
-
- standard_flow = []
- for _, row in flow_df.iterrows():
- transaction_time = row["交易时间"]
- debit_str = str(row["借"]).strip()
- credit_str = str(row["贷"]).strip()
- debit_amount = pd.to_numeric(debit_str.replace(',', ''), errors='coerce') if debit_str != 'nan' else 0
- credit_amount = pd.to_numeric(credit_str.replace(',', ''), errors='coerce') if credit_str != 'nan' else 0
- balance = str(row["账户余额"]).strip()
- opponent_name = str(row["对方姓名"]).strip()
- opponent_bank = str(row["对方账号开户行"]).strip()
- summary = str(row["备注"]).strip()
-
- expense = debit_amount if pd.notna(debit_amount) and debit_amount > 0 else 0
- income = credit_amount if pd.notna(credit_amount) and credit_amount > 0 else 0
-
- 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,
- "备注": summary,
- "余额": balance
- })
-
- return pd.DataFrame(standard_flow)
- except Exception as e:
- messagebox.showerror("错误", f"解析微众银行流水失败:{str(e)}")
- return None
-
- def get_bank_name(self):
- """返回银行名称"""
- return "微众银行"
|