fix schema
This commit is contained in:
@@ -2,8 +2,8 @@ package schema
|
|||||||
|
|
||||||
import "gorm.io/gorm"
|
import "gorm.io/gorm"
|
||||||
|
|
||||||
// DatasetStockBasic 股票基本信息表(合并 dataset/stock 与 gostock 字段;gostock 独有 Level、Desc)。
|
// DatasetBasic 股票基本信息表(合并 dataset/stock 与 gostock 字段;gostock 独有 Level、Desc)。
|
||||||
type DatasetStockBasic struct {
|
type DatasetBasic struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
TsCode string `gorm:"type:varchar(50);not null;index;comment:TS代码"`
|
TsCode string `gorm:"type:varchar(50);not null;index;comment:TS代码"`
|
||||||
Symbol string `gorm:"type:varchar(50);not null;comment:股票代码"`
|
Symbol string `gorm:"type:varchar(50);not null;comment:股票代码"`
|
||||||
@@ -21,17 +21,17 @@ type DatasetStockBasic struct {
|
|||||||
ActEntType string `gorm:"type:varchar(50);not null;default:'';comment:实控人企业性质"`
|
ActEntType string `gorm:"type:varchar(50);not null;default:'';comment:实控人企业性质"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DatasetStockBasic) TableName() string {
|
func (DatasetBasic) TableName() string {
|
||||||
return "dataset_stock_basic"
|
return "dataset_basic"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key 业务主键:TS 代码。
|
// Key 业务主键:TS 代码。
|
||||||
func (s *DatasetStockBasic) Key() string {
|
func (s *DatasetBasic) Key() string {
|
||||||
return s.TsCode
|
return s.TsCode
|
||||||
}
|
}
|
||||||
|
|
||||||
// DisplaySymbol 展示用代码:有 symbol 用 symbol,否则用 ts_code。
|
// DisplaySymbol 展示用代码:有 symbol 用 symbol,否则用 ts_code。
|
||||||
func (s *DatasetStockBasic) DisplaySymbol() string {
|
func (s *DatasetBasic) DisplaySymbol() string {
|
||||||
if s.Symbol != "" {
|
if s.Symbol != "" {
|
||||||
return s.Symbol
|
return s.Symbol
|
||||||
}
|
}
|
||||||
@@ -39,6 +39,6 @@ func (s *DatasetStockBasic) DisplaySymbol() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsNorthbound 是否沪深港通标的(H 沪股通 / S 深股通)。
|
// IsNorthbound 是否沪深港通标的(H 沪股通 / S 深股通)。
|
||||||
func (s *DatasetStockBasic) IsNorthbound() bool {
|
func (s *DatasetBasic) IsNorthbound() bool {
|
||||||
return s.IsHS == "H" || s.IsHS == "S"
|
return s.IsHS == "H" || s.IsHS == "S"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package schema
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
// DatasetStockDaily 股票日线数据(两仓库结构一致)。
|
// DatasetDaily 股票日线数据(两仓库结构一致)。
|
||||||
type DatasetStockDaily struct {
|
type DatasetDaily struct {
|
||||||
ID uint `gorm:"primarykey;autoIncrement" json:"id"`
|
ID uint `gorm:"primarykey;autoIncrement" json:"id"`
|
||||||
TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;uniqueIndex:un_code_date;comment:股票代码" json:"ts_code"`
|
TsCode string `gorm:"type:varchar(20);not null;index:idx_ts_code;uniqueIndex:un_code_date;comment:股票代码" json:"ts_code"`
|
||||||
TradeDate int `gorm:"index:idx_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"`
|
TradeDate int `gorm:"index:idx_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"`
|
||||||
@@ -19,12 +19,12 @@ type DatasetStockDaily struct {
|
|||||||
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
|
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DatasetStockDaily) TableName() string {
|
func (DatasetDaily) TableName() string {
|
||||||
return "dataset_stock_daily"
|
return "dataset_daily"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key 业务主键:ts_code + 交易日。
|
// Key 业务主键:ts_code + 交易日。
|
||||||
func (d *DatasetStockDaily) Key() string {
|
func (d *DatasetDaily) Key() string {
|
||||||
if d.TsCode == "" && d.TradeDate == 0 {
|
if d.TsCode == "" && d.TradeDate == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -32,17 +32,17 @@ func (d *DatasetStockDaily) Key() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsRising 是否收涨(昨收有效且收盘高于昨收)。
|
// IsRising 是否收涨(昨收有效且收盘高于昨收)。
|
||||||
func (d *DatasetStockDaily) IsRising() bool {
|
func (d *DatasetDaily) IsRising() bool {
|
||||||
return d.PreClose > 0 && d.Close > d.PreClose
|
return d.PreClose > 0 && d.Close > d.PreClose
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsFalling 是否收跌。
|
// IsFalling 是否收跌。
|
||||||
func (d *DatasetStockDaily) IsFalling() bool {
|
func (d *DatasetDaily) IsFalling() bool {
|
||||||
return d.PreClose > 0 && d.Close < d.PreClose
|
return d.PreClose > 0 && d.Close < d.PreClose
|
||||||
}
|
}
|
||||||
|
|
||||||
// PctChangeFromPre 由昨收计算的涨跌幅(%);昨收无效时返回 0。
|
// PctChangeFromPre 由昨收计算的涨跌幅(%);昨收无效时返回 0。
|
||||||
func (d *DatasetStockDaily) PctChangeFromPre() float64 {
|
func (d *DatasetDaily) PctChangeFromPre() float64 {
|
||||||
if d.PreClose <= 0 {
|
if d.PreClose <= 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ func (d *DatasetStockDaily) PctChangeFromPre() float64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AmplitudePct 振幅(相对昨收,%):(最高-最低)/昨收*100。
|
// AmplitudePct 振幅(相对昨收,%):(最高-最低)/昨收*100。
|
||||||
func (d *DatasetStockDaily) AmplitudePct() float64 {
|
func (d *DatasetDaily) AmplitudePct() float64 {
|
||||||
if d.PreClose <= 0 {
|
if d.PreClose <= 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DatasetStockFinaIndicator 财务指标模型
|
// DatasetFinaIndicator 财务指标模型
|
||||||
type DatasetStockFinaIndicator struct {
|
type DatasetFinaIndicator struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
TsCode string `gorm:"type:varchar(20);not null;index:fi_ts_code;uniqueIndex:un_fi_code_date;comment:TS代码"`
|
TsCode string `gorm:"type:varchar(20);not null;index:fi_ts_code;uniqueIndex:un_fi_code_date;comment:TS代码"`
|
||||||
Period int `gorm:"index:idx_period;uniqueIndex:un_fi_code_date;comment:报告期数"`
|
Period int `gorm:"index:idx_period;uniqueIndex:un_fi_code_date;comment:报告期数"`
|
||||||
@@ -205,12 +205,12 @@ type DatasetStockFinaIndicator struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TableName 设置表名
|
// TableName 设置表名
|
||||||
func (DatasetStockFinaIndicator) TableName() string {
|
func (DatasetFinaIndicator) TableName() string {
|
||||||
return "dataset_fina_indicator"
|
return "dataset_fina_indicator"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key 与表 uniqueIndex un_fi_code_date 一致:ts_code + period。
|
// Key 与表 uniqueIndex un_fi_code_date 一致:ts_code + period。
|
||||||
func (f *DatasetStockFinaIndicator) Key() string {
|
func (f *DatasetFinaIndicator) Key() string {
|
||||||
if f.TsCode == "" && f.Period == 0 {
|
if f.TsCode == "" && f.Period == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ func (f *DatasetStockFinaIndicator) Key() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RowLabel 便于日志/调试:ts_code + 报告期 end_date + 公告 ann_date。
|
// RowLabel 便于日志/调试:ts_code + 报告期 end_date + 公告 ann_date。
|
||||||
func (f *DatasetStockFinaIndicator) RowLabel() string {
|
func (f *DatasetFinaIndicator) RowLabel() string {
|
||||||
if f.EndDate != "" || f.AnnDate != "" {
|
if f.EndDate != "" || f.AnnDate != "" {
|
||||||
return f.TsCode + " end=" + f.EndDate + " ann=" + f.AnnDate
|
return f.TsCode + " end=" + f.EndDate + " ann=" + f.AnnDate
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package schema
|
|||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
// DatasetStockIndicator 每日基本面指标(采用 dataset/stock 的 decimal 定义,与采集端迁移一致)。
|
// DatasetIndicator 每日基本面指标(采用 dataset/stock 的 decimal 定义,与采集端迁移一致)。
|
||||||
type DatasetStockIndicator struct {
|
type DatasetIndicator struct {
|
||||||
ID uint `gorm:"primarykey;autoIncrement"`
|
ID uint `gorm:"primarykey;autoIncrement"`
|
||||||
TsCode string `gorm:"type:varchar(20);not null;index:si_ts_code;uniqueIndex:un_si_code_date;comment:股票代码" json:"ts_code"`
|
TsCode string `gorm:"type:varchar(20);not null;index:si_ts_code;uniqueIndex:un_si_code_date;comment:股票代码" json:"ts_code"`
|
||||||
TradeDate int `gorm:"index:si_trade_date;uniqueIndex:un_si_code_date;comment:交易日期" json:"trade_date"`
|
TradeDate int `gorm:"index:si_trade_date;uniqueIndex:un_si_code_date;comment:交易日期" json:"trade_date"`
|
||||||
@@ -26,12 +26,12 @@ type DatasetStockIndicator struct {
|
|||||||
Roe float64 `gorm:"type:decimal(20,4);comment:ROE(%) 净利润/股本"`
|
Roe float64 `gorm:"type:decimal(20,4);comment:ROE(%) 净利润/股本"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (DatasetStockIndicator) TableName() string {
|
func (DatasetIndicator) TableName() string {
|
||||||
return "dataset_stock_indicator"
|
return "dataset_indicator"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key 业务主键:ts_code + 交易日。
|
// Key 业务主键:ts_code + 交易日。
|
||||||
func (s *DatasetStockIndicator) Key() string {
|
func (s *DatasetIndicator) Key() string {
|
||||||
if s.TsCode == "" && s.TradeDate == 0 {
|
if s.TsCode == "" && s.TradeDate == 0 {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -39,11 +39,11 @@ func (s *DatasetStockIndicator) Key() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// HasTotalMV 总市值是否已填充(大于 0)。
|
// HasTotalMV 总市值是否已填充(大于 0)。
|
||||||
func (s *DatasetStockIndicator) HasTotalMV() bool {
|
func (s *DatasetIndicator) HasTotalMV() bool {
|
||||||
return s.TotalMv > 0
|
return s.TotalMv > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasCircMV 流通市值是否已填充。
|
// HasCircMV 流通市值是否已填充。
|
||||||
func (s *DatasetStockIndicator) HasCircMV() bool {
|
func (s *DatasetIndicator) HasCircMV() bool {
|
||||||
return s.CircMv > 0
|
return s.CircMv > 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,18 @@ package schema
|
|||||||
|
|
||||||
import "git.apinb.com/bsm-sdk/core/database"
|
import "git.apinb.com/bsm-sdk/core/database"
|
||||||
|
|
||||||
// RegisterAutoMigrate 将本包内与 stock/gostock 共用的表注册到 bsm-sdk 的迁移列表(可选;也可在各应用 init 中自行 AppendMigrate)。
|
// RegisterAutoMigrate 共用的表注册到 bsm-sdk 的迁移列表(可选;也可在各应用 init 中自行 AppendMigrate)。
|
||||||
func RegisterAutoMigrate() {
|
func RegisterAutoMigrate() {
|
||||||
for _, t := range []any{
|
for _, t := range []any{
|
||||||
&DatasetStockBasic{},
|
&DatasetBasic{},
|
||||||
&DatasetStockDaily{},
|
&DatasetDaily{},
|
||||||
&DatasetBlocksIndex{},
|
&DatasetBlocksIndex{},
|
||||||
&DatasetBlocksMember{},
|
&DatasetBlocksMember{},
|
||||||
&DatasetMoneyTotal{},
|
&DatasetMoneyTotal{},
|
||||||
&DatasetPledgeStat{},
|
&DatasetPledgeStat{},
|
||||||
&DatasetStockIndicator{},
|
&DatasetIndicator{},
|
||||||
&DatasetIndicatorPro{},
|
&DatasetIndicatorPro{},
|
||||||
&DatasetStockFinaIndicator{},
|
&DatasetFinaIndicator{},
|
||||||
} {
|
} {
|
||||||
database.AppendMigrate(t)
|
database.AppendMigrate(t)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user