refactor price var

This commit is contained in:
BaoXuebin 2023-12-10 18:47:49 +08:00
parent e905eebf60
commit fd72ba8a2b
3 changed files with 21 additions and 22 deletions

View File

@ -37,8 +37,8 @@ type Account struct {
StartDate string `json:"startDate"` StartDate string `json:"startDate"`
Currency string `json:"currency,omitempty"` // 货币 Currency string `json:"currency,omitempty"` // 货币
CurrencySymbol string `json:"currencySymbol,omitempty"` // 货币符号 CurrencySymbol string `json:"currencySymbol,omitempty"` // 货币符号
ExRate string `json:"exRate,omitempty"` // 汇率 Price string `json:"price,omitempty"` // 汇率
ExDate string `json:"exDate,omitempty"` // 汇率日期 PriceDate string `json:"priceDate,omitempty"` // 汇率日期
IsAnotherCurrency bool `json:"isAnotherCurrency,omitempty"` // 其他币种标识 IsAnotherCurrency bool `json:"isAnotherCurrency,omitempty"` // 其他币种标识
IsCurrent bool `json:"isCurrent,omitempty"` IsCurrent bool `json:"isCurrent,omitempty"`
Positions []AccountPosition `json:"positions,omitempty"` Positions []AccountPosition `json:"positions,omitempty"`
@ -61,12 +61,12 @@ type AccountType struct {
} }
type LedgerCurrency struct { type LedgerCurrency struct {
Name string `json:"name"` Name string `json:"name"`
Currency string `json:"currency"` Currency string `json:"currency"`
Symbol string `json:"symbol"` Symbol string `json:"symbol"`
Current bool `json:"current,omitempty"` Current bool `json:"current,omitempty"`
ExRate string `json:"exRate,omitempty"` Price string `json:"price,omitempty"`
Date string `json:"date,omitempty"` PriceDate string `json:"priceDate,omitempty"`
} }
func GetServerConfig() Config { func GetServerConfig() Config {
@ -488,25 +488,25 @@ func RefreshLedgerCurrency(ledgerConfig *Config) []LedgerCurrency {
currencies := GetLedgerCurrency(ledgerConfig.Id) currencies := GetLedgerCurrency(ledgerConfig.Id)
for _, c := range currencies { for _, c := range currencies {
current := c.Currency == ledgerConfig.OperatingCurrency current := c.Currency == ledgerConfig.OperatingCurrency
var exRate string var price string
var date string var date string
if current { if current {
exRate = "1" price = "1"
date = time.Now().Format("2006-01-02") date = time.Now().Format("2006-01-02")
} else { } else {
value, exists := existCurrencyMap[c.Currency] value, exists := existCurrencyMap[c.Currency]
if exists { if exists {
exRate = value.Value price = value.Value
date = value.Date date = value.Date
} }
} }
result = append(result, LedgerCurrency{ result = append(result, LedgerCurrency{
Name: c.Name, Name: c.Name,
Currency: c.Currency, Currency: c.Currency,
Symbol: c.Symbol, Symbol: c.Symbol,
Current: current, Current: current,
ExRate: exRate, Price: price,
Date: date, PriceDate: date,
}) })
} }
// 刷新账本货币缓存 // 刷新账本货币缓存

View File

@ -6,7 +6,6 @@ import (
) )
func isWindows() bool { func isWindows() bool {
return false
os := runtime.GOOS os := runtime.GOOS
return os == "windows" return os == "windows"
} }

View File

@ -24,8 +24,8 @@ func QueryValidAccount(c *gin.Context) {
currency, ok := currencyMap[account.Currency] currency, ok := currencyMap[account.Currency]
if ok { if ok {
account.CurrencySymbol = currency.Symbol account.CurrencySymbol = currency.Symbol
account.ExRate = currency.ExRate account.Price = currency.Price
account.ExDate = currency.Date account.PriceDate = currency.PriceDate
account.IsAnotherCurrency = true account.IsAnotherCurrency = true
} }
} }
@ -72,8 +72,8 @@ func QueryAllAccount(c *gin.Context) {
currency, ok := currencyMap[account.Currency] currency, ok := currencyMap[account.Currency]
if ok { if ok {
account.CurrencySymbol = currency.Symbol account.CurrencySymbol = currency.Symbol
account.ExRate = currency.ExRate account.Price = currency.Price
account.ExDate = currency.Date account.PriceDate = currency.PriceDate
account.IsAnotherCurrency = true account.IsAnotherCurrency = true
} }
} }