From 9622e0d828243a8edb809b697fd5dd0a06e98dce Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Thu, 30 Apr 2026 11:38:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E4=BF=AE=E5=A4=8D=20getHistoricalPo?= =?UTF-8?q?sitions=20=E4=B8=AD=20Drizzle=20ORM=20=E7=9A=84=20lte=20?= =?UTF-8?q?=E8=AF=AD=E6=B3=95=E8=B0=83=E7=94=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Memory.md | 6 ++++++ src/actions/snapshots.ts | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Memory.md b/Memory.md index 61d4463..2badcad 100644 --- a/Memory.md +++ b/Memory.md @@ -141,6 +141,12 @@ - 在 `src/actions/snapshots.ts` 中新增 `getEffectivePrice(assetId, targetDate)` 函数:在 `assetPricesHistory` 表中查询指定 `assetId` 且 `date <= targetDate` 的记录,按照 `date` 降序排列 (`desc`) 并 `.limit(1)` 取第一条,实现价格断点结转(Forward-Fill)逻辑——如果目标当天没有导入价格,系统自动抓取该资产在目标日期之前「最新」的一次有效价格。 - 两个函数均使用 `Big.js` 进行高精度数值计算,为历史净值时光机功能提供底层数据支撑。 +## 修复 Drizzle ORM 中 lte 操作符的语法调用错误 (Task 50d) +- 修复 Drizzle ORM 中 lte 操作符的语法调用错误,从链式调用更正为标准纯函数导入。 +- 在 `src/actions/snapshots.ts` 的 `getHistoricalPositions` 函数中,将 `transactions.executedAt.lte(targetDate)` 替换为 `lte(transactions.executedAt, targetDate)`。 +- 同时修复 `getSnapshots` 函数中的 `portfolioSnapshots.date.lte(endDate)` 为 `lte(portfolioSnapshots.date, endDate)`。 +- `lte` 操作符已从文件顶部 `drizzle-orm` 引入,无需额外添加导入。 + ## 净值时光机主引擎 - Day-by-Day 循环遍历重建 (Task 50b) - 完成净值时光机主引擎,通过 Day-by-Day 循环遍历历史流水并结合断点结转价格,自动重建全量历史资产快照。 - 在 `src/actions/snapshots.ts` 中新增 `reconstructPortfolioHistory()` 函数:查询 `transactions` 表找出最早的 `executedAt` 作为回溯起点,转换为 `Asia/Shanghai` 时区后以天为单位循环至今天。 diff --git a/src/actions/snapshots.ts b/src/actions/snapshots.ts index 6337adb..5fdeca4 100644 --- a/src/actions/snapshots.ts +++ b/src/actions/snapshots.ts @@ -97,7 +97,7 @@ export async function getSnapshots(params?: { } if (endDate) { query = query.where( - portfolioSnapshots.date.lte(endDate) + lte(portfolioSnapshots.date, endDate) ); } @@ -125,8 +125,8 @@ export async function getHistoricalPositions(targetDate: Date): Promise