Преглед на файлове

🔨 build: 更新 PyInstaller 配置以完整收集 mysql.connector 依赖

wenhongquan преди 2 месеца
родител
ревизия
aa8a999201
променени са 6 файла, в които са добавени 66 реда и са изтрити 13 реда
  1. 1 1
      .github/workflows/build-windows.yml
  2. BIN
      __pycache__/sync_measure_data.cpython-313.pyc
  3. 1 1
      build_windows.bat
  4. 56 8
      sync_measure_data.py
  5. 8 3
      sync_measure_data.spec
  6. BIN
      沪武档案同步玄海.exe

+ 1 - 1
.github/workflows/build-windows.yml

@@ -25,7 +25,7 @@ jobs:
 
       - name: Build EXE
         run: |
-          pyinstaller --onefile --console --name "沪武档案同步玄海" --hidden-import=mysql.connector --clean sync_measure_data.py
+          pyinstaller --onefile --console --name "沪武档案同步玄海" --collect-all mysql.connector --clean sync_measure_data.py
 
       - name: Upload artifact
         uses: actions/upload-artifact@v4

BIN
__pycache__/sync_measure_data.cpython-313.pyc


+ 1 - 1
build_windows.bat

@@ -29,7 +29,7 @@ pyinstaller ^
     --onefile ^
     --console ^
     --name "沪武档案同步玄海" ^
-    --hidden-import=mysql.connector ^
+    --collect-all mysql.connector ^
     --clean ^
     sync_measure_data.py
 

+ 56 - 8
sync_measure_data.py

@@ -417,7 +417,8 @@ QUERY_FLOW_NODES = """
            ai.ASSIGNEE_      AS assignee,
            u.account         AS assignee_account,
            u.real_name       AS assignee_name,
-           d.full_name       AS org_name,
+           u.dept_id         AS assignee_dept_id,
+           d.dept_name       AS org_name,
            (SELECT v.TEXT_
               FROM ACT_HI_VARINST v
              WHERE v.TASK_ID_ = ai.TASK_ID_
@@ -431,13 +432,41 @@ QUERY_FLOW_NODES = """
              LIMIT 1)        AS comment_msg
       FROM ACT_HI_ACTINST ai
       LEFT JOIN blade_user u ON u.id = ai.ASSIGNEE_ AND u.is_deleted = 0
-      LEFT JOIN blade_dept d ON FIND_IN_SET(d.id, u.dept_id) AND d.is_deleted = 0
+      LEFT JOIN blade_dept d ON d.id = CAST(SUBSTRING_INDEX(u.dept_id, ',', 1) AS CHAR)
      WHERE ai.PROC_INST_ID_ = %s
        AND ai.ACT_TYPE_ = 'userTask'
      ORDER BY IFNULL(ai.END_TIME_, NOW()), ai.START_TIME_
 """
 
 
+def _resolve_dept_name(cursor, dept_id, cache):
+    """按部门 id 取部门名(对应 dept/list 接口的 deptName,即 dept_name);逐级向上直到找到有效部门。"""
+    dept_id = str(dept_id or '').strip()
+    if not dept_id:
+        return ''
+    if dept_id in cache:
+        return cache[dept_id]
+    name = ''
+    seen = set()
+    current = dept_id
+    while current and current not in seen:
+        seen.add(current)
+        cursor.execute(
+            "SELECT dept_name, full_name, parent_id, is_deleted FROM blade_dept WHERE id = %s LIMIT 1",
+            (current,)
+        )
+        drow = cursor.fetchone()
+        if not drow:
+            break
+        if not drow.get('is_deleted'):
+            name = drow.get('dept_name') or drow.get('full_name') or ''
+            if name:
+                break
+        current = str(drow.get('parent_id') or '').strip() or None
+    cache[dept_id] = name or ''
+    return name or ''
+
+
 def fetch_flow_nodes(cursor, flow_process_inst_id):
     """获取计量单审核过程节点列表 (等价于 /api/flow/process/flow/detail 的 flow 数据)。
 
@@ -459,6 +488,8 @@ def fetch_flow_nodes(cursor, flow_process_inst_id):
     cursor.execute(QUERY_FLOW_NODES, (inst_row['proc_inst_id'],))
     rows = cursor.fetchall()
 
+    dept_cache = {}
+
     def fmt_time(value):
         if not value:
             return ''
@@ -480,11 +511,18 @@ def fetch_flow_nodes(cursor, flow_process_inst_id):
             except Exception:
                 comment = ''
 
+        # 组织机构:优先 SQL 关联结果;为空时按用户主部门逐级向上解析
+        org_name = row.get('org_name')
+        if not org_name:
+            first_dept = str(row.get('assignee_dept_id') or '').split(',')[0].strip()
+            org_name = _resolve_dept_name(cursor, first_dept, dept_cache)
+        org_name = org_name or ARCHIVE_UNIT
+
         nodes.append({
             'id': row.get('node_id') or '',
             'name': row.get('task_name') or '',
             'type': '计量支付',
-            'orgName': row.get('org_name') or ARCHIVE_UNIT,
+            'orgName': org_name,
             'operatorId': str(row.get('assignee') or row.get('assignee_account') or ''),
             'operatorName': row.get('assignee_name') or '',
             'createdTime': fmt_time(row.get('create_time')),
@@ -624,7 +662,8 @@ def build_metadata_entities(order_data, file_id):
         tabulator_org,
         tabulation_date,
         '制表',
-        f"{tabulator_name or ''}文件制表提交".strip(),
+        f"制表;{tabulator_name or ''}文件制表提交;制表时间:{format_datetime(tabulation_date)}".strip(';'),
+        '计量支付',
         business_id=stable_guid(f"{file_id}:tabulator")
     )
 
@@ -632,9 +671,18 @@ def build_metadata_entities(order_data, file_id):
         operator_id = node.get('operatorId') or node.get('assignee')
         operator_name = node.get('operatorName')
         org_name = node.get('orgName') or ARCHIVE_UNIT
-        conclusion = node.get('conclusion') or '通过'
-        action = '审批通过' if conclusion == '通过' else f"审批{conclusion}"
-        description = f"{node.get('name') or '审批节点'}-{operator_name or ''}{action}".strip('-')
+        conclusion = node.get('conclusion') or ''
+        # 行为依据 = 节点类型(计量支付)
+        basis = node.get('type') or '计量支付'
+        # 行为描述 = 节点名称 | 意见 | 结论 | 办理时间 | 创建时间(空值自动跳过)
+        desc_parts = [
+            node.get('name') or '审批节点',
+            node.get('opinion') or '',
+            f"结论:{conclusion}" if conclusion else '',
+            f"办理时间:{format_datetime(node.get('operateTime'))}" if node.get('operateTime') else '',
+            f"创建时间:{format_datetime(node.get('createdTime'))}" if node.get('createdTime') else '',
+        ]
+        description = ';'.join(p for p in desc_parts if p)
         add_entity(
             operator_id,
             operator_name,
@@ -642,7 +690,7 @@ def build_metadata_entities(order_data, file_id):
             node.get('operateTime'),
             '审批',
             description,
-            node.get('id') or node.get('taskId') or '',
+            basis,
             stable_guid(f"{file_id}:{node.get('id') or node.get('taskId') or node.get('operatorId')}")
         )
 

+ 8 - 3
sync_measure_data.spec

@@ -1,13 +1,18 @@
 # -*- mode: python ; coding: utf-8 -*-
 
+from PyInstaller.utils.hooks import collect_all
+
 block_cipher = None
 
+# mysql.connector 的认证插件(plugins)和语言包(locales)为动态加载,必须完整收集
+mysql_datas, mysql_binaries, mysql_hiddenimports = collect_all('mysql.connector')
+
 a = Analysis(
     ['sync_measure_data.py'],
     pathex=[],
-    binaries=[],
-    datas=[],
-    hiddenimports=['mysql.connector', 'requests', 'charset_normalizer', 'idna'],
+    binaries=mysql_binaries,
+    datas=mysql_datas,
+    hiddenimports=mysql_hiddenimports + ['requests', 'charset_normalizer', 'idna'],
     hookspath=[],
     hooksconfig={},
     runtime_hooks=[],

BIN
沪武档案同步玄海.exe