From acd6997bf0b2fa68671f848c8cb93d8526f3ac02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=85=E5=BF=B5?= Date: Thu, 10 Sep 2026 14:23:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(groups):=20=E6=8E=92=E5=BA=8F=E7=BB=88?= =?UTF-8?q?=E5=88=A4=E2=80=94=E2=80=94owner=20=E4=BA=8C=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=BA=8F(=E4=BA=91=E5=AE=A2?= =?UTF-8?q?=E9=80=90=E4=BD=8D=E5=90=BB=E5=90=88),=E5=BC=83=20list=5Forder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 上版按 list_order 排不对:云客员工列表序 ≠ 群统计页员工序。真机对照 切换点员工终判:群统计员工顺序 = owner(微信号/wxid 混存)的**区分大小写 二进制字符串升序**(Nancyjade < csf7169708 < wxid_01gv…,大写在小写前, 逐位吻合),组内 room_id 字符串升序。COLLATE BINARY 双库通用,且无需 JOIN wechat_account。 726 测试绿。 Co-Authored-By: Claude Code --- yunke-server/app/api/routers/groups.py | 17 ++++++----------- yunke-server/tests/test_api_groups.py | 7 +++---- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/yunke-server/app/api/routers/groups.py b/yunke-server/app/api/routers/groups.py index 0794290..077487f 100644 --- a/yunke-server/app/api/routers/groups.py +++ b/yunke-server/app/api/routers/groups.py @@ -102,18 +102,13 @@ async def list_groups( if conditions: list_stmt = list_stmt.where(*conditions) if (channel or "wechat") == "wechat": - # 云客「微信群统计」同款排序(2026-09-10 真机判别):员工分组—— - # 按云客员工列表序(wechat_account.list_order,NULL 垫底按 wx_id)、 - # 组内按 room_id(chatRoomId)字符串升序。WA 保持最近活跃优先。 + # 云客「微信群统计」同款排序(2026-09-10 真机终判):owner_account_id + # (=微信号/wxid 混存,如 Nancyjade < csf7169708 < wxid_01gv…——大写 + # 在小写前=区分大小写)**二进制字符串升序**分组,组内 room_id 字符串 + # 升序。COLLATE BINARY 双库通用(MySQL/SQLite)。WA 保持最近活跃优先。 list_stmt = ( - list_stmt.outerjoin( - WechatAccount, - WechatAccount.wx_id == ChatGroup.owner_account_id, - ) - .order_by( - WechatAccount.list_order.is_(None), - WechatAccount.list_order.asc(), - ChatGroup.owner_account_id.asc(), + list_stmt.order_by( + ChatGroup.owner_account_id.collate("BINARY").asc(), ChatGroup.room_id.asc(), ) .limit(page_size) diff --git a/yunke-server/tests/test_api_groups.py b/yunke-server/tests/test_api_groups.py index 4522c12..cbcdfca 100644 --- a/yunke-server/tests/test_api_groups.py +++ b/yunke-server/tests/test_api_groups.py @@ -64,10 +64,9 @@ async def _seed(session: AsyncSession) -> None: async def test_default_list_returns_all_ordered_desc(make_client): - """No filters -> 3 groups;微信排序=员工分组(list_order NULL 按 owner asc) - +组内 room_id 字符串升序(云客群统计同款,2026-09-10)。 - seed 无 wechat_account 行 → list_order 全 NULL → owner 字符串序: - wa_owner_1 < wx_owner_1 < wx_owner_2 → [wa_room_x, room_a, room_b]。 + """No filters -> 3 groups;微信排序=owner 二进制字符串升序分组+room_id + 升序(云客群统计同款,2026-09-10 终判:区分大小写,大写排小写前)。 + owner 序:wa_owner_1 < wx_owner_1 < wx_owner_2 → [wa_room_x, room_a, room_b]。 """ client = await make_client(_seed) r = await client.get("/api/groups")