debug: 创建 file_path 保存测试脚本

为了准确定位 file_path 为 null 的问题,创建了 test_file_path.py 测试脚本。

脚本功能:
1. 直接连接数据库
2. 插入测试数据(包含 file_path)
3. 查询刚插入的数据
4. 验证 file_path 是否正确保存和读取
5. 清理测试数据

运行方式:
```bash
python test_file_path.py
```

根据测试结果判断:
- 正常:问题在 report_generator.py 的保存逻辑
- 不匹配:问题在数据库或表结构

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-09 13:35:00 +08:00
parent 495aef7b69
commit 2fbda995ce
2 changed files with 106 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

106
test_file_path.py Normal file
View File

@@ -0,0 +1,106 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单测试:直接测试保存和查询 file_path
"""
import pymysql
import os
from datetime import datetime
def test_file_path():
"""测试 file_path 的保存和查询"""
print("="*60)
print("测试 file_path 保存和查询")
print("="*60)
conn = None
try:
# 连接数据库
print("\n1. 连接数据库...")
conn = pymysql.connect(
host='haoslm2.xicp.net',
port=10216,
user='root',
password='DsideaL147258369',
database='yltcharge',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor
)
print(" ✓ 连接成功")
cursor = conn.cursor()
# 2. 插入测试数据
print("\n2. 插入测试数据...")
test_id = int(datetime.now().timestamp() * 1000)
test_file_path = '/reports/test_file_path.xlsx'
print(f" 准备插入:")
print(f" - ID: {test_id}")
print(f" - file_path: '{test_file_path}'")
insert_sql = """
INSERT INTO t_daily_report_history
(id, report_date, start_time, end_time, split_type, split_value,
total_orders, total_amount, file_path, status, create_time)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())
"""
cursor.execute(insert_sql, (
test_id,
'2025-01-01',
'2025-01-01 08:00:00',
'2025-01-02 08:00:00',
'test',
'test_value',
10,
100.50,
test_file_path, # 这里传入 file_path
1
))
conn.commit()
print(" ✓ 插入成功")
# 3. 查询数据
print("\n3. 查询刚插入的数据...")
cursor.execute("SELECT * FROM t_daily_report_history WHERE id = %s", (test_id,))
result = cursor.fetchone()
if result:
print(" ✓ 查询成功")
print(f" - ID: {result.get('id')}")
print(f" - file_path: '{result.get('file_path')}'")
print(f" - status: {result.get('status')}")
if result.get('file_path') == test_file_path:
print("\n✓✓✓ file_path 保存和查询正常!")
else:
print(f"\n❌❌❌ file_path 不匹配!")
print(f" 期望: '{test_file_path}'")
print(f" 实际: '{result.get('file_path')}'")
else:
print(" ❌ 查询失败,没有找到数据")
# 4. 清理测试数据
print("\n4. 清理测试数据...")
cursor.execute("DELETE FROM t_daily_report_history WHERE id = %s", (test_id,))
conn.commit()
print(" ✓ 已清理")
print("\n" + "="*60)
print("测试完成")
print("="*60)
except Exception as e:
print(f"\n❌ 测试失败: {e}")
import traceback
traceback.print_exc()
finally:
if conn:
conn.close()
input("\n按回车键退出...")
if __name__ == "__main__":
test_file_path()