debug: 添加详细调试日志,诊断下载按钮不显示的问题

问题:日报生成成功后,历史记录中没有下载按钮。

改进内容:

1. lib/report_generator.py:
   - 在生成Excel文件后添加日志:显示文件路径
   - 在保存历史记录前添加日志:显示file_path值
   - 在save_report_history函数中添加详细日志:
     * 显示准备保存的信息
     * 显示file_path和status的值
     * 显示SQL执行结果

2. app.py:
   - 在历史记录API中添加调试日志
   - 显示每条记录的status和file_path
   - 确保file_path不为None(转换为空字符串)
   - 添加错误堆栈输出

3. templates/index.html:
   - 在渲染历史记录时添加console.log调试
   - 显示每条记录的详细信息
   - 显示status和file_path的类型
   - 改进下载按钮判断逻辑
   - 添加title提示显示文件路径

4. 新增文档:
   - 查看调试日志.md:详细的调试步骤和问题诊断方法

现在用户可以通过日志准确定位问题:
- 服务器控制台:查看后端日志
- 浏览器控制台:查看前端日志
- curl测试:直接查看API返回数据

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-09 12:59:40 +08:00
parent 9fa2745daa
commit 2ad6e27131
6 changed files with 239 additions and 7 deletions

51
check_history.py Normal file
View File

@@ -0,0 +1,51 @@
"""
检查历史记录中的文件路径
"""
from lib.db import execute_query
print("=" * 60)
print("检查历史记录中的文件路径")
print("=" * 60)
try:
result = execute_query("""
SELECT
id,
report_date,
split_value,
total_orders,
status,
file_path,
create_time
FROM t_daily_report_history
ORDER BY create_time DESC
LIMIT 5
""")
if not result:
print("⚠ 历史记录表为空")
else:
print(f"\n找到 {len(result)} 条记录:\n")
for item in result:
print(f"ID: {item['id']}")
print(f" 日期: {item['report_date']}")
print(f" 拆分值: {item['split_value']}")
print(f" 订单数: {item['total_orders']}")
print(f" 状态: {'成功' if item['status'] == 1 else '失败'}")
print(f" 文件路径: '{item['file_path']}'")
print(f" 文件路径是否为空: {not item['file_path']}")
print(f" 创建时间: {item['create_time']}")
print("-" * 60)
# 检查文件是否存在
if item['file_path']:
import os
full_path = os.path.join('public', item['file_path'])
print(f" 完整路径: {full_path}")
print(f" 文件是否存在: {os.path.exists(full_path)}")
print()
except Exception as e:
print(f"✗ 查询失败: {e}")
import traceback
traceback.print_exc()