""" 资金分类规则模块 用于管理日记账生成中的资金分类规则 采用策略模式和规则链模式,便于扩展和维护 """ class FundClassificationRule: """资金分类规则基类""" def match(self, context): """ 判断是否匹配该规则 Args: context: 包含交易上下文信息的字典 - is_settlement: 是否为结算交易 - income: 收入金额 - opponent_name: 对手户名称 - summary: 摘要 - flow_remark: 流水备注 Returns: bool: 是否匹配该规则 """ return False def apply(self, context): """ 应用规则,返回分类结果 Args: context: 包含交易上下文信息的字典 Returns: dict: 包含资金分类-1级、资金分类-2级、资金分类-3级的字典 """ return {"level1": "", "level2": "", "level3": ""} class SettlementRule(FundClassificationRule): """结算收入/支出规则""" def match(self, context): return context["is_settlement"] def apply(self, context): if context["income"] > 0: return {"level1": "结算收入", "level2": "结算收入", "level3": "结算收入"} else: return {"level1": "结算支出", "level2": "结算支出", "level3": "结算支出"} class LoanPaymentRule(FundClassificationRule): """贷款支出规则""" def match(self, context): return "款" in context["flow_remark"] and context["opponent_name"] in ["赵丽"] def apply(self, context): return {"level1": "贷款支出", "level2": "贷款支出", "level3": "贷款支出"} class TelecomRule(FundClassificationRule): """电信日常管理费用规则""" def match(self, context): return "电信" in context["opponent_name"] def apply(self, context): return {"level1": "日常管理", "level2": "日常管理", "level3": "日常管理费用"} class WithdrawalRule(FundClassificationRule): """会长提现支付规则""" def match(self, context): return "会长提现" in context["flow_remark"] or "提现" in context["flow_remark"] def apply(self, context): return {"level1": "游戏业务", "level2": "结算支出", "level3": "会长提现支付"} class YilianRule(FundClassificationRule): """易练推广支付规则""" def match(self, context): return "易练" in context["flow_remark"] and "云账户" in context["opponent_name"] def apply(self, context): return {"level1": "易练结算", "level2": "易练结算", "level3": "易练推广支付"} class FeeRule(FundClassificationRule): """手续费规则""" def match(self, context): return "手续费" in context["summary"] or "服务费" in context["summary"] def apply(self, context): return {"level1": "财务费用", "level2": "财务费用", "level3": "手续费"} class CloudServiceRule(FundClassificationRule): """云服务日常管理费用规则""" def match(self, context): cloud_providers = ["七牛", "阿里云", "京东云", "金山云"] return any(provider in context["opponent_name"] for provider in cloud_providers) def apply(self, context): return {"level1": "日常管理", "level2": "日常管理", "level3": "日常管理费用"} class PendingSettlementRule(FundClassificationRule): """待清算个人会长充值规则""" def match(self, context): return "待清算" in context["opponent_name"] def apply(self, context): return {"level1": "游戏业务", "level2": "会长收款", "level3": "个人会长充值"} class NongxinMerchant238Rule(FundClassificationRule): """农信银行商户238165993385171入账规则""" def match(self, context): return "商户238165993385171入账" in context["summary"] or "商户238165993385171入账" in context["opponent_name"] def apply(self, context): return {"level1": "游戏业务", "level2": "会长收款", "level3": "个人会长充值"} class NongxinFeeRule(FundClassificationRule): """农信银行手续费规则""" def match(self, context): return "手续费" in context["summary"] def apply(self, context): return {"level1": "财务费用", "level2": "财务费用", "level3": "手续费"} class NongxinYilianRule(FundClassificationRule): """农信银行易练规则""" def match(self, context): return "易练" in context["summary"] def apply(self, context): return {"level1": "易练结算", "level2": "易练结算", "level3": "易练推广支付"} class NongxinLoanRule(FundClassificationRule): """农信银行贷款规则""" def match(self, context): return "贷款" in context["summary"] def apply(self, context): return {"level1": "贷款支出", "level2": "贷款支出", "level3": "贷款支出"} class NongxinMerchant238ExpenseRule(FundClassificationRule): """农信银行商户238165993385171入账支出规则""" def match(self, context): return "商户238165993385171入账" in context["opponent_name"] def apply(self, context): return {"level1": "日常管理", "level2": "日常管理", "level3": "法务费"} def get_classification_rules(): """ 获取所有资金分类规则列表 Returns: list: 资金分类规则对象列表 """ return [ SettlementRule(), LoanPaymentRule(), TelecomRule(), WithdrawalRule(), YilianRule(), FeeRule(), CloudServiceRule(), PendingSettlementRule(), NongxinMerchant238Rule(), NongxinFeeRule(), NongxinYilianRule(), NongxinLoanRule(), NongxinMerchant238ExpenseRule() ]