feat:新增接口

This commit is contained in:
zhangyongcai
2026-09-10 23:21:30 +08:00
parent bd7adfd919
commit ea091c041b
25 changed files with 897 additions and 20 deletions
+33
View File
@@ -0,0 +1,33 @@
"""fin_account 客户资金账户表 ORM 模型(现金余额,一人一户)。
balance 为账户总余额(含冻结部分),可用余额 = balance - frozen_amount,不落库。
"""
from __future__ import annotations
from datetime import datetime
from decimal import Decimal
from sqlalchemy import BigInteger, DateTime, Integer, Numeric, String, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class FinAccount(Base):
__tablename__ = "fin_account"
__table_args__ = {"comment": "客户资金账户表(现金余额,申购扣款/赎回入账的账务载体)"}
customer_id: Mapped[int] = mapped_column(
BigInteger, primary_key=True, autoincrement=False
)
balance: Mapped[Decimal] = mapped_column(Numeric(18, 2), server_default="0")
frozen_amount: Mapped[Decimal] = mapped_column(Numeric(18, 2), server_default="0")
currency: Mapped[str] = mapped_column(String(8), server_default="CNY")
status: Mapped[str] = mapped_column(String(16), server_default="正常")
version: Mapped[int] = mapped_column(Integer, server_default="0")
create_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now()
)
update_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), onupdate=func.now()
)
+34
View File
@@ -0,0 +1,34 @@
"""fin_customer_profile 客户画像主表 ORM 模型。"""
from __future__ import annotations
from datetime import datetime
from decimal import Decimal
from sqlalchemy import JSON, BigInteger, DateTime, Integer, Numeric, String, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class FinCustomerProfile(Base):
__tablename__ = "fin_customer_profile"
__table_args__ = {"comment": "客户画像主表(RAG/GraphRAG 个性化推荐核心上下文)"}
customer_id: Mapped[int] = mapped_column(
BigInteger, primary_key=True, autoincrement=False
)
risk_level: Mapped[str | None] = mapped_column(String(16))
risk_score: Mapped[int | None] = mapped_column(Integer)
investment_experience: Mapped[str | None] = mapped_column(String(16))
annual_income_range: Mapped[str | None] = mapped_column(String(32))
total_assets: Mapped[Decimal | None] = mapped_column(Numeric(18, 2))
asset_allocation: Mapped[dict | None] = mapped_column(JSON)
product_preference: Mapped[dict | None] = mapped_column(JSON)
customer_level: Mapped[str | None] = mapped_column(String(16))
confidence_score: Mapped[Decimal] = mapped_column(
Numeric(5, 2), server_default="0.50"
)
profile_version: Mapped[int] = mapped_column(Integer, server_default="1")
update_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), onupdate=func.now()
)
+29
View File
@@ -0,0 +1,29 @@
"""fin_holdings 持仓表 ORM 模型(当前/历史持仓快照)。"""
from __future__ import annotations
from datetime import datetime
from decimal import Decimal
from sqlalchemy import BigInteger, DateTime, Numeric, String, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class FinHoldings(Base):
__tablename__ = "fin_holdings"
__table_args__ = {"comment": "持仓表(当前/历史持仓快照)"}
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
customer_id: Mapped[int] = mapped_column(BigInteger)
product_id: Mapped[int] = mapped_column(BigInteger)
shares: Mapped[Decimal] = mapped_column(Numeric(18, 4), server_default="0")
cost_amount: Mapped[Decimal] = mapped_column(Numeric(18, 2), server_default="0")
current_value: Mapped[Decimal] = mapped_column(Numeric(18, 2), server_default="0")
profit_loss: Mapped[Decimal] = mapped_column(Numeric(18, 2), server_default="0")
profit_ratio: Mapped[Decimal] = mapped_column(Numeric(8, 4), server_default="0")
status: Mapped[str] = mapped_column(String(16), server_default="持有中")
create_time: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
update_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), onupdate=func.now()
)
+32
View File
@@ -0,0 +1,32 @@
"""fin_product 公募基金产品表 ORM 模型。"""
from __future__ import annotations
from datetime import date, datetime
from decimal import Decimal
from sqlalchemy import BigInteger, Date, DateTime, Integer, Numeric, String, func
from sqlalchemy.orm import Mapped, mapped_column
from model.base import Base
class FinProduct(Base):
__tablename__ = "fin_product"
__table_args__ = {"comment": "公募基金产品表"}
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, autoincrement=True)
product_code: Mapped[str] = mapped_column(String(32), unique=True)
product_name: Mapped[str] = mapped_column(String(128))
product_type: Mapped[str] = mapped_column(String(32))
risk_level: Mapped[str] = mapped_column(String(8))
expected_return: Mapped[Decimal | None] = mapped_column(Numeric(7, 4))
nav: Mapped[Decimal | None] = mapped_column(Numeric(12, 6))
nav_date: Mapped[date | None] = mapped_column(Date)
fee_rate: Mapped[Decimal] = mapped_column(Numeric(6, 4), server_default="0.0000")
term_days: Mapped[int] = mapped_column(Integer, server_default="0")
fund_manager: Mapped[str | None] = mapped_column(String(64))
status: Mapped[str] = mapped_column(String(16), server_default="在售")
create_time: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
update_time: Mapped[datetime] = mapped_column(
DateTime, server_default=func.now(), onupdate=func.now()
)