fix(db): 修复 getHistoricalPositions 中 Drizzle ORM 的 lte 语法调用错误
This commit is contained in:
parent
c38d3fe30f
commit
9622e0d828
@ -141,6 +141,12 @@
|
|||||||
- 在 `src/actions/snapshots.ts` 中新增 `getEffectivePrice(assetId, targetDate)` 函数:在 `assetPricesHistory` 表中查询指定 `assetId` 且 `date <= targetDate` 的记录,按照 `date` 降序排列 (`desc`) 并 `.limit(1)` 取第一条,实现价格断点结转(Forward-Fill)逻辑——如果目标当天没有导入价格,系统自动抓取该资产在目标日期之前「最新」的一次有效价格。
|
- 在 `src/actions/snapshots.ts` 中新增 `getEffectivePrice(assetId, targetDate)` 函数:在 `assetPricesHistory` 表中查询指定 `assetId` 且 `date <= targetDate` 的记录,按照 `date` 降序排列 (`desc`) 并 `.limit(1)` 取第一条,实现价格断点结转(Forward-Fill)逻辑——如果目标当天没有导入价格,系统自动抓取该资产在目标日期之前「最新」的一次有效价格。
|
||||||
- 两个函数均使用 `Big.js` 进行高精度数值计算,为历史净值时光机功能提供底层数据支撑。
|
- 两个函数均使用 `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 循环遍历重建 (Task 50b)
|
||||||
- 完成净值时光机主引擎,通过 Day-by-Day 循环遍历历史流水并结合断点结转价格,自动重建全量历史资产快照。
|
- 完成净值时光机主引擎,通过 Day-by-Day 循环遍历历史流水并结合断点结转价格,自动重建全量历史资产快照。
|
||||||
- 在 `src/actions/snapshots.ts` 中新增 `reconstructPortfolioHistory()` 函数:查询 `transactions` 表找出最早的 `executedAt` 作为回溯起点,转换为 `Asia/Shanghai` 时区后以天为单位循环至今天。
|
- 在 `src/actions/snapshots.ts` 中新增 `reconstructPortfolioHistory()` 函数:查询 `transactions` 表找出最早的 `executedAt` 作为回溯起点,转换为 `Asia/Shanghai` 时区后以天为单位循环至今天。
|
||||||
|
|||||||
@ -97,7 +97,7 @@ export async function getSnapshots(params?: {
|
|||||||
}
|
}
|
||||||
if (endDate) {
|
if (endDate) {
|
||||||
query = query.where(
|
query = query.where(
|
||||||
portfolioSnapshots.date.lte(endDate)
|
lte(portfolioSnapshots.date, endDate)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,8 +125,8 @@ export async function getHistoricalPositions(targetDate: Date): Promise<Historic
|
|||||||
executedAt: transactions.executedAt,
|
executedAt: transactions.executedAt,
|
||||||
})
|
})
|
||||||
.from(transactions)
|
.from(transactions)
|
||||||
.where(
|
.where(
|
||||||
transactions.executedAt.lte(targetDate)
|
lte(transactions.executedAt, targetDate)
|
||||||
)
|
)
|
||||||
.orderBy(asc(transactions.executedAt));
|
.orderBy(asc(transactions.executedAt));
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user