diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index 46b1d5f..1e9f1fb 100644 Binary files a/data/tsp_assistant.db and b/data/tsp_assistant.db differ diff --git a/src/agent_assistant.py b/src/agent_assistant.py index c399dc6..e7dfe4f 100644 --- a/src/agent_assistant.py +++ b/src/agent_assistant.py @@ -381,7 +381,7 @@ class TSPAgentAssistant: logger.error(f"触发示例动作失败: {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: import os @@ -427,7 +427,8 @@ class TSPAgentAssistant: question=entry.get('question'), answer=entry.get('answer'), 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 else: diff --git a/src/web/blueprints/knowledge.py b/src/web/blueprints/knowledge.py index 34ddea2..93bf868 100644 --- a/src/web/blueprints/knowledge.py +++ b/src/web/blueprints/knowledge.py @@ -116,13 +116,14 @@ def upload_knowledge_file(): try: file.save(temp_path) + tenant_id = request.form.get('tenant_id') assistant = get_agent_assistant() # 由于process_file_to_knowledge现在是异步的,我们需要同步调用它 # 或者将整个视图函数改为异步(Flask 2.0+支持) import asyncio loop = asyncio.new_event_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() cache_manager.clear() diff --git a/src/web/static/js/dashboard.js b/src/web/static/js/dashboard.js index b51068e..8ec2791 100644 --- a/src/web/static/js/dashboard.js +++ b/src/web/static/js/dashboard.js @@ -124,6 +124,11 @@ class TSPDashboard { const cv = woFilter.value; woFilter.innerHTML = '' + tenants.map(t => ``).join(''); } + // 工单创建租户选择器 + const woCreate = document.getElementById('wo-tenant-id'); + if (woCreate) { + woCreate.innerHTML = tenants.map(t => ``).join(''); + } } catch (e) { console.warn('加载租户列表失败:', e); } } diff --git a/src/web/static/js/modules/knowledge.js b/src/web/static/js/modules/knowledge.js index ff71f0e..21ddd45 100644 --- a/src/web/static/js/modules/knowledge.js +++ b/src/web/static/js/modules/knowledge.js @@ -437,6 +437,10 @@ Object.assign(TSPDashboard.prototype, { if (manualQuestion) { formData.append('manual_question', manualQuestion); } + // 传递租户 ID + if (this.knowledgeCurrentTenantId) { + formData.append('tenant_id', this.knowledgeCurrentTenantId); + } // 模拟进度更新 let progress = 0; diff --git a/src/web/static/js/modules/workorders.js b/src/web/static/js/modules/workorders.js index 1a315b8..0b813e8 100644 --- a/src/web/static/js/modules/workorders.js +++ b/src/web/static/js/modules/workorders.js @@ -224,9 +224,10 @@ Object.assign(TSPDashboard.prototype, { const description = document.getElementById('wo-description').value.trim(); const category = document.getElementById('wo-category').value; const priority = document.getElementById('wo-priority').value; + const tenantId = document.getElementById('wo-tenant-id')?.value || 'default'; if (!title || !description) { this.showNotification('请填写完整信息', 'warning'); return; } 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(); if (data.success) { this.showNotification('工单创建成功', 'success'); diff --git a/src/web/templates/dashboard.html b/src/web/templates/dashboard.html index 2c0fb65..11e36ab 100644 --- a/src/web/templates/dashboard.html +++ b/src/web/templates/dashboard.html @@ -2292,6 +2292,12 @@