dongguoliang hace 2 meses
padre
commit
ba3d922f0e

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+build/
+dist/

BIN
51050146686100001911.xls


BIN
__pycache__/fund_classification_rules.cpython-312.pyc


BIN
__pycache__/journal_generator.cpython-312.pyc


+ 53 - 0
build.py

@@ -0,0 +1,53 @@
+"""
+PyInstaller 打包脚本
+用于将日记账生成工具打包成 exe 文件
+"""
+
+import os
+import subprocess
+import sys
+
+def build_exe():
+    """执行打包操作"""
+    
+    print("=" * 50)
+    print("开始打包日记账生成工具")
+    print("=" * 50)
+    
+    pyinstaller_path = os.path.join(sys.executable, "-m")
+    
+    cmd = [
+        sys.executable,
+        "-m",
+        "PyInstaller",
+        "--name=日记账生成工具",
+        "--onefile",
+        "--windowed",
+        "--clean",
+        "--noconfirm",
+        "main.py"
+    ]
+    
+    print("执行命令:")
+    print(" ".join(cmd))
+    print()
+    
+    try:
+        result = subprocess.run(cmd, check=True)
+        
+        print("=" * 50)
+        print("打包完成!")
+        print("=" * 50)
+        print("生成的 exe 文件位于: dist/日记账生成工具.exe")
+        
+        return True
+        
+    except subprocess.CalledProcessError as e:
+        print("=" * 50)
+        print("打包失败!")
+        print("=" * 50)
+        print(f"错误代码: {e.returncode}")
+        return False
+
+if __name__ == "__main__":
+    build_exe()

+ 141 - 0
fund_classification_rules.py

@@ -0,0 +1,141 @@
+"""
+资金分类规则模块
+用于管理日记账生成中的资金分类规则
+采用策略模式和规则链模式,便于扩展和维护
+"""
+
+
+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": "个人会长充值"}
+
+
+def get_classification_rules():
+    """
+    获取所有资金分类规则列表
+    
+    Returns:
+        list: 资金分类规则对象列表
+    """
+    return [
+        SettlementRule(),
+        LoanPaymentRule(),
+        TelecomRule(),
+        WithdrawalRule(),
+        YilianRule(),
+        FeeRule(),
+        CloudServiceRule(),
+        PendingSettlementRule()
+    ]

+ 21 - 33
journal_generator.py

@@ -1,5 +1,6 @@
 import pandas as pd
 from tkinter import messagebox
+from fund_classification_rules import get_classification_rules
 
 
 class JournalGenerator:
@@ -9,6 +10,7 @@ class JournalGenerator:
         self.param_df = None
         self.account_info_df = None
         self.shouzhi_class_df = None
+        self.classification_rules = get_classification_rules()
     
     def load_parameter_table(self, param_file_path):
         """加载参数表"""
@@ -94,39 +96,25 @@ class JournalGenerator:
                 if opponent_name in self.account_info_df["公司"].values:
                     is_settlement = True
                 
-                if is_settlement:
-                    if income > 0:
-                        fund_level1 = "结算收入"
-                        fund_level2 = "结算收入"
-                        fund_level3 = "结算收入"
-                    else:
-                        fund_level1 = "结算支出"
-                        fund_level2 = "结算支出"
-                        fund_level3 = "结算支出"
-                elif "款" in flow_remark and opponent_name in ["赵丽"]:
-                        fund_level1 = "贷款支出"
-                        fund_level2 = "贷款支出"
-                        fund_level3 = "贷款支出"
-                elif "电信" in opponent_name :
-                        fund_level1 = "日常管理"
-                        fund_level2 = "日常管理"
-                        fund_level3 = "日常管理费用"
-                elif "会长提现" in flow_remark or "提现" in flow_remark:
-                        fund_level1 = "游戏业务"
-                        fund_level2 = "结算支出"
-                        fund_level3 = "会长提现支付"
-                elif "易练" in flow_remark and "云账户" in opponent_name :
-                        fund_level1 = "易练结算"
-                        fund_level2 = "易练结算"
-                        fund_level3 = "易练推广支付"
-                elif "手续费" in summary or "服务费" in summary:
-                    fund_level1 = "财务费用"
-                    fund_level2 = "财务费用"
-                    fund_level3 = "手续费"
-                else:
-                    fund_level1 = ""
-                    fund_level2 = ""
-                    fund_level3 = ""
+                context = {
+                    "is_settlement": is_settlement,
+                    "income": income,
+                    "opponent_name": opponent_name,
+                    "summary": summary,
+                    "flow_remark": flow_remark
+                }
+                
+                fund_level1 = ""
+                fund_level2 = ""
+                fund_level3 = ""
+                
+                for rule in self.classification_rules:
+                    if rule.match(context):
+                        result = rule.apply(context)
+                        fund_level1 = result["level1"]
+                        fund_level2 = result["level2"]
+                        fund_level3 = result["level3"]
+                        break
                 
                 if "手续费" in summary or "服务费" in summary:
                     opponent_name = "手续费"

+ 4 - 0
readme

@@ -0,0 +1,4 @@
+###编译成exe
+D:\soft\python\3.12.2\python.exe build.py
+###或者直接使用命令
+D:\soft\python\3.12.2\python.exe -m PyInstaller --name=日记账生成工具 --onefile --windowed --clean --noconfirm main.py

BIN
中行HISXLS-20260128-20260129-0804715541775272430.xls


BIN
参数表.xlsx


BIN
成都锦高量科科技有限公司-建设银行-4-日记账-2026年01月26日.xlsx


BIN
成都锦高量科科技有限公司-建设银行-5-日记账-2026年01月29日.xlsx


BIN
日记账.xlsx


+ 38 - 0
日记账生成工具.spec

@@ -0,0 +1,38 @@
+# -*- mode: python ; coding: utf-8 -*-
+
+
+a = Analysis(
+    ['main.py'],
+    pathex=[],
+    binaries=[],
+    datas=[],
+    hiddenimports=[],
+    hookspath=[],
+    hooksconfig={},
+    runtime_hooks=[],
+    excludes=[],
+    noarchive=False,
+    optimize=0,
+)
+pyz = PYZ(a.pure)
+
+exe = EXE(
+    pyz,
+    a.scripts,
+    a.binaries,
+    a.datas,
+    [],
+    name='日记账生成工具',
+    debug=False,
+    bootloader_ignore_signals=False,
+    strip=False,
+    upx=True,
+    upx_exclude=[],
+    runtime_tmpdir=None,
+    console=False,
+    disable_windowed_traceback=False,
+    argv_emulation=False,
+    target_arch=None,
+    codesign_identity=None,
+    entitlements_file=None,
+)

BIN
锦高建行的流水.xls