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

View File

@@ -120,10 +120,13 @@ def generate_daily_report(config_id, start_time=None, end_time=None):
end_time=end_time_str
)
print(f"[日报生成] Excel文件已生成: {file_path}")
# 计算总金额
total_amount = sum(float(order.get('total_money', 0) or 0) for order in orders)
# 保存历史记录
print(f"[日报生成] 准备保存历史记录file_path={file_path}")
history_id = save_report_history(
report_date=start_time.strftime('%Y-%m-%d'),
start_time=start_time_str,
@@ -138,6 +141,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None):
file_path=file_path,
status=1
)
print(f"[日报生成] 历史记录已保存ID={history_id}")
print(f"[日报生成] ✓ 生成成功")
print(f" 订单数量: {len(orders)}")
@@ -285,6 +289,11 @@ def save_report_history(report_date, start_time, end_time, split_type, split_val
# 生成ID
history_id = int(datetime.now().timestamp() * 1000)
print(f"[保存历史] 准备保存历史记录")
print(f" ID: {history_id}")
print(f" file_path: '{file_path}'")
print(f" status: {status}")
sql = """
INSERT INTO t_daily_report_history
(id, report_date, start_time, end_time, split_type, split_value, split_name,
@@ -308,6 +317,8 @@ def save_report_history(report_date, start_time, end_time, split_type, split_val
status
)
execute_insert(sql, params)
print(f"[保存历史] 执行SQL插入...")
result = execute_insert(sql, params)
print(f"[保存历史] 插入完成返回ID: {result}")
return history_id