Merge branch 'dev' into hugo-shipping-notice

This commit is contained in:
hugo committed 2026-06-29 18:03:01 +08:00
commit ca32191c77
30 files changed
+1181 -79

No files matched your search

+7
View File
@@ -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:
+27 -1
View File
@@ -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