修复历史记录等外显信息
This commit is contained in:
@@ -85,7 +85,7 @@ def get_report_history():
|
|||||||
|
|
||||||
# 查询数据
|
# 查询数据
|
||||||
history = execute_query(
|
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)
|
tuple(params) + (page_size, offset)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -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'}
|
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]
|
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(电费金额)
|
# 如果选择了实收金额字段,需要确保查询 charge_elecfee_amount(电费金额)
|
||||||
if 'total_amount' in selected_fields and 'charge_elecfee_amount' not in db_fields:
|
if 'total_amount' in selected_fields and 'charge_elecfee_amount' not in db_fields:
|
||||||
db_fields.append('charge_elecfee_amount')
|
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')
|
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')
|
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_id=config_id,
|
||||||
config_name=config.get('config_name', ''),
|
config_name=config.get('config_name', ''),
|
||||||
total_orders=len(orders),
|
total_orders=len(orders),
|
||||||
total_amount=total_amount,
|
total_amount=total_degree,
|
||||||
sum_results=sum_results,
|
sum_results=sum_results,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
status=1
|
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"[日报生成] ✓ 生成成功", 'report')
|
||||||
log_info(f" 订单数量: {len(orders)}", '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" 文件路径: {file_path}", 'report')
|
||||||
log_info(f" 历史记录ID: {history_id}", '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': '日报生成成功',
|
'message': '日报生成成功',
|
||||||
'file_path': file_path,
|
'file_path': file_path,
|
||||||
'total_orders': len(orders),
|
'total_orders': len(orders),
|
||||||
'total_amount': total_amount,
|
'total_degree': total_degree,
|
||||||
'sum_results': sum_results,
|
'sum_results': sum_results,
|
||||||
'history_id': history_id
|
'history_id': history_id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ function renderHistory(list) {
|
|||||||
const configName = item.config_name || '-';
|
const configName = item.config_name || '-';
|
||||||
const splitValue = item.split_name || '-';
|
const splitValue = item.split_name || '-';
|
||||||
const totalOrders = item.total_orders || 0;
|
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 `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
@@ -205,7 +205,7 @@ function renderHistory(list) {
|
|||||||
<td>${configName}</td>
|
<td>${configName}</td>
|
||||||
<td>${splitValue}</td>
|
<td>${splitValue}</td>
|
||||||
<td>${totalOrders}</td>
|
<td>${totalOrders}</td>
|
||||||
<td>¥${totalAmount}</td>
|
<td>${totalDegree}</td>
|
||||||
<td><span class="${statusClass}">${statusText}</span></td>
|
<td><span class="${statusClass}">${statusText}</span></td>
|
||||||
<td>
|
<td>
|
||||||
${item.status === 1 && item.file_path ?
|
${item.status === 1 && item.file_path ?
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ async function generateReport() {
|
|||||||
if (r.success) {
|
if (r.success) {
|
||||||
html += `<div style="margin: 10px 0; padding: 10px; background: #f0f8ff; border-radius: 4px;">`;
|
html += `<div style="margin: 10px 0; padding: 10px; background: #f0f8ff; border-radius: 4px;">`;
|
||||||
html += `<strong>✓ ${r.name}</strong><br>`;
|
html += `<strong>✓ ${r.name}</strong><br>`;
|
||||||
html += `订单数量:${r.total_orders} 条,总金额:¥${r.total_amount.toFixed(2)}<br>`;
|
html += `订单数量:${r.total_orders} 条,总电量:${r.total_degree ? parseFloat(r.total_degree).toFixed(3) : '0.000'} kWh<br>`;
|
||||||
html += `<a href="/api/download?path=${r.file_path}" target="_blank" class="btn btn-sm btn-success" style="margin-top: 5px;">📥 下载</a>`;
|
html += `<a href="/api/download?path=${r.file_path}" target="_blank" class="btn btn-sm btn-success" style="margin-top: 5px;">📥 下载</a>`;
|
||||||
html += `</div>`;
|
html += `</div>`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -151,7 +151,7 @@
|
|||||||
<th>配置名称</th>
|
<th>配置名称</th>
|
||||||
<th>拆分值</th>
|
<th>拆分值</th>
|
||||||
<th>订单数</th>
|
<th>订单数</th>
|
||||||
<th>总金额</th>
|
<th>总电量(kWh)</th>
|
||||||
<th>状态</th>
|
<th>状态</th>
|
||||||
<th>操作</th>
|
<th>操作</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user