Skip to content

Commit

Permalink
refactor price var
Browse files Browse the repository at this point in the history
  • Loading branch information
BaoXuebin committed Dec 10, 2023
1 parent e905eeb commit fd72ba8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
34 changes: 17 additions & 17 deletions script/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
})
}
// 刷新账本货币缓存
Expand Down
1 change: 0 additions & 1 deletion script/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
)

func isWindows() bool {
return false
os := runtime.GOOS
return os == "windows"
}
Expand Down
8 changes: 4 additions & 4 deletions service/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit fd72ba8

Please sign in to comment.