feat: 配置管理增加复制功能,修复企业加载问题
## 修复问题 ### 1. 企业加载不出来 **问题**:`Unknown column 'company_id' in 'table list'` **原因**:`t_company` 表中字段名是 `id` 而不是 `company_id` **修复**:修改 `/api/entities` API 中的SQL查询,使用正确的字段名 `id` ## 新增功能 ### 2. 配置复制功能 - 在配置列表中每个配置添加"复制"按钮 - 点击复制按钮,复制整个配置(包括所有字段设置) - 新配置名称自动添加"_副本"后缀 - 后端API:`POST /api/config/<id>/copy` ## 功能说明 ### 复制配置 1. 在配置管理标签页 2. 找到要复制的配置 3. 点击"复制"按钮 4. 系统会创建一个新配置,名称为"原名称_副本" 5. 新配置包含原配置的所有设置(拆分方式、字段、求和等) ### 企业加载 现在企业列表可以正常加载了,显示企业ID和名称。 ## 重启应用测试 ```bash # Ctrl+C 停止 python app.py ``` 然后刷新页面,测试: 1. 企业列表是否正常显示 2. 配置复制功能是否正常工作 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
38
app.py
38
app.py
@@ -152,6 +152,42 @@ def delete_config(config_id):
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/config/<int:config_id>/copy', methods=['POST'])
|
||||
def copy_config(config_id):
|
||||
"""复制配置"""
|
||||
try:
|
||||
# 获取原配置
|
||||
configs = execute_query('SELECT * FROM t_daily_report_config WHERE id = %s', (config_id,))
|
||||
if not configs:
|
||||
return jsonify({'success': False, 'message': '原配置不存在'}), 404
|
||||
|
||||
original = configs[0]
|
||||
|
||||
# 生成新配置名称
|
||||
new_name = f"{original['config_name']}_副本"
|
||||
|
||||
# 插入新配置
|
||||
new_id = execute_insert(
|
||||
'''INSERT INTO t_daily_report_config
|
||||
(config_name, split_type, split_value, split_name, selected_fields, sum_fields, is_active, sort_order)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)''',
|
||||
(
|
||||
new_name,
|
||||
original['split_type'],
|
||||
original['split_value'],
|
||||
original['split_name'],
|
||||
original['selected_fields'],
|
||||
original.get('sum_fields', ''),
|
||||
original['is_active'],
|
||||
original.get('sort_order', 0)
|
||||
)
|
||||
)
|
||||
|
||||
return jsonify({'success': True, 'message': '配置复制成功', 'id': new_id})
|
||||
except Exception as e:
|
||||
return jsonify({'success': False, 'message': str(e)}), 500
|
||||
|
||||
|
||||
@app.route('/api/config/<int:config_id>/toggle', methods=['POST'])
|
||||
def toggle_config(config_id):
|
||||
"""启用/禁用配置"""
|
||||
@@ -230,7 +266,7 @@ def get_entities():
|
||||
if entity_type == 'company':
|
||||
# 获取企业列表
|
||||
companies = execute_query(
|
||||
'SELECT DISTINCT company_id, company_name FROM t_company ORDER BY company_name'
|
||||
'SELECT id AS company_id, company_name FROM t_company WHERE company_state = "1" ORDER BY company_name'
|
||||
)
|
||||
return jsonify({'success': True, 'data': companies})
|
||||
else:
|
||||
|
||||
@@ -570,6 +570,7 @@
|
||||
${config.is_active ? '禁用' : '启用'}
|
||||
</button>
|
||||
<button class="btn btn-sm btn-primary" onclick="editConfig(${config.id})">编辑</button>
|
||||
<button class="btn btn-sm btn-success" onclick="copyConfig(${config.id})">复制</button>
|
||||
<button class="btn btn-sm btn-danger" onclick="deleteConfig(${config.id})">删除</button>
|
||||
<button class="btn btn-sm" onclick="moveConfig(${config.id}, 'up')">↑</button>
|
||||
<button class="btn btn-sm" onclick="moveConfig(${config.id}, 'down')">↓</button>
|
||||
@@ -747,6 +748,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 复制配置
|
||||
async function copyConfig(configId) {
|
||||
try {
|
||||
const response = await fetch(`/api/config/${configId}/copy`, {
|
||||
method: 'POST'
|
||||
});
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert('配置复制成功!');
|
||||
loadConfigs();
|
||||
} else {
|
||||
alert('复制失败: ' + result.error);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('复制配置失败:', error);
|
||||
alert('复制失败,请稍后重试');
|
||||
}
|
||||
}
|
||||
|
||||
// 删除配置
|
||||
async function deleteConfig(configId) {
|
||||
if (!confirm('确定要删除这个配置吗?')) {
|
||||
|
||||
Reference in New Issue
Block a user