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

View File

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

View File

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