Files
group_xinghuo_jinrong/app/service/platform/customer_service.py
T
zhanghongyu_0626 ef56c56435 feat(api): 实现代销平台 API v0.1,包括客户、产品、理财师、合规及员工接口
- 新增多个 API 路由:`/api/customers`, `/api/products`, `/api/advisors`, `/api/compliance`, `/api/staff`,支持客户信息、产品详情、理财师客户列表、合规判定及员工上下文查询。
- 引入平台服务层,封装核心只读操作,支持数据脱敏功能。
- 更新依赖注入,确保各 API 路由的权限控制与数据访问一致性。
- 添加相应的单元测试,确保新接口的功能完整性与稳定性。

此更新为代销平台提供了基础的 REST API 支持,增强了系统的可扩展性与可维护性。
2026-09-08 21:01:07 +08:00

54 lines
1.7 KiB
Python

"""客户 L0 / 持仓 / 流水 / 可购产品(Platform Service)。"""
from __future__ import annotations
from typing import Any
from app.repository.core_ro import CoreReadOnlyRepository
from app.service.platform.common import prepare_row, to_jsonable
def get_customer_l0(
customer_id: str, core_ro: CoreReadOnlyRepository | None = None
) -> dict[str, Any] | None:
repo = core_ro or CoreReadOnlyRepository()
row = repo.get_customer_l0(customer_id)
return prepare_row(row)
def list_holdings(
customer_id: str,
limit: int = 500,
core_ro: CoreReadOnlyRepository | None = None,
) -> dict[str, Any]:
repo = core_ro or CoreReadOnlyRepository()
rows = repo.list_holdings(customer_id, limit=limit)
items = [prepare_row(r) for r in rows]
truncated = len(rows) >= limit
return {"items": items, "total": len(items), "limit": limit, "truncated": truncated}
def list_trades(
customer_id: str,
limit: int = 50,
offset: int = 0,
core_ro: CoreReadOnlyRepository | None = None,
) -> dict[str, Any]:
repo = core_ro or CoreReadOnlyRepository()
fetch = min(limit + offset, 500)
rows = repo.list_trades(customer_id, limit=fetch)
page = rows[offset : offset + limit]
items = [to_jsonable(r) for r in page]
return {"items": items, "total": len(rows), "limit": limit, "offset": offset}
def list_customer_products(
customer_id: str,
limit: int = 50,
core_ro: CoreReadOnlyRepository | None = None,
) -> dict[str, Any]:
repo = core_ro or CoreReadOnlyRepository()
rows = repo.list_products_for_customer(customer_id, limit=limit)
items = [to_jsonable(r) for r in rows]
return {"items": items, "total": len(items), "limit": limit}