fix(ledger): 补全 getEffectivePrice 复合查询条件,修复历史价格跨资产串联 Bug

This commit is contained in:
2026-04-30 13:42:51 +08:00
parent 91e7485259
commit b131400aa9
2 changed files with 13 additions and 4 deletions
+7 -3
View File
@@ -3,7 +3,7 @@
import { db } from '@/db';
import { portfolioSnapshots, transactions, assetPricesHistory, assets, exchangeRates } from '@/db/schema';
import { getPortfolioPositions } from './portfolio';
import { asc, desc, eq, gte, lte, sql } from 'drizzle-orm';
import { and, asc, desc, eq, gte, lte, sql } from 'drizzle-orm';
import Big from 'big.js';
function formatDateString(date: Date): string {
@@ -194,8 +194,12 @@ export async function getEffectivePrice(
price: assetPricesHistory.price,
})
.from(assetPricesHistory)
.where(eq(assetPricesHistory.assetId, assetId))
.where(lte(assetPricesHistory.date, dateStr))
.where(
and(
eq(assetPricesHistory.assetId, assetId),
lte(assetPricesHistory.date, dateStr)
)
)
.orderBy(desc(assetPricesHistory.date))
.limit(1);