Files
Mutual_Fund/service/advisor/data_query.py
T

33 lines
1005 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""工作台到投顾 Agent 的客户数据查询代理。"""
from __future__ import annotations
from sqlalchemy.ext.asyncio import AsyncSession
from model.sys_user import SysUser
from schemas.advisor import AdvisorDataQueryReq
from service.advisor.agent_client import get_agent_client
from service.advisor.permissions import ensure_customer_owned
async def query_customer_data(
db: AsyncSession,
user: SysUser,
*,
auth_header: str,
trace_id: str,
req: AdvisorDataQueryReq,
) -> dict:
"""先做工作台归属校验,再透传到 Agent;customer_id 不由 Agent 客户端覆盖。"""
await ensure_customer_owned(db, user.id, req.customer_id)
payload = req.model_dump(exclude_none=True)
result = await get_agent_client().data_query(
payload,
auth_header=auth_header,
trace_id=trace_id,
)
data = result["data"] or {}
data.pop("sql", None)
if result["warning"]:
data["warning"] = result["warning"]
return data