fix: 修复历史记录页面显示问题 - 报表日期中文化、时间范围格式修正、配置名称显示
Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
10
app.py
10
app.py
@@ -645,6 +645,7 @@ def init_tables():
|
|||||||
split_value VARCHAR(100) NULL COMMENT '拆分值',
|
split_value VARCHAR(100) NULL COMMENT '拆分值',
|
||||||
split_name VARCHAR(200) NULL COMMENT '拆分显示名称',
|
split_name VARCHAR(200) NULL COMMENT '拆分显示名称',
|
||||||
config_id BIGINT NULL COMMENT '配置ID',
|
config_id BIGINT NULL COMMENT '配置ID',
|
||||||
|
config_name VARCHAR(200) NULL COMMENT '配置名称',
|
||||||
total_orders INT NULL COMMENT '订单总数',
|
total_orders INT NULL COMMENT '订单总数',
|
||||||
total_amount DECIMAL(10,2) NULL COMMENT '总金额',
|
total_amount DECIMAL(10,2) NULL COMMENT '总金额',
|
||||||
sum_results VARCHAR(2000) NULL COMMENT '求和结果',
|
sum_results VARCHAR(2000) NULL COMMENT '求和结果',
|
||||||
@@ -658,6 +659,15 @@ def init_tables():
|
|||||||
"""
|
"""
|
||||||
execute_update(create_history_table)
|
execute_update(create_history_table)
|
||||||
|
|
||||||
|
# 为已存在的表添加 config_name 字段(如果不存在)
|
||||||
|
try:
|
||||||
|
execute_update("""
|
||||||
|
ALTER TABLE t_daily_report_history
|
||||||
|
ADD COLUMN IF NOT EXISTS config_name VARCHAR(200) NULL COMMENT '配置名称'
|
||||||
|
""")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[数据库] 添加 config_name 字段时出错(可能已存在): {e}")
|
||||||
|
|
||||||
return jsonify({'success': True, 'message': '数据库表初始化成功'})
|
return jsonify({'success': True, 'message': '数据库表初始化成功'})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({'success': False, 'message': str(e)}), 500
|
return jsonify({'success': False, 'message': str(e)}), 500
|
||||||
|
|||||||
BIN
assets/image_20260713144552224.png
Normal file
BIN
assets/image_20260713144552224.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 62 KiB |
@@ -409,6 +409,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None):
|
|||||||
split_value=config['split_value'],
|
split_value=config['split_value'],
|
||||||
split_name=config.get('split_name', config['split_value']),
|
split_name=config.get('split_name', config['split_value']),
|
||||||
config_id=config_id,
|
config_id=config_id,
|
||||||
|
config_name=config.get('config_name', ''),
|
||||||
total_orders=0,
|
total_orders=0,
|
||||||
total_amount=0,
|
total_amount=0,
|
||||||
sum_results={},
|
sum_results={},
|
||||||
@@ -482,6 +483,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None):
|
|||||||
split_value=config['split_value'],
|
split_value=config['split_value'],
|
||||||
split_name=config.get('split_name', config['split_value']),
|
split_name=config.get('split_name', config['split_value']),
|
||||||
config_id=config_id,
|
config_id=config_id,
|
||||||
|
config_name=config.get('config_name', ''),
|
||||||
total_orders=len(orders),
|
total_orders=len(orders),
|
||||||
total_amount=total_amount,
|
total_amount=total_amount,
|
||||||
sum_results=sum_results,
|
sum_results=sum_results,
|
||||||
@@ -521,6 +523,7 @@ def generate_daily_report(config_id, start_time=None, end_time=None):
|
|||||||
split_value=config['split_value'] if 'config' in locals() and config else '',
|
split_value=config['split_value'] if 'config' in locals() and config else '',
|
||||||
split_name=config.get('split_name', '') if 'config' in locals() and config else '',
|
split_name=config.get('split_name', '') if 'config' in locals() and config else '',
|
||||||
config_id=config_id,
|
config_id=config_id,
|
||||||
|
config_name=config.get('config_name', '') if 'config' in locals() and config else '',
|
||||||
total_orders=0,
|
total_orders=0,
|
||||||
total_amount=0,
|
total_amount=0,
|
||||||
sum_results={},
|
sum_results={},
|
||||||
@@ -661,7 +664,7 @@ def generate_excel(orders, selected_fields, sum_fields, sum_results,
|
|||||||
|
|
||||||
|
|
||||||
def save_report_history(report_date, start_time, end_time, split_type, split_value,
|
def save_report_history(report_date, start_time, end_time, split_type, split_value,
|
||||||
split_name, config_id, total_orders, total_amount,
|
split_name, config_id, config_name, total_orders, total_amount,
|
||||||
sum_results, file_path, status):
|
sum_results, file_path, status):
|
||||||
"""
|
"""
|
||||||
保存日报生成历史记录
|
保存日报生成历史记录
|
||||||
@@ -680,8 +683,8 @@ def save_report_history(report_date, start_time, end_time, split_type, split_val
|
|||||||
sql = """
|
sql = """
|
||||||
INSERT INTO t_daily_report_history
|
INSERT INTO t_daily_report_history
|
||||||
(id, report_date, start_time, end_time, split_type, split_value, split_name,
|
(id, report_date, start_time, end_time, split_type, split_value, split_name,
|
||||||
config_id, total_orders, total_amount, sum_results, file_path, status, create_time)
|
config_id, config_name, total_orders, total_amount, sum_results, file_path, status, create_time)
|
||||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())
|
||||||
"""
|
"""
|
||||||
|
|
||||||
params = (
|
params = (
|
||||||
@@ -693,6 +696,7 @@ def save_report_history(report_date, start_time, end_time, split_type, split_val
|
|||||||
split_value,
|
split_value,
|
||||||
split_name,
|
split_name,
|
||||||
config_id,
|
config_id,
|
||||||
|
config_name,
|
||||||
total_orders,
|
total_orders,
|
||||||
total_amount,
|
total_amount,
|
||||||
json.dumps(sum_results, ensure_ascii=False),
|
json.dumps(sum_results, ensure_ascii=False),
|
||||||
|
|||||||
@@ -2221,10 +2221,40 @@
|
|||||||
tbody.innerHTML = list.map(item => {
|
tbody.innerHTML = list.map(item => {
|
||||||
const statusText = item.status === 1 ? '成功' : '失败';
|
const statusText = item.status === 1 ? '成功' : '失败';
|
||||||
const statusClass = item.status === 1 ? 'status-success' : 'status-failed';
|
const statusClass = item.status === 1 ? 'status-success' : 'status-failed';
|
||||||
const startTime = item.start_time ? new Date(item.start_time).toLocaleString('zh-CN') : '-';
|
|
||||||
const endTime = item.end_time ? new Date(item.end_time).toLocaleString('zh-CN') : '-';
|
// 格式化报表日期为中文(直接解析字符串格式 '2026-07-12')
|
||||||
const timeRange = `${startTime} 至 ${endTime}`;
|
let reportDate = '-';
|
||||||
const reportDate = item.report_date || '-';
|
if (item.report_date) {
|
||||||
|
const match = item.report_date.match(/(\d{4})-(\d{1,2})-(\d{1,2})/);
|
||||||
|
if (match) {
|
||||||
|
const year = parseInt(match[1]);
|
||||||
|
const month = parseInt(match[2]);
|
||||||
|
const day = parseInt(match[3]);
|
||||||
|
reportDate = `${year}年${month}月${day}日`;
|
||||||
|
} else {
|
||||||
|
reportDate = item.report_date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 格式化时间范围(直接解析字符串格式 '2026-07-12 08:00:00')
|
||||||
|
let timeRange = '-';
|
||||||
|
if (item.start_time && item.end_time) {
|
||||||
|
const formatTimeStr = (timeStr) => {
|
||||||
|
const match = timeStr.match(/(\d{4})-(\d{1,2})-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{1,2})/);
|
||||||
|
if (match) {
|
||||||
|
const year = match[1];
|
||||||
|
const month = match[2].padStart(2, '0');
|
||||||
|
const day = match[3].padStart(2, '0');
|
||||||
|
const hour = match[4].padStart(2, '0');
|
||||||
|
const minute = match[5].padStart(2, '0');
|
||||||
|
const second = match[6].padStart(2, '0');
|
||||||
|
return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
|
||||||
|
}
|
||||||
|
return timeStr;
|
||||||
|
};
|
||||||
|
timeRange = `${formatTimeStr(item.start_time)} 至 ${formatTimeStr(item.end_time)}`;
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user