345
This commit is contained in:
@@ -1438,7 +1438,9 @@ func (s *AIBookkeepingService) GetSession(sessionID string) (*AISession, bool) {
|
||||
// FinancialContext 用户财务上下文,供 AI 综合分析
|
||||
type FinancialContext struct {
|
||||
// 账户信息
|
||||
TotalBalance float64 `json:"total_balance"` // 总余额
|
||||
TotalBalance float64 `json:"total_balance"` // 净资产 (资产 - 负债)
|
||||
TotalAssets float64 `json:"total_assets"` // 总资产
|
||||
TotalLiabilities float64 `json:"total_liabilities"` // 总负债
|
||||
AccountSummary []AccountBrief `json:"account_summary"` // 账户摘要
|
||||
|
||||
// 最近消费
|
||||
@@ -1500,6 +1502,16 @@ func (s *AIBookkeepingService) GetUserFinancialContext(ctx context.Context, user
|
||||
if err == nil {
|
||||
for _, acc := range accounts {
|
||||
fc.TotalBalance += acc.Balance
|
||||
|
||||
// 根据余额正负判断资产/负债
|
||||
// 余额 >= 0 计入资产
|
||||
// 余额 < 0 计入负债(取绝对值)
|
||||
if acc.Balance >= 0 {
|
||||
fc.TotalAssets += acc.Balance
|
||||
} else {
|
||||
fc.TotalLiabilities += -acc.Balance
|
||||
}
|
||||
|
||||
fc.AccountSummary = append(fc.AccountSummary, AccountBrief{
|
||||
Name: acc.Name,
|
||||
Balance: acc.Balance,
|
||||
|
||||
Reference in New Issue
Block a user