mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
feat(fund):增加基金估算净值涨跌幅并优化净值显示
- 在基金数据结构中添加 NetEstimatedRate 字段,用于表示估算净值涨跌幅 - 在获取关注基金列表时,计算并填充 NetEstimatedRate 值- 前端组件中增加估算净值涨跌幅的显示 - 优化单位净值和估算净值的显示格式
This commit is contained in:
parent
db43da6577
commit
4f96b0a784
@ -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"
|
||||
@ -39,6 +40,10 @@ type FollowedFund struct {
|
||||
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"`
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
@ -154,9 +154,13 @@ function formatterTitle(title){
|
||||
<n-tag size="small" :bordered="false" type="info">{{info.code}}</n-tag>
|
||||
<n-tag size="small" :bordered="false" type="success" @click="unFollow(info.code)"> 取消关注</n-tag>
|
||||
</template>
|
||||
<n-tag size="small" :type="info.netEstimatedUnit>0?'error':'success'" :bordered="false" v-if="info.netEstimatedUnit">估算净值:{{info.netEstimatedUnit}}({{info.netEstimatedUnitTime}})</n-tag>
|
||||
<n-tag size="small" :type="info.netEstimatedRate>0?'error':'success'" :bordered="false" v-if="info.netEstimatedUnit">
|
||||
估算净值:{{info.netEstimatedUnit}}
|
||||
{{info.netEstimatedRate}} %
|
||||
({{info.netEstimatedUnitTime}})</n-tag>
|
||||
<n-divider vertical></n-divider>
|
||||
<n-tag size="small" :type="info.netUnitValue>0?'error':'success'" :bordered="false" v-if="info.netUnitValue">单位净值:{{info.netUnitValue}}({{info.netUnitValueDate}})</n-tag>
|
||||
<n-tag size="small" :type="info.netEstimatedRate>0?'error':'success'" :bordered="false" v-if="info.netUnitValue">
|
||||
单位净值:{{info.netUnitValue}} ({{info.netUnitValueDate}})</n-tag>
|
||||
<n-divider v-if="info.netUnitValue"></n-divider>
|
||||
<n-flex justify="start">
|
||||
<n-tag size="small" :type="info.fundBasic.netGrowth1>0?'error':'success'" :bordered="false" v-if="info.fundBasic.netGrowth1">近一月:{{info.fundBasic.netGrowth1}}%</n-tag>
|
||||
|
Loading…
x
Reference in New Issue
Block a user