Files
Mutual_Fund/repositories/fund_nav.py
T

33 lines
1.1 KiB
Python

"""fund_nav_history 净值历史仓储:按产品代码与日期区间查询走势。
数据现状说明:fund_nav_history.product_id 列在 Mock 数据灌入时存的是基金代码
(如 110001)而非 fin_product 主键 id。为不改数据库、只通过代码适配,这里用
CAST 把 BIGINT 列按字符串与 product_code 比对。
"""
from __future__ import annotations
from datetime import date
from sqlalchemy import String, cast, select
from model.fund_nav_history import FundNavHistory
from repositories.base import BaseRepository
class FundNavRepo(BaseRepository):
model = FundNavHistory
async def list_series(
self, product_code: str, start_date: date, end_date: date
) -> list[FundNavHistory]:
stmt = (
select(FundNavHistory)
.where(
cast(FundNavHistory.product_id, String) == product_code,
FundNavHistory.nav_date >= start_date,
FundNavHistory.nav_date <= end_date,
)
.order_by(FundNavHistory.nav_date.asc())
)
return list((await self.db.scalars(stmt)).all())