fix: 客户列表多 primary 经理时顿号连接显示(修复字典覆盖)
- mgr_map 由字典推导式改为按 customer_id 聚合 list,再用顿号连接 - 修复同一客户多个 primary 经理时,后写入覆盖先写入导致只显示一个名字 数据修复: 大化瑶族自治县公安局交通警察大队 移除韦柳柏的 primary 分配,唐晓静为唯一 primary Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -103,10 +103,14 @@ async def list_customers(
|
|||||||
select(CustomerAssignment.customer_id, User.name)
|
select(CustomerAssignment.customer_id, User.name)
|
||||||
.join(User, CustomerAssignment.manager_id == User.id)
|
.join(User, CustomerAssignment.manager_id == User.id)
|
||||||
.where(CustomerAssignment.customer_id.in_([c.id for c in items]), CustomerAssignment.role == "primary")
|
.where(CustomerAssignment.customer_id.in_([c.id for c in items]), CustomerAssignment.role == "primary")
|
||||||
|
.order_by(CustomerAssignment.customer_id)
|
||||||
)
|
)
|
||||||
mgr_map = {str(cid): name for cid, name in mgr_result.all()}
|
mgr_map: dict[str, list] = {}
|
||||||
|
for cid, name in mgr_result.all():
|
||||||
|
mgr_map.setdefault(str(cid), []).append(name)
|
||||||
for item in items:
|
for item in items:
|
||||||
item.primary_manager_name = mgr_map.get(str(item.id), None)
|
names = mgr_map.get(str(item.id), [])
|
||||||
|
item.primary_manager_name = "、".join(names) if names else None
|
||||||
|
|
||||||
return CustomerListResponse(
|
return CustomerListResponse(
|
||||||
items=items,
|
items=items,
|
||||||
|
|||||||
Reference in New Issue
Block a user