From 4f96b0a784646e729f77ff4dfafca294180bb6f5 Mon Sep 17 00:00:00 2001 From: sparkmemory Date: Mon, 10 Mar 2025 14:59:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(fund):=E5=A2=9E=E5=8A=A0=E5=9F=BA=E9=87=91?= =?UTF-8?q?=E4=BC=B0=E7=AE=97=E5=87=80=E5=80=BC=E6=B6=A8=E8=B7=8C=E5=B9=85?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E5=87=80=E5=80=BC=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在基金数据结构中添加 NetEstimatedRate 字段,用于表示估算净值涨跌幅 - 在获取关注基金列表时,计算并填充 NetEstimatedRate 值- 前端组件中增加估算净值涨跌幅的显示 - 优化单位净值和估算净值的显示格式 --- backend/data/fund_data_api.go | 25 +++++++++++++++++++------ frontend/src/components/fund.vue | 8 ++++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/backend/data/fund_data_api.go b/backend/data/fund_data_api.go index db1f1d5..84006b6 100644 --- a/backend/data/fund_data_api.go +++ b/backend/data/fund_data_api.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "github.com/duke-git/lancet/v2/convertor" + "github.com/duke-git/lancet/v2/mathutil" "github.com/duke-git/lancet/v2/strutil" "github.com/go-resty/resty/v2" "go-stock/backend/db" @@ -34,12 +35,16 @@ type FollowedFund struct { Code string `json:"code" gorm:"index"` // 基金代码 Name string `json:"name"` // 基金简称 - NetUnitValue *float64 `json:"netUnitValue"` // 单位净值 - NetUnitValueDate string `json:"netUnitValueDate"` // 单位净值日期 - NetEstimatedUnit *float64 `json:"netEstimatedUnit"` // 估算单位净值 - NetEstimatedTime string `json:"netEstimatedUnitTime"` // 估算单位净值日期 - NetAccumulated *float64 `json:"netAccumulated"` // 累计净值 - FundBasic FundBasic `json:"fundBasic" gorm:"foreignKey:Code;references:Code"` + NetUnitValue *float64 `json:"netUnitValue"` // 单位净值 + NetUnitValueDate string `json:"netUnitValueDate"` // 单位净值日期 + NetEstimatedUnit *float64 `json:"netEstimatedUnit"` // 估算单位净值 + NetEstimatedTime string `json:"netEstimatedUnitTime"` // 估算单位净值日期 + NetAccumulated *float64 `json:"netAccumulated"` // 累计净值 + + //计算值 + NetEstimatedRate *float64 `json:"netEstimatedRate"` // 估算单位净值涨跌幅 + + FundBasic FundBasic `json:"fundBasic" gorm:"foreignKey:Code;references:Code"` } func (FollowedFund) TableName() string { @@ -226,6 +231,14 @@ func (f *FundApi) GetFundList(key string) []FundBasic { func (f *FundApi) GetFollowedFund() []FollowedFund { var funds []FollowedFund db.Dao.Preload("FundBasic").Find(&funds) + for i, fund := range funds { + if fund.NetUnitValue != nil && fund.NetEstimatedUnit != nil && *fund.NetUnitValue > 0 { + netEstimatedRate := (*(funds[i].NetEstimatedUnit) - *(funds[i].NetUnitValue)) / *(fund.NetUnitValue) * 100 + netEstimatedRate = mathutil.RoundToFloat(netEstimatedRate, 2) + funds[i].NetEstimatedRate = &netEstimatedRate + } + + } return funds } func (f *FundApi) FollowFund(fundCode string) string { diff --git a/frontend/src/components/fund.vue b/frontend/src/components/fund.vue index bb372ad..0c9359e 100644 --- a/frontend/src/components/fund.vue +++ b/frontend/src/components/fund.vue @@ -154,9 +154,13 @@ function formatterTitle(title){ {{info.code}}  取消关注 - 估算净值:{{info.netEstimatedUnit}}({{info.netEstimatedUnitTime}}) + + 估算净值:{{info.netEstimatedUnit}}  + {{info.netEstimatedRate}} %    + ({{info.netEstimatedUnitTime}}) - 单位净值:{{info.netUnitValue}}({{info.netUnitValueDate}}) + + 单位净值:{{info.netUnitValue}} ({{info.netUnitValueDate}}) 近一月:{{info.fundBasic.netGrowth1}}%