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")