From 8f5ce4bc74a38d21e41bb8a009500d17368b9f87 Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Wed, 29 Apr 2026 12:17:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(ledger):=20=E4=BF=AE=E5=A4=8D=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E5=BC=95=E6=93=8E=20reduce=20=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=80=BC=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF=EF=BC=8C=E4=BF=9D?= =?UTF-8?q?=E9=9A=9C=E6=AF=8F=E6=97=A5=E5=BF=AB=E7=85=A7=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/snapshots.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/actions/snapshots.ts b/src/actions/snapshots.ts index 7d9c2d5..d221db8 100644 --- a/src/actions/snapshots.ts +++ b/src/actions/snapshots.ts @@ -4,6 +4,7 @@ import { db } from '@/db'; import { portfolioSnapshots } from '@/db/schema'; import { getPortfolioPositions } from './portfolio'; import { eq, sql } from 'drizzle-orm'; +import Big from 'big.js'; function getTodayInShanghai(): string { const now = new Date(); @@ -22,13 +23,13 @@ export async function recordDailySnapshot() { const totalValueCny = positions.reduce( (sum, pos) => sum.plus(pos.cnyValue || '0'), - 0 as number | string - ); + new Big(0) + ).toString(); const totalCostCny = positions.reduce( (sum, pos) => sum.plus(pos.totalCostCny || '0'), - 0 as number | string - ); + new Big(0) + ).toString(); const dateStr = getTodayInShanghai(); @@ -44,8 +45,8 @@ export async function recordDailySnapshot() { await db .update(portfolioSnapshots) .set({ - totalValueCny: String(totalValueCny), - totalCostCny: String(totalCostCny), + totalValueCny, + totalCostCny, updatedAt: now, }) .where(eq(portfolioSnapshots.date, dateStr)); @@ -54,8 +55,8 @@ export async function recordDailySnapshot() { success: true, action: 'updated', date: dateStr, - totalValueCny: String(totalValueCny), - totalCostCny: String(totalCostCny), + totalValueCny, + totalCostCny, }; } @@ -63,8 +64,8 @@ export async function recordDailySnapshot() { .insert(portfolioSnapshots) .values({ date: dateStr, - totalValueCny: String(totalValueCny), - totalCostCny: String(totalCostCny), + totalValueCny, + totalCostCny, createdAt: now, updatedAt: now, }); @@ -73,8 +74,8 @@ export async function recordDailySnapshot() { success: true, action: 'inserted', date: dateStr, - totalValueCny: String(totalValueCny), - totalCostCny: String(totalCostCny), + totalValueCny, + totalCostCny, }; }