fix(customers): WA客户破1万上限(逐员工uid过滤,8585→11931全量)+双渠道页脚云客口径+消息同步刷新最近沟通时间

- wa-friends 逐员工抓取:全局查询~1万行硬上限(云客11931只翻到10000),
  uid=员工WA号过滤(真机验证 declared 1145→1149),total-aware翻页
- declared-total 分渠道:Σ wechat/whatsapp_account.contacts_num(8590/11915)
- 消息增量同步顺带刷新 customer.last_chat_time(云客列表按最近沟通实时
  排序,快照每日一次导致顺序滞后;微信1:1+WA都加)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-20 14:04:06 +08:00
parent fd3cf0003b
commit edca9b4c77
5 changed files with 187 additions and 62 deletions
+17 -6
View File
@@ -29,13 +29,16 @@ PageSizeParam = Annotated[int, Query(ge=1, le=100)]
@router.get("/customers/declared-total")
async def customers_declared_total(session: SessionDep) -> dict:
"""云客口径的微信客户合计 = Σ wechat_account.contacts_num。
"""云客口径的客户合计(分渠道)= Σ 员工账号表的 contacts_num 声明值。
云客列表的页脚数字含 ES 索引重复条目(实测 csf 员工声明 1999 vs 真实
distinct 1449,连行 id 都相同的重复 doc,2026-08-20);本地表存去重真实
客户,此端点把「与云客页脚一字不差」的声明口径给前端展示。
distinct 1449,连行 id 都相同的重复 doc,2026-08-20;WA 同理 11931 vs
8674);本地表存去重真实客户,此端点把「与云客页脚一字不差」的声明口径
给前端展示。
"""
row = (
from app.db.models import WhatsappAccount
wechat = (
await session.execute(
sa.select(
sa.func.coalesce(sa.func.sum(WechatAccount.contacts_num), 0),
@@ -43,9 +46,17 @@ async def customers_declared_total(session: SessionDep) -> dict:
)
)
).one()
whatsapp = (
await session.execute(
sa.select(
sa.func.coalesce(sa.func.sum(WhatsappAccount.contacts_num), 0),
sa.func.count(WhatsappAccount.contacts_num),
)
)
).one()
return {
"declared_total": int(row[0]),
"account_count": int(row[1]),
"wechat": {"declared_total": int(wechat[0]), "account_count": int(wechat[1])},
"whatsapp": {"declared_total": int(whatsapp[0]), "account_count": int(whatsapp[1])},
}