From 47e4359eda9059b41c5a50caa1c28fdc0a668f1d Mon Sep 17 00:00:00 2001 From: haoslm <6083297@qq.com> Date: Fri, 24 Jul 2026 15:49:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=86=E5=8F=B2=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E7=AD=89=E5=A4=96=E6=98=BE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api/report_api.py | 2 +- lib/report_generator.py | 14 +++++++++----- public/static/js/history.js | 4 ++-- public/static/js/report.js | 2 +- templates/index.html | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/api/report_api.py b/lib/api/report_api.py index 02ff00f..4a20c38 100644 --- a/lib/api/report_api.py +++ b/lib/api/report_api.py @@ -85,7 +85,7 @@ def get_report_history(): # 查询数据 history = execute_query( - f'SELECT * FROM t_daily_report_history WHERE {where_sql} ORDER BY create_time DESC LIMIT %s OFFSET %s', + f'SELECT *, total_amount AS total_degree FROM t_daily_report_history WHERE {where_sql} ORDER BY create_time DESC LIMIT %s OFFSET %s', tuple(params) + (page_size, offset) ) diff --git a/lib/report_generator.py b/lib/report_generator.py index fb51e20..a632b45 100644 --- a/lib/report_generator.py +++ b/lib/report_generator.py @@ -345,6 +345,10 @@ def generate_daily_report(config_id, start_time=None, end_time=None): VIRTUAL_FIELDS = {'sharp_electricity', 'peak_electricity', 'flat_electricity', 'valley_electricity', 'custom_service_fee', 'total_amount'} db_fields = [f for f in selected_fields if f not in VIRTUAL_FIELDS] + # 确保 charge_degree 总是被查询(用于计算总电量) + if 'charge_degree' not in db_fields: + db_fields.append('charge_degree') + # 如果选择了实收金额字段,需要确保查询 charge_elecfee_amount(电费金额) if 'total_amount' in selected_fields and 'charge_elecfee_amount' not in db_fields: db_fields.append('charge_elecfee_amount') @@ -519,8 +523,8 @@ def generate_daily_report(config_id, start_time=None, end_time=None): log_info(f"[日报生成] Excel文件已生成: {file_path}", 'report') - # 计算总金额 - total_amount = sum(float(order.get('total_money', 0) or 0) for order in orders) + # 计算总电量(包括驿来特和特来电所有订单) + total_degree = sum(float(order.get('charge_degree', 0) or 0) for order in orders) # 保存历史记录 log_info(f"[日报生成] 准备保存历史记录,file_path={file_path}", 'report') @@ -534,7 +538,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None): config_id=config_id, config_name=config.get('config_name', ''), total_orders=len(orders), - total_amount=total_amount, + total_amount=total_degree, sum_results=sum_results, file_path=file_path, status=1 @@ -555,7 +559,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None): log_info(f"[日报生成] ✓ 生成成功", 'report') log_info(f" 订单数量: {len(orders)}", 'report') - log_info(f" 总金额: {total_amount}", 'report') + log_info(f" 总电量: {total_degree} kWh", 'report') log_info(f" 文件路径: {file_path}", 'report') log_info(f" 历史记录ID: {history_id}", 'report') @@ -564,7 +568,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None): 'message': '日报生成成功', 'file_path': file_path, 'total_orders': len(orders), - 'total_amount': total_amount, + 'total_degree': total_degree, 'sum_results': sum_results, 'history_id': history_id } diff --git a/public/static/js/history.js b/public/static/js/history.js index 1d24078..b709e63 100644 --- a/public/static/js/history.js +++ b/public/static/js/history.js @@ -195,7 +195,7 @@ function renderHistory(list) { const configName = item.config_name || '-'; const splitValue = item.split_name || '-'; const totalOrders = item.total_orders || 0; - const totalAmount = item.total_amount ? parseFloat(item.total_amount).toFixed(2) : '0.00'; + const totalDegree = item.total_degree ? parseFloat(item.total_degree).toFixed(3) : '0.000'; return ` @@ -205,7 +205,7 @@ function renderHistory(list) { ${configName} ${splitValue} ${totalOrders} - ¥${totalAmount} + ${totalDegree} ${statusText} ${item.status === 1 && item.file_path ? diff --git a/public/static/js/report.js b/public/static/js/report.js index 96d3893..e5f9a55 100644 --- a/public/static/js/report.js +++ b/public/static/js/report.js @@ -351,7 +351,7 @@ async function generateReport() { if (r.success) { html += `
`; html += `✓ ${r.name}
`; - html += `订单数量:${r.total_orders} 条,总金额:¥${r.total_amount.toFixed(2)}
`; + html += `订单数量:${r.total_orders} 条,总电量:${r.total_degree ? parseFloat(r.total_degree).toFixed(3) : '0.000'} kWh
`; html += `📥 下载`; html += `
`; } else { diff --git a/templates/index.html b/templates/index.html index 1dab430..bc25c6d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -151,7 +151,7 @@ 配置名称 拆分值 订单数 - 总金额 + 总电量(kWh) 状态 操作