From fa3c3935f71ba76a6ed3df63bb796759eadc84df Mon Sep 17 00:00:00 2001 From: Jeason <1710884619@qq.com> Date: Thu, 2 Apr 2026 21:25:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=9F=E6=88=B7=E9=9B=86=E6=88=90?= =?UTF-8?q?=E9=81=97=E6=BC=8F=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 同时填充工单创建的租户选择器 --- data/tsp_assistant.db | Bin 217088 -> 217088 bytes src/agent_assistant.py | 5 +++-- src/web/blueprints/knowledge.py | 3 ++- src/web/static/js/dashboard.js | 5 +++++ src/web/static/js/modules/knowledge.js | 4 ++++ src/web/static/js/modules/workorders.js | 3 ++- src/web/templates/dashboard.html | 6 ++++++ 7 files changed, 22 insertions(+), 4 deletions(-) diff --git a/data/tsp_assistant.db b/data/tsp_assistant.db index 46b1d5fae61535b6d126a9d6fa60b9a1d3540063..1e9f1fb268e7bcec527baaa104f349825d551ef4 100644 GIT binary patch delta 216 zcmZozz}v8ZcY-wI>WMPWjH??HS`!$zCNM2oFU8HZoq@lVpNp@bPlR_SuN==}9u4lb z+(um6Hw!Avycas3q C+ClpO delta 68 zcmV-K0K5Nypbdba4UiiFr;!{(0jGgrg 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 @@