修复求和数据统计的问题
This commit is contained in:
@@ -93,12 +93,13 @@ def update_sum_data_api(sum_data_id):
|
||||
"""更新求和数据"""
|
||||
try:
|
||||
data = request.json
|
||||
log_info(f'[求和数据API] 更新求和数据,ID: {sum_data_id}', 'api')
|
||||
log_info(f'[求和数据API] 更新求和数据,ID: {sum_data_id}, 请求数据: {data}', 'api')
|
||||
result = update_sum_data(sum_data_id, data)
|
||||
if result['success']:
|
||||
log_info(f'[求和数据API] 更新成功,ID: {sum_data_id}', 'api')
|
||||
return jsonify(result)
|
||||
else:
|
||||
log_warning(f'[求和数据API] 更新失败,ID: {sum_data_id}, 原因: {result["message"]}', 'api')
|
||||
return jsonify(result), 400
|
||||
except Exception as e:
|
||||
log_error(f'[求和数据API] 更新求和数据失败: {e}', 'api')
|
||||
@@ -143,6 +144,57 @@ def batch_delete_sum_data_api():
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
|
||||
@sum_data_bp.route('/sum-data/batch-query', methods=['POST'])
|
||||
def batch_query_sum_data():
|
||||
"""根据ID列表批量查询求和数据"""
|
||||
try:
|
||||
data = request.json
|
||||
ids = data.get('ids', [])
|
||||
log_info(f'[求和数据API] 批量查询求和数据,ID数量: {len(ids)}', 'api')
|
||||
|
||||
if not ids:
|
||||
return jsonify({'success': False, 'message': '请提供ID列表'}), 400
|
||||
|
||||
from lib.db import execute_query
|
||||
|
||||
placeholders = ','.join(['%s'] * len(ids))
|
||||
sql = f'SELECT * FROM t_daily_report_sum_data WHERE id IN ({placeholders})'
|
||||
|
||||
result = execute_query(sql, tuple(ids))
|
||||
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'data': result
|
||||
})
|
||||
except Exception as e:
|
||||
log_error(f'[求和数据API] 批量查询求和数据失败: {e}', 'api')
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
|
||||
@sum_data_bp.route('/sum-data/batch-add', methods=['POST'])
|
||||
def batch_add_sum_data():
|
||||
"""批量添加求和数据"""
|
||||
try:
|
||||
data = request.json
|
||||
fields = data.get('fields', [])
|
||||
log_info(f'[求和数据API] 批量添加求和数据,字段数量: {len(fields)}', 'api')
|
||||
|
||||
if not fields:
|
||||
return jsonify({'success': False, 'message': '请至少添加一个字段'}), 400
|
||||
|
||||
from lib.sum_data_collector import batch_add_sum_data
|
||||
|
||||
result = batch_add_sum_data(data)
|
||||
if result['success']:
|
||||
log_info(f'[求和数据API] 批量添加成功,添加{result["count"]}条记录', 'api')
|
||||
return jsonify(result)
|
||||
else:
|
||||
return jsonify(result), 400
|
||||
except Exception as e:
|
||||
log_error(f'[求和数据API] 批量添加求和数据失败: {e}', 'api')
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
|
||||
@sum_data_bp.route('/sum-data/monthly-total', methods=['GET'])
|
||||
def monthly_charge_degree_total():
|
||||
"""获取指定配置当月充电电量累计(从sum_data表查询,对账后的数据)
|
||||
|
||||
Reference in New Issue
Block a user