diff --git a/.env.shared b/.env.shared index 358740d3..8d536ebb 100644 --- a/.env.shared +++ b/.env.shared @@ -28,7 +28,7 @@ EDKB_SOFFICE_TIMEOUT_SEC=600 # Windows Word COM / word_bridge 单次转换超时(秒);复杂 .doc 可适当放宽 EDKB_WORD_TIMEOUT_SEC=300 # 单文件清洗总超时(秒);超时后终止当前文件处理,避免单条任务长期卡住整个 worker -EDKB_FILE_TIMEOUT_SEC=180 +EDKB_FILE_TIMEOUT_SEC=300 # Word 文档(.doc/.docx)单文件清洗总超时(秒);优先于 EDKB_FILE_TIMEOUT_SEC EDKB_WORD_FILE_TIMEOUT_SEC=420 # running 任务回收阈值,须大于 EDKB_SOFFICE_TIMEOUT_SEC 及整条清洗链路耗时 diff --git a/backend/app/api/admin.py b/backend/app/api/admin.py index 0045b09e..0299f19a 100644 --- a/backend/app/api/admin.py +++ b/backend/app/api/admin.py @@ -1320,6 +1320,8 @@ def _apply_chat_logs_report_filters(query): query = query.filter(Agent.name.cast(db.String).ilike(f'%{value}%')) elif key == 'username': query = query.filter(User.username.cast(db.String).ilike(f'%{value}%')) + elif key == 'real_name': + query = query.filter(User.real_name.cast(db.String).ilike(f'%{value}%')) elif hasattr(ChatLog, key): col = getattr(ChatLog, key) query = query.filter(col.cast(db.String).ilike(f'%{value}%')) @@ -1391,6 +1393,11 @@ def get_table_count(table): """ Return total row count for admin report tables. """ + if table == 'chat_logs': + query = _apply_chat_logs_report_filters(_chat_logs_report_query()) + total = query.count() + return jsonify({'table': table, 'total': int(total or 0)}) + model_map = {'users': User, 'agents': Agent, 'chat_logs': ChatLog, 'feedbacks': Feedback, 'permission_requests': PermissionRequest, 'departments': Department, 'quick_questions': QuickQuestion, 'user_homepage_configs': UserHomepageConfig, 'user_favorite_agents': UserFavoriteAgent, 'user_default_agents': UserDefaultAgent} model = model_map.get(table) if not model: diff --git a/backend/tests/test_admin.py b/backend/tests/test_admin.py index 487dafa6..d042fe6b 100644 --- a/backend/tests/test_admin.py +++ b/backend/tests/test_admin.py @@ -1,5 +1,5 @@ import pytest -from app.models import Agent, User, PermissionRequest +from app.models import Agent, ChatLog, User, PermissionRequest from app import db def test_agent_lifecycle(client, admin_headers): @@ -278,3 +278,29 @@ def test_reports(client, admin_headers): data = response.json assert 'avg_score' in data assert 'distribution' in data + + +def test_chat_logs_report_filters_by_real_name(client, app, admin_headers): + """聊天日志报表真实姓名筛选:real_name 是 User 关联字段,列表与计数必须使用同一过滤条件。""" + with app.app_context(): + agent = Agent(name='HR Assistant', type='api', dify_app_id='hr-app', dify_api_key='hr-key') + sophie = User(username='26030025', email='sophie@example.com', real_name='sophie', role='user') + admin = User(username='admin-user', email='admin-user@example.com', real_name='admin', role='user') + db.session.add_all([agent, sophie, admin]) + db.session.flush() + db.session.add_all([ + ChatLog(user_id=sophie.id, agent_id=agent.id, query='人事规章', answer='A', tokens_used=1), + ChatLog(user_id=admin.id, agent_id=agent.id, query='上班时间', answer='B', tokens_used=1), + ]) + db.session.commit() + + response = client.get('/api/admin/database/chat_logs?real_name=sophie', headers=admin_headers) + assert response.status_code == 200 + rows = response.json + assert len(rows) == 1 + assert rows[0]['real_name'] == 'sophie' + assert rows[0]['username'] == '26030025' + + count_response = client.get('/api/admin/database/chat_logs/count?real_name=sophie', headers=admin_headers) + assert count_response.status_code == 200 + assert count_response.json['total'] == 1 diff --git a/frontend/src/features/chat/components/ChatInputBar.vue b/frontend/src/features/chat/components/ChatInputBar.vue index 5fabde40..55ed27df 100644 --- a/frontend/src/features/chat/components/ChatInputBar.vue +++ b/frontend/src/features/chat/components/ChatInputBar.vue @@ -3,7 +3,7 @@ * 聊天输入栏:文本框、附件、语音、知识库选择与发送按钮。 */