fix(names): 会话/统计弹窗/zip 文件名的共享好友昵称读 link 快照
用户报 Lily 聊天窗口「聊天好友」列表里 A**郑 显示成 wxid_ir6uxy2li8no22 ——A**郑是 14 个员工共享的客户,档案行(customer 全局单行 last-wins)挂在 别的员工名下,按 owner 查档案查空,三个显示位回退 wxid: - sessions._meta(会话列表名字/头像/delete_flag) - staff_chat_stats._customer_names(五数字弹窗明细) - chat-html-zip 文件名 统一改为优先 customer_account_link per-owner 快照(link 未覆盖回退档案, 空表过渡安全)。staff_stats(统计分析新客户等)仍是档案口径,属分析语义 另行评估。613 测试绿(新增会话共享好友昵称 2 例)。 Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -22,7 +22,13 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.api.deps import get_session
|
||||
from app.api.schemas import SessionListOut, SessionOut
|
||||
from app.db.models import ChatGroup, Customer, Message, MsgDailyStats
|
||||
from app.db.models import (
|
||||
ChatGroup,
|
||||
Customer,
|
||||
CustomerAccountLink,
|
||||
Message,
|
||||
MsgDailyStats,
|
||||
)
|
||||
from app.storage.summary import day_key, has_rows as _summary_has_rows
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["sessions"])
|
||||
@@ -117,7 +123,13 @@ async def _summary_rows(
|
||||
|
||||
|
||||
async def _meta(session: AsyncSession, owner: str, channel: str, friend_ids: list[str], room_ids: list[str]):
|
||||
"""查 customer/chat_group 表合并昵称/头像;好友行额外带 delete_flag(is_del 过滤用)。
|
||||
"""查 customer_account_link(主)/customer(兜底)/chat_group 合并昵称/头像。
|
||||
|
||||
好友名优先读 ``customer_account_link`` 的 per-owner 快照——共享客户的
|
||||
档案行(customer 全局单行,last-wins)可能挂在别的员工名下,按 owner 查
|
||||
档案会查空,会话列表就回退显示 wxid(2026-09-09 用户报「有昵称却显示
|
||||
微信号」);link 表每账号一行,回填后都有昵称。link 没覆盖的(空表过渡/
|
||||
老数据)回退档案路径。
|
||||
|
||||
friends 值为 ``(name, avatar, delete_flag)``;群无删除标记,groups 值仍为
|
||||
``(name, avatar)``。
|
||||
@@ -126,12 +138,29 @@ async def _meta(session: AsyncSession, owner: str, channel: str, friend_ids: lis
|
||||
if friend_ids:
|
||||
for fid, remark, nick, real, avatar, delete_flag in (await session.execute(
|
||||
sa.select(
|
||||
Customer.friend_id, Customer.friend_remark, Customer.friend_nickname,
|
||||
Customer.real_name, Customer.head_image_url, Customer.delete_flag,
|
||||
CustomerAccountLink.friend_id, CustomerAccountLink.friend_remark,
|
||||
CustomerAccountLink.friend_nickname, CustomerAccountLink.real_name,
|
||||
CustomerAccountLink.head_image_url, CustomerAccountLink.delete_flag,
|
||||
)
|
||||
.where(
|
||||
CustomerAccountLink.channel == channel,
|
||||
CustomerAccountLink.owner_account_id == owner,
|
||||
CustomerAccountLink.friend_id.in_(friend_ids),
|
||||
)
|
||||
.where(Customer.channel == channel, Customer.owner_account_id == owner, Customer.friend_id.in_(friend_ids))
|
||||
)).all():
|
||||
friends[fid] = (remark or nick or real or fid, avatar, delete_flag)
|
||||
# link 未覆盖的好友回退档案(按 owner 过滤;共享好友在此仍可能查空,
|
||||
# 上层以 wxid 兜底显示)
|
||||
missing = [fid for fid in friend_ids if fid not in friends]
|
||||
if missing:
|
||||
for fid, remark, nick, real, avatar, delete_flag in (await session.execute(
|
||||
sa.select(
|
||||
Customer.friend_id, Customer.friend_remark, Customer.friend_nickname,
|
||||
Customer.real_name, Customer.head_image_url, Customer.delete_flag,
|
||||
)
|
||||
.where(Customer.channel == channel, Customer.owner_account_id == owner, Customer.friend_id.in_(missing))
|
||||
)).all():
|
||||
friends[fid] = (remark or nick or real or fid, avatar, delete_flag)
|
||||
groups: dict[str, tuple[str, str | None]] = {}
|
||||
if room_ids:
|
||||
for rid, name, avatar in (await session.execute(
|
||||
|
||||
Reference in New Issue
Block a user