修改数据采集
This commit is contained in:
@@ -149,26 +149,48 @@ def batch_delete_sum_data_api():
|
|||||||
|
|
||||||
@sum_data_bp.route('/sum-data/batch-query', methods=['POST'])
|
@sum_data_bp.route('/sum-data/batch-query', methods=['POST'])
|
||||||
def batch_query_sum_data():
|
def batch_query_sum_data():
|
||||||
"""根据ID列表批量查询求和数据"""
|
"""根据ID列表或条件批量查询求和数据"""
|
||||||
try:
|
try:
|
||||||
data = request.json
|
data = request.json
|
||||||
ids = data.get('ids', [])
|
ids = data.get('ids', [])
|
||||||
log_info(f'[求和数据API] 批量查询求和数据,ID数量: {len(ids)}', 'api')
|
conditions = data.get('conditions', {})
|
||||||
|
|
||||||
if not ids:
|
|
||||||
return jsonify({'success': False, 'message': '请提供ID列表'}), 400
|
|
||||||
|
|
||||||
from lib.db import execute_query
|
from lib.db import execute_query
|
||||||
|
|
||||||
placeholders = ','.join(['%s'] * len(ids))
|
# 支持按ID列表查询
|
||||||
sql = f'SELECT * FROM t_daily_report_sum_data WHERE id IN ({placeholders})'
|
if ids:
|
||||||
|
log_info(f'[求和数据API] 按ID批量查询求和数据,ID数量: {len(ids)}', 'api')
|
||||||
|
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
|
||||||
|
})
|
||||||
|
|
||||||
result = execute_query(sql, tuple(ids))
|
# 支持按条件查询
|
||||||
|
if conditions:
|
||||||
|
log_info(f'[求和数据API] 按条件查询求和数据,条件: {conditions}', 'api')
|
||||||
|
where_clauses = []
|
||||||
|
params = []
|
||||||
|
|
||||||
|
for key, value in conditions.items():
|
||||||
|
if value is not None and value != '':
|
||||||
|
where_clauses.append(f'{key} = %s')
|
||||||
|
params.append(value)
|
||||||
|
|
||||||
|
if not where_clauses:
|
||||||
|
return jsonify({'success': False, 'message': '请提供有效的查询条件'}), 400
|
||||||
|
|
||||||
|
sql = f'SELECT * FROM t_daily_report_sum_data WHERE {" AND ".join(where_clauses)}'
|
||||||
|
result = execute_query(sql, tuple(params))
|
||||||
|
|
||||||
|
return jsonify({
|
||||||
|
'success': True,
|
||||||
|
'data': result
|
||||||
|
})
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({'success': False, 'message': '请提供ID列表或查询条件'}), 400
|
||||||
'success': True,
|
|
||||||
'data': result
|
|
||||||
})
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_error(f'[求和数据API] 批量查询求和数据失败: {e}', 'api')
|
log_error(f'[求和数据API] 批量查询求和数据失败: {e}', 'api')
|
||||||
return jsonify({'success': False, 'message': str(e)}), 500
|
return jsonify({'success': False, 'message': str(e)}), 500
|
||||||
|
|||||||
@@ -424,7 +424,37 @@ async function saveSumData() {
|
|||||||
try {
|
try {
|
||||||
// 分组编辑模式
|
// 分组编辑模式
|
||||||
if (editingGroupIds && editingGroupIds.length > 0) {
|
if (editingGroupIds && editingGroupIds.length > 0) {
|
||||||
// 读取动态字段值
|
// 先获取分组信息,确定需要删除的自动采集记录
|
||||||
|
if (editingGroupData && editingGroupData.length > 0) {
|
||||||
|
const chargeItem = editingGroupData.find(i => i.sum_field_key === 'charge_degree') || editingGroupData[0];
|
||||||
|
|
||||||
|
// 查询该分组下所有字段的ID(用于删除重复的自动采集记录)
|
||||||
|
const deleteResponse = await fetch('/api/sum-data/batch-query', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
conditions: {
|
||||||
|
report_date: chargeItem.report_date,
|
||||||
|
config_id: chargeItem.config_id,
|
||||||
|
split_type: chargeItem.split_type,
|
||||||
|
split_value: chargeItem.split_value,
|
||||||
|
data_source: 'auto'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
const deleteResult = await deleteResponse.json();
|
||||||
|
|
||||||
|
// 删除所有自动采集的记录(避免重复)
|
||||||
|
if (deleteResult.success && deleteResult.data && deleteResult.data.length > 0) {
|
||||||
|
const autoIds = deleteResult.data.map(d => d.id);
|
||||||
|
for (const autoId of autoIds) {
|
||||||
|
await fetch(`/api/sum-data/${autoId}`, { method: 'DELETE' });
|
||||||
|
}
|
||||||
|
console.log(`已删除 ${autoIds.length} 条自动采集记录`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 读取动态字段值(这些是手动编辑后的记录)
|
||||||
const fieldInputs = document.querySelectorAll('#sum-data-dynamic-fields input[data-field-key]');
|
const fieldInputs = document.querySelectorAll('#sum-data-dynamic-fields input[data-field-key]');
|
||||||
let successCount = 0;
|
let successCount = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user