29 lines
790 B
Go
29 lines
790 B
Go
|
|
package schema
|
|||
|
|
|
|||
|
|
import "gorm.io/gorm"
|
|||
|
|
|
|||
|
|
// BlocksMember 板块成分股。
|
|||
|
|
type BlocksMember struct {
|
|||
|
|
gorm.Model
|
|||
|
|
TiCode string `gorm:"type:varchar(50);not null;default:'';comment:板块代码;index" json:"ti_code"`
|
|||
|
|
StockCode string `gorm:"type:varchar(50);not null;default:'';comment:股票代码;index" json:"stock_code"`
|
|||
|
|
Weight float64 `gorm:"type:float;not null;default:0;comment:权重" json:"weight"`
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func (BlocksMember) TableName() string {
|
|||
|
|
return "blocks_member"
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// Key 成分在板块内的键:ti_code + stock_code。
|
|||
|
|
func (b *BlocksMember) Key() string {
|
|||
|
|
if b.TiCode == "" && b.StockCode == "" {
|
|||
|
|
return ""
|
|||
|
|
}
|
|||
|
|
return b.TiCode + "/" + b.StockCode
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// HasWeight 是否带权重量化成分。
|
|||
|
|
func (b *BlocksMember) HasWeight() bool {
|
|||
|
|
return b.Weight > 0
|
|||
|
|
}
|