From a8b8d9d81c4afcb5ae1e6c94fd1ed6320d30a084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Sat, 22 Aug 2026 17:00:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(export+calls):=20=E5=90=8C=E7=B1=BBowner?= =?UTF-8?q?=E9=94=99=E4=BD=8D=E9=97=AE=E9=A2=98=E5=85=A8=E9=9D=A2=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D(=E7=BE=A4=E5=AF=BC=E5=87=BA=E4=B8=8D=E6=8C=89owner?= =?UTF-8?q?=E8=BF=87=E6=BB=A4+=E7=BE=A4=E8=AF=AD=E9=9F=B3=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=82=B9=E5=87=BB=E8=B5=B0=E7=BE=A4=E8=81=8A=E8=B7=AF?= =?UTF-8?q?=E7=94=B1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /api/export/chat-html: room 查询忽略 owner(chat_group owner 错位同 ChatTimeline,群列表/聊天页的导出按钮原来会导出空文件) - CallList viewCallCustomer: talker 以 @chatroom 结尾→group-chat 路由 (原走 1:1 路由按 talker_id 查@chatroom 恒空) - TDD: 群消息在 ownerB 名下用 ownerA+room 导出仍能拿到;428 测试绿 - 实测:错位 owner 导出 43304 群返回 15002 个消息元素 Co-Authored-By: Claude --- yunke-server/app/api/routers/export.py | 23 ++++++++++++----------- yunke-server/tests/test_api_export.py | 23 +++++++++++++++++++++++ yunkes/src/views/CallList.vue | 17 ++++++++++++++++- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/yunke-server/app/api/routers/export.py b/yunke-server/app/api/routers/export.py index bf06787..7ff4488 100644 --- a/yunke-server/app/api/routers/export.py +++ b/yunke-server/app/api/routers/export.py @@ -128,21 +128,22 @@ async def export_chat_html( start: Annotated[int | None, Query(ge=0)] = None, end: Annotated[int | None, Query(ge=0)] = None, ) -> Response: - q = ( - sa.select(Message) - .where(Message.channel == channel) - .where(Message.owner_account_id == owner_account_id) - ) + # 群聊(room_id)不按 owner 过滤:chat_group 表按 room 去重、owner 被末位 + # 员工覆盖,与消息实际归属 owner 错位会导出空文件(同 ChatTimeline 修复, + # 2026-08-22);room 全局唯一且消息只在单一 owner 名下。 + q = sa.select(Message).where(Message.channel == channel) peer = "" if room_id: q = q.where(Message.room_id == room_id) peer = room_id - elif talker_id: - # DM:限定 room_id 为空,避免误捞群消息 - q = q.where(Message.talker_id == talker_id).where( - (Message.room_id == None) | (Message.room_id == "") # noqa: E711 - ) - peer = talker_id + else: + q = q.where(Message.owner_account_id == owner_account_id) + if talker_id: + # DM:限定 room_id 为空,避免误捞群消息 + q = q.where(Message.talker_id == talker_id).where( + (Message.room_id == None) | (Message.room_id == "") # noqa: E711 + ) + peer = talker_id if start is not None: q = q.where(Message.timestamp >= start) if end is not None: diff --git a/yunke-server/tests/test_api_export.py b/yunke-server/tests/test_api_export.py index 9283948..fb005cf 100644 --- a/yunke-server/tests/test_api_export.py +++ b/yunke-server/tests/test_api_export.py @@ -137,3 +137,26 @@ async def test_export_no_warning_below_cap(make_client): assert r.status_code == 200 # No warning DIV (the CSS class still lives in