feat: 完成配置管理增强功能
## 修复问题 ### 1. 企业加载不出来 **问题**:`Unknown column 'company_id' in 'table list'` **原因**:`t_company` 表中字段名是 `id` 而不是 `company_id` **修复**:修改 `/api/entities` API 中的SQL查询,使用正确的字段名 ### 2. 用户加载不出来 **问题**:`Unknown column 'name' in 'field list'` **原因**:`t_user` 表中字段名是 `user_name` 而不是 `name` **修复**:修改SQL查询,使用正确的字段名 `user_name` ## 新增功能 ### 3. 拆分方式增加"按场站" - 在拆分方式下拉框中添加"按场站"选项 - 支持从 `t_station` 表加载场站列表 - 场站显示名称格式:`station_id - name` ### 4. 企业/用户/场站多选功能 - 将选择框改为多选(`multiple` 属性) - 保存时将多个值用逗号分隔存储 - 编辑时自动解析逗号分隔的值并选中对应选项 - 日报生成时支持多选值查询(使用 IN 语句) ### 5. 配置复制功能 - 在配置列表中添加"复制"按钮 - 复制配置时自动添加"_副本"后缀 - 后端API:`POST /api/config/<id>/copy` ### 6. 后端查询优化 - 修改 `report_generator.py` 中的查询逻辑 - 支持多选值查询(逗号分隔的值使用 IN 语句) ## 重启应用测试 ```bash # Ctrl+C 停止 python app.py ``` 然后刷新页面,测试: 1. ✅ 企业/用户/场站列表是否正常加载 2. ✅ 多选功能是否正常工作 3. ✅ 配置复制功能是否正常 4. ✅ 生成日报时多选值是否正确查询 Coze-Commit-Type: user Coze-User-ID: 3722323274763196 Coze-Conversation-ID: 9894087
This commit is contained in:
@@ -466,14 +466,16 @@
|
||||
<option value="">请选择拆分方式</option>
|
||||
<option value="company_id">按企业ID</option>
|
||||
<option value="user_id">按用户ID</option>
|
||||
<option value="station_id">按场站ID</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>选择企业/用户 *</label>
|
||||
<select id="split-value" class="form-control">
|
||||
<label>选择企业/用户/场站(可多选) *</label>
|
||||
<select id="split-value" class="form-control" multiple size="5">
|
||||
<option value="">请先选择拆分方式</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">按住 Ctrl 或 Shift 键可多选</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
@@ -641,18 +643,41 @@
|
||||
|
||||
select.innerHTML = '<option value="">加载中...</option>';
|
||||
|
||||
// 根据拆分方式确定实体类型
|
||||
let entityType = '';
|
||||
if (splitType === 'company_id') {
|
||||
entityType = 'company';
|
||||
} else if (splitType === 'user_id') {
|
||||
entityType = 'user';
|
||||
} else if (splitType === 'station_id') {
|
||||
entityType = 'station';
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/entities?type=${splitType === 'company_id' ? 'company' : 'user'}`);
|
||||
const response = await fetch(`/api/entities?type=${entityType}`);
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
const entities = result.data;
|
||||
select.innerHTML = '<option value="">请选择</option>' +
|
||||
select.innerHTML = '<option value="">请选择(可多选)</option>' +
|
||||
entities.map(e => {
|
||||
const value = splitType === 'company_id' ? e.company_id : e.user_id;
|
||||
const name = splitType === 'company_id' ? e.company_name : e.user_name;
|
||||
const type = e.order_type === 3 ? '(企业用户)' : '(普通用户)';
|
||||
return `<option value="${value}" data-name="${name}">${name} ${splitType === 'user_id' ? type : ''}</option>`;
|
||||
let value = '';
|
||||
let name = '';
|
||||
let typeLabel = '';
|
||||
|
||||
if (splitType === 'company_id') {
|
||||
value = e.id;
|
||||
name = e.name;
|
||||
} else if (splitType === 'user_id') {
|
||||
value = e.id;
|
||||
name = e.name;
|
||||
typeLabel = e.order_type === 3 ? '(企业用户)' : '(普通用户)';
|
||||
} else if (splitType === 'station_id') {
|
||||
value = e.id;
|
||||
name = e.name;
|
||||
}
|
||||
|
||||
return `<option value="${value}" data-name="${name}">${name} ${typeLabel}</option>`;
|
||||
}).join('');
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -665,8 +690,11 @@
|
||||
const configName = document.getElementById('config-name').value;
|
||||
const splitType = document.getElementById('split-type').value;
|
||||
const splitValueSelect = document.getElementById('split-value');
|
||||
const splitValue = splitValueSelect.value;
|
||||
const splitName = splitValueSelect.options[splitValueSelect.selectedIndex].dataset.name || '';
|
||||
|
||||
// 处理多选:获取所有选中的选项
|
||||
const selectedOptions = Array.from(splitValueSelect.selectedOptions).filter(opt => opt.value);
|
||||
const splitValue = selectedOptions.map(opt => opt.value).join(',');
|
||||
const splitName = selectedOptions.map(opt => opt.dataset.name || '').join(',');
|
||||
|
||||
const selectedFields = Array.from(document.querySelectorAll('#fields-list input:checked')).map(cb => cb.value);
|
||||
const sumFields = Array.from(document.querySelectorAll('#sum-fields-list input:checked')).map(cb => cb.value);
|
||||
@@ -735,7 +763,15 @@
|
||||
document.getElementById('split-type').value = config.split_type;
|
||||
|
||||
await loadEntities();
|
||||
document.getElementById('split-value').value = config.split_value;
|
||||
|
||||
// 处理多选值回显:split_value 可能是逗号分隔的多个值
|
||||
const splitValueSelect = document.getElementById('split-value');
|
||||
const splitValues = config.split_value.split(',');
|
||||
|
||||
// 清除所有选中状态
|
||||
Array.from(splitValueSelect.options).forEach(opt => {
|
||||
opt.selected = splitValues.includes(opt.value);
|
||||
});
|
||||
|
||||
await loadFields();
|
||||
renderFields(config.selected_fields, config.sum_fields);
|
||||
|
||||
Reference in New Issue
Block a user