fix: 租户集成遗漏修复
1. 知识库文件上传:前端 FormData 传 tenant_id,后端 upload 端点读取并传给 process_file_to_knowledge 2. process_file_to_knowledge 接受 tenant_id 参数,add_knowledge_entry 时传递 3. 工单创建弹窗新增租户选择器,createWorkOrder 传 tenant_id 4. populateTenantSelectors 同时填充工单创建的租户选择器
This commit is contained in:
Binary file not shown.
@@ -381,7 +381,7 @@ class TSPAgentAssistant:
|
|||||||
logger.error(f"触发示例动作失败: {e}")
|
logger.error(f"触发示例动作失败: {e}")
|
||||||
return {"success": False, "error": str(e)}
|
return {"success": False, "error": str(e)}
|
||||||
|
|
||||||
async def process_file_to_knowledge(self, file_path: str, filename: str) -> Dict[str, Any]:
|
async def process_file_to_knowledge(self, file_path: str, filename: str, tenant_id: str = None) -> Dict[str, Any]:
|
||||||
"""处理文件并生成知识库"""
|
"""处理文件并生成知识库"""
|
||||||
try:
|
try:
|
||||||
import os
|
import os
|
||||||
@@ -427,7 +427,8 @@ class TSPAgentAssistant:
|
|||||||
question=entry.get('question'),
|
question=entry.get('question'),
|
||||||
answer=entry.get('answer'),
|
answer=entry.get('answer'),
|
||||||
category=entry.get('category', '文档导入'),
|
category=entry.get('category', '文档导入'),
|
||||||
confidence_score=entry.get('confidence_score', 0.8)
|
confidence_score=entry.get('confidence_score', 0.8),
|
||||||
|
tenant_id=tenant_id
|
||||||
)
|
)
|
||||||
saved_count += 1
|
saved_count += 1
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -116,13 +116,14 @@ def upload_knowledge_file():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
file.save(temp_path)
|
file.save(temp_path)
|
||||||
|
tenant_id = request.form.get('tenant_id')
|
||||||
assistant = get_agent_assistant()
|
assistant = get_agent_assistant()
|
||||||
# 由于process_file_to_knowledge现在是异步的,我们需要同步调用它
|
# 由于process_file_to_knowledge现在是异步的,我们需要同步调用它
|
||||||
# 或者将整个视图函数改为异步(Flask 2.0+支持)
|
# 或者将整个视图函数改为异步(Flask 2.0+支持)
|
||||||
import asyncio
|
import asyncio
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
asyncio.set_event_loop(loop)
|
asyncio.set_event_loop(loop)
|
||||||
result = loop.run_until_complete(assistant.process_file_to_knowledge(temp_path, file.filename))
|
result = loop.run_until_complete(assistant.process_file_to_knowledge(temp_path, file.filename, tenant_id=tenant_id))
|
||||||
loop.close()
|
loop.close()
|
||||||
|
|
||||||
cache_manager.clear()
|
cache_manager.clear()
|
||||||
|
|||||||
@@ -124,6 +124,11 @@ class TSPDashboard {
|
|||||||
const cv = woFilter.value;
|
const cv = woFilter.value;
|
||||||
woFilter.innerHTML = '<option value="all">全部租户</option>' + tenants.map(t => `<option value="${t.tenant_id}"${t.tenant_id === cv ? ' selected' : ''}>${t.name}</option>`).join('');
|
woFilter.innerHTML = '<option value="all">全部租户</option>' + tenants.map(t => `<option value="${t.tenant_id}"${t.tenant_id === cv ? ' selected' : ''}>${t.name}</option>`).join('');
|
||||||
}
|
}
|
||||||
|
// 工单创建租户选择器
|
||||||
|
const woCreate = document.getElementById('wo-tenant-id');
|
||||||
|
if (woCreate) {
|
||||||
|
woCreate.innerHTML = tenants.map(t => `<option value="${t.tenant_id}">${t.name} (${t.tenant_id})</option>`).join('');
|
||||||
|
}
|
||||||
} catch (e) { console.warn('加载租户列表失败:', e); }
|
} catch (e) { console.warn('加载租户列表失败:', e); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -437,6 +437,10 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
if (manualQuestion) {
|
if (manualQuestion) {
|
||||||
formData.append('manual_question', manualQuestion);
|
formData.append('manual_question', manualQuestion);
|
||||||
}
|
}
|
||||||
|
// 传递租户 ID
|
||||||
|
if (this.knowledgeCurrentTenantId) {
|
||||||
|
formData.append('tenant_id', this.knowledgeCurrentTenantId);
|
||||||
|
}
|
||||||
|
|
||||||
// 模拟进度更新
|
// 模拟进度更新
|
||||||
let progress = 0;
|
let progress = 0;
|
||||||
|
|||||||
@@ -224,9 +224,10 @@ Object.assign(TSPDashboard.prototype, {
|
|||||||
const description = document.getElementById('wo-description').value.trim();
|
const description = document.getElementById('wo-description').value.trim();
|
||||||
const category = document.getElementById('wo-category').value;
|
const category = document.getElementById('wo-category').value;
|
||||||
const priority = document.getElementById('wo-priority').value;
|
const priority = document.getElementById('wo-priority').value;
|
||||||
|
const tenantId = document.getElementById('wo-tenant-id')?.value || 'default';
|
||||||
if (!title || !description) { this.showNotification('请填写完整信息', 'warning'); return; }
|
if (!title || !description) { this.showNotification('请填写完整信息', 'warning'); return; }
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/api/workorders', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title, description, category, priority }) });
|
const response = await fetch('/api/workorders', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title, description, category, priority, tenant_id: tenantId }) });
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
this.showNotification('工单创建成功', 'success');
|
this.showNotification('工单创建成功', 'success');
|
||||||
|
|||||||
@@ -2292,6 +2292,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form id="work-order-form">
|
<form id="work-order-form">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label class="form-label">所属租户</label>
|
||||||
|
<select class="form-select" id="wo-tenant-id">
|
||||||
|
<option value="default">默认租户</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">问题标题</label>
|
<label class="form-label">问题标题</label>
|
||||||
<input type="text" class="form-control" id="wo-title" placeholder="简要描述问题,如:远程启动失败" required>
|
<input type="text" class="form-control" id="wo-title" placeholder="简要描述问题,如:远程启动失败" required>
|
||||||
|
|||||||
Reference in New Issue
Block a user