修改峰平谷不对齐

This commit is contained in:
2026-07-24 10:40:19 +08:00
parent e37e494a1f
commit c118ab39b7
3 changed files with 43 additions and 14 deletions

View File

@@ -22,9 +22,11 @@ def collect_sum_data():
try:
data = request.get_json(silent=True) or {}
history_id = data.get('history_id')
log_info(f'[求和数据API] 采集求和数据历史记录ID: {history_id or "全部"}', 'api')
start_date = data.get('start_date')
end_date = data.get('end_date')
log_info(f'[求和数据API] 采集求和数据历史记录ID: {history_id or "全部"},日期范围: {start_date or "开始"} ~ {end_date or "结束"}', 'api')
result = collect_sum_data_from_history(history_id)
result = collect_sum_data_from_history(history_id, start_date, end_date)
if result['success']:
log_info(f'[求和数据API] 采集成功: {result["message"]}', 'api')
return jsonify(result)

View File

@@ -9,13 +9,15 @@ from lib.field_mapping import get_field_display_name
from lib.logger import log_info, log_error, log_warning
def collect_sum_data_from_history(history_id=None):
def collect_sum_data_from_history(history_id=None, start_date=None, end_date=None):
"""
从历史记录中采集求和数据并写入求和数据表
充电电量charge_degree是必须采集的其他求和字段有就采集没有就不采集
Args:
history_id: 历史记录ID可选不填则采集所有成功的历史记录
start_date: 开始日期(可选,格式 YYYY-MM-DD
end_date: 结束日期(可选,格式 YYYY-MM-DD
Returns:
dict: 采集结果
@@ -28,8 +30,18 @@ def collect_sum_data_from_history(history_id=None):
(history_id,)
)
else:
where_clauses = ['status = 1']
params = []
if start_date:
where_clauses.append('report_date >= %s')
params.append(start_date)
if end_date:
where_clauses.append('report_date <= %s')
params.append(end_date)
where_sql = ' AND '.join(where_clauses)
history_list = execute_query(
'SELECT * FROM t_daily_report_history WHERE status = 1 ORDER BY create_time DESC'
f'SELECT * FROM t_daily_report_history WHERE {where_sql} ORDER BY create_time DESC',
tuple(params)
)
if not history_list:
@@ -506,6 +518,10 @@ def update_sum_data(sum_data_id, data):
update_fields.append('remark = %s')
params.append(data['remark'])
if 'data_source' in data:
update_fields.append('data_source = %s')
params.append(data['data_source'])
if not update_fields:
return {'success': False, 'message': '没有需要更新的字段'}