ok
This commit is contained in:
28
schema/blocks_index.go
Normal file
28
schema/blocks_index.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package schema
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// BlocksIndex 板块索引(采用 dataset/stock 的 code 唯一约束)。
|
||||
type BlocksIndex struct {
|
||||
gorm.Model
|
||||
Code string `gorm:"type:varchar(50);not null;default:'';comment:板块代码;uniqueIndex:uq_blocks_index_code" json:"code"`
|
||||
Name string `gorm:"type:varchar(50);not null;default:'';comment:板块名称" json:"name"`
|
||||
IsRecommend bool `gorm:"type:bool;not null;default:false;comment:是否推荐" json:"is_recommend"`
|
||||
}
|
||||
|
||||
func (BlocksIndex) TableName() string {
|
||||
return "blocks_index"
|
||||
}
|
||||
|
||||
// Key 板块业务主键:code。
|
||||
func (b *BlocksIndex) Key() string {
|
||||
return b.Code
|
||||
}
|
||||
|
||||
// DisplayName 展示名称:非空 name,否则回退 code。
|
||||
func (b *BlocksIndex) DisplayName() string {
|
||||
if b.Name != "" {
|
||||
return b.Name
|
||||
}
|
||||
return b.Code
|
||||
}
|
||||
28
schema/blocks_member.go
Normal file
28
schema/blocks_member.go
Normal file
@@ -0,0 +1,28 @@
|
||||
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
|
||||
}
|
||||
31
schema/money_total.go
Normal file
31
schema/money_total.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package schema
|
||||
|
||||
// MoneyTotal 资金流汇总(采用 dataset/stock 的索引定义)。
|
||||
type MoneyTotal struct {
|
||||
ID uint `gorm:"primarykey"`
|
||||
Code string `gorm:"type:varchar(20);not null;uniqueIndex:uq_money_total_code"`
|
||||
Last1DayMfAmount float64
|
||||
Last3DayMfAmount float64
|
||||
Last1DayTotalAmount float64
|
||||
Last3DayTotalAmount float64
|
||||
IsGreaterPervious bool
|
||||
}
|
||||
|
||||
func (MoneyTotal) TableName() string {
|
||||
return "money_total"
|
||||
}
|
||||
|
||||
// Key 与唯一索引 uq_money_total_code 一致。
|
||||
func (m *MoneyTotal) Key() string {
|
||||
return m.Code
|
||||
}
|
||||
|
||||
// NetFlow1Day 最近 1 日主力净流入(万元),与字段语义一致。
|
||||
func (m *MoneyTotal) NetFlow1Day() float64 {
|
||||
return m.Last1DayMfAmount
|
||||
}
|
||||
|
||||
// NetFlow3Day 最近 3 日主力净流入(万元)。
|
||||
func (m *MoneyTotal) NetFlow3Day() float64 {
|
||||
return m.Last3DayMfAmount
|
||||
}
|
||||
30
schema/pledge_stat.go
Normal file
30
schema/pledge_stat.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package schema
|
||||
|
||||
// PledgeStat 股权质押统计(表 pledge_stat;dataset/stock 中原为 PledgeStatModel,业务层 Save 请留在各应用内)。
|
||||
type PledgeStat struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
TsCode string `gorm:"type:varchar(50);not null;default:'';comment:股票代码;uniqueIndex:uq_pledge_stat_ts_code" json:"ts_code"`
|
||||
EndDate int `gorm:"type:int;not null;default:0;comment:截止日期" json:"end_date"`
|
||||
PledgeCount float64 `json:"pledge_count"`
|
||||
UnrestPledge float64 `json:"unrest_pledge"`
|
||||
RestPledge float64 `json:"rest_pledge"`
|
||||
TotalShare float64 `json:"total_share"`
|
||||
PledgeRatio float64 `json:"pledge_ratio"`
|
||||
}
|
||||
|
||||
func (PledgeStat) TableName() string {
|
||||
return "pledge_stat"
|
||||
}
|
||||
|
||||
// Key 与唯一约束 uq_pledge_stat_ts_code 一致:ts_code。
|
||||
func (p *PledgeStat) Key() string {
|
||||
return p.TsCode
|
||||
}
|
||||
|
||||
// HasPledgeFacts 是否具备任一质押统计字段(比例、次数或股本)。
|
||||
func (p *PledgeStat) HasPledgeFacts() bool {
|
||||
return p.PledgeRatio > 0 || p.PledgeCount > 0 || p.TotalShare > 0
|
||||
}
|
||||
|
||||
// PledgeStatModel 兼容 dataset/stock 中的类型名。
|
||||
type PledgeStatModel = PledgeStat
|
||||
19
schema/register.go
Normal file
19
schema/register.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package schema
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/database"
|
||||
|
||||
// RegisterAutoMigrate 将本包内与 stock/gostock 共用的表注册到 bsm-sdk 的迁移列表(可选;也可在各应用 init 中自行 AppendMigrate)。
|
||||
func RegisterAutoMigrate() {
|
||||
for _, t := range []any{
|
||||
&StockBasic{},
|
||||
&StockDaily{},
|
||||
&BlocksIndex{},
|
||||
&BlocksMember{},
|
||||
&MoneyTotal{},
|
||||
&PledgeStat{},
|
||||
&StockIndicator{},
|
||||
&StockFinaIndicator{},
|
||||
} {
|
||||
database.AppendMigrate(t)
|
||||
}
|
||||
}
|
||||
107
schema/scopes.go
Normal file
107
schema/scopes.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package schema
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// ScopeTsCode 按 ts_code 精确过滤;空字符串则不加条件。
|
||||
func ScopeTsCode(tsCode string) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if tsCode == "" {
|
||||
return db
|
||||
}
|
||||
return db.Where("ts_code = ?", tsCode)
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeTsCodes 按 ts_code IN (...);nil 或空切片不加条件。
|
||||
func ScopeTsCodes(tsCodes []string) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if len(tsCodes) == 0 {
|
||||
return db
|
||||
}
|
||||
return db.Where("ts_code IN ?", tsCodes)
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeTradeDateEQ 按 trade_date 等于;0 表示不加条件。
|
||||
func ScopeTradeDateEQ(tradeDate int) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if tradeDate == 0 {
|
||||
return db
|
||||
}
|
||||
return db.Where("trade_date = ?", tradeDate)
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeTradeDateBetween trade_date 区间 [start,end];仅传一侧时做单边约束;均为 0 不加条件。
|
||||
func ScopeTradeDateBetween(start, end int) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
switch {
|
||||
case start > 0 && end > 0:
|
||||
return db.Where("trade_date BETWEEN ? AND ?", start, end)
|
||||
case start > 0:
|
||||
return db.Where("trade_date >= ?", start)
|
||||
case end > 0:
|
||||
return db.Where("trade_date <= ?", end)
|
||||
default:
|
||||
return db
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeStockDailyTsDate 日线:ts_code + 交易日(任一为空则该项不限制)。
|
||||
func ScopeStockDailyTsDate(tsCode string, tradeDate int) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Scopes(ScopeTsCode(tsCode), ScopeTradeDateEQ(tradeDate))
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeStockIndicatorTsDate 指标表:ts_code + trade_date。
|
||||
func ScopeStockIndicatorTsDate(tsCode string, tradeDate int) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
return db.Scopes(ScopeTsCode(tsCode), ScopeTradeDateEQ(tradeDate))
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeFinaTsPeriod 财务指标:ts_code + period(与 uniqueIndex un_fi_code_date 一致);period 为 0 时不限制 period。
|
||||
func ScopeFinaTsPeriod(tsCode string, period int) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
db = db.Scopes(ScopeTsCode(tsCode))
|
||||
if period != 0 {
|
||||
db = db.Where("period = ?", period)
|
||||
}
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeBlocksIndexCode 板块 code。
|
||||
func ScopeBlocksIndexCode(code string) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if code == "" {
|
||||
return db
|
||||
}
|
||||
return db.Where("code = ?", code)
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeBlocksMemberPair 板块 ti_code + 成分 stock_code。
|
||||
func ScopeBlocksMemberPair(tiCode, stockCode string) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if tiCode != "" {
|
||||
db = db.Where("ti_code = ?", tiCode)
|
||||
}
|
||||
if stockCode != "" {
|
||||
db = db.Where("stock_code = ?", stockCode)
|
||||
}
|
||||
return db
|
||||
}
|
||||
}
|
||||
|
||||
// ScopeMoneyTotalCode 资金流 code。
|
||||
func ScopeMoneyTotalCode(code string) func(*gorm.DB) *gorm.DB {
|
||||
return func(db *gorm.DB) *gorm.DB {
|
||||
if code == "" {
|
||||
return db
|
||||
}
|
||||
return db.Where("code = ?", code)
|
||||
}
|
||||
}
|
||||
44
schema/stock_basic.go
Normal file
44
schema/stock_basic.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package schema
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
// StockBasic 股票基本信息表(合并 dataset/stock 与 gostock 字段;gostock 独有 Level、Desc)。
|
||||
type StockBasic struct {
|
||||
gorm.Model
|
||||
TsCode string `gorm:"type:varchar(50);not null;index;comment:TS代码"`
|
||||
Symbol string `gorm:"type:varchar(50);not null;comment:股票代码"`
|
||||
Name string `gorm:"type:varchar(50);not null;comment:股票名称"`
|
||||
Area string `gorm:"type:varchar(50);not null;default:'';comment:地域"`
|
||||
Industry string `gorm:"type:varchar(50);not null;default:'';comment:所属行业"`
|
||||
FullName string `gorm:"type:varchar(500);comment:股票全称"`
|
||||
EnName string `gorm:"type:varchar(200);comment:英文全称"`
|
||||
CnSpell string `gorm:"type:varchar(50);not null;default:'';comment:拼音缩写"`
|
||||
Market string `gorm:"type:varchar(50);not null;comment:市场类型(主板/创业板/科创板/CDR)"`
|
||||
Exchange string `gorm:"type:varchar(50);comment:交易所代码"`
|
||||
ListDate string `gorm:"type:varchar(50);not null;comment:上市日期"`
|
||||
IsHS string `gorm:"type:varchar(2);default:'N';comment:是否沪深港通标的,N否 H沪股通 S深股通"`
|
||||
ActName string `gorm:"type:varchar(500);not null;default:'';comment:实控人名称"`
|
||||
ActEntType string `gorm:"type:varchar(50);not null;default:'';comment:实控人企业性质"`
|
||||
}
|
||||
|
||||
func (StockBasic) TableName() string {
|
||||
return "stock_basic"
|
||||
}
|
||||
|
||||
// Key 业务主键:TS 代码。
|
||||
func (s *StockBasic) Key() string {
|
||||
return s.TsCode
|
||||
}
|
||||
|
||||
// DisplaySymbol 展示用代码:有 symbol 用 symbol,否则用 ts_code。
|
||||
func (s *StockBasic) DisplaySymbol() string {
|
||||
if s.Symbol != "" {
|
||||
return s.Symbol
|
||||
}
|
||||
return s.TsCode
|
||||
}
|
||||
|
||||
// IsNorthbound 是否沪深港通标的(H 沪股通 / S 深股通)。
|
||||
func (s *StockBasic) IsNorthbound() bool {
|
||||
return s.IsHS == "H" || s.IsHS == "S"
|
||||
}
|
||||
58
schema/stock_daily.go
Normal file
58
schema/stock_daily.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package schema
|
||||
|
||||
import "strconv"
|
||||
|
||||
// StockDaily 股票日线数据(两仓库结构一致)。
|
||||
type StockDaily struct {
|
||||
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"`
|
||||
TradeDate int `gorm:"index:idx_trade_date;uniqueIndex:un_code_date;comment:交易日期" json:"trade_date"`
|
||||
Open float64 `gorm:"type:decimal(10,4);comment:开盘价" json:"open"`
|
||||
High float64 `gorm:"type:decimal(10,4);comment:最高价" json:"high"`
|
||||
Low float64 `gorm:"type:decimal(10,4);comment:最低价" json:"low"`
|
||||
Close float64 `gorm:"type:decimal(10,4);comment:收盘价" json:"close"`
|
||||
PreClose float64 `gorm:"type:decimal(10,4);comment:昨收价(除权价)" json:"pre_close"`
|
||||
Change float64 `gorm:"type:decimal(10,4);comment:涨跌额" json:"change"`
|
||||
PctChg float64 `gorm:"type:decimal(10,6);comment:涨跌幅(%)" json:"pct_chg"`
|
||||
DayChg float64 `gorm:"type:decimal(6,2);comment:日均振幅(%)" json:"day_chg"`
|
||||
Vol float64 `gorm:"type:decimal(15,2);comment:成交量(手)" json:"vol"`
|
||||
Amount float64 `gorm:"type:decimal(20,2);comment:成交额(千元)" json:"amount"`
|
||||
}
|
||||
|
||||
func (StockDaily) TableName() string {
|
||||
return "stock_daily"
|
||||
}
|
||||
|
||||
// Key 业务主键:ts_code + 交易日。
|
||||
func (d *StockDaily) Key() string {
|
||||
if d.TsCode == "" && d.TradeDate == 0 {
|
||||
return ""
|
||||
}
|
||||
return d.TsCode + "#" + strconv.Itoa(d.TradeDate)
|
||||
}
|
||||
|
||||
// IsRising 是否收涨(昨收有效且收盘高于昨收)。
|
||||
func (d *StockDaily) IsRising() bool {
|
||||
return d.PreClose > 0 && d.Close > d.PreClose
|
||||
}
|
||||
|
||||
// IsFalling 是否收跌。
|
||||
func (d *StockDaily) IsFalling() bool {
|
||||
return d.PreClose > 0 && d.Close < d.PreClose
|
||||
}
|
||||
|
||||
// PctChangeFromPre 由昨收计算的涨跌幅(%);昨收无效时返回 0。
|
||||
func (d *StockDaily) PctChangeFromPre() float64 {
|
||||
if d.PreClose <= 0 {
|
||||
return 0
|
||||
}
|
||||
return (d.Close - d.PreClose) / d.PreClose * 100
|
||||
}
|
||||
|
||||
// AmplitudePct 振幅(相对昨收,%):(最高-最低)/昨收*100。
|
||||
func (d *StockDaily) AmplitudePct() float64 {
|
||||
if d.PreClose <= 0 {
|
||||
return 0
|
||||
}
|
||||
return (d.High - d.Low) / d.PreClose * 100
|
||||
}
|
||||
226
schema/stock_fina_indicator.go
Normal file
226
schema/stock_fina_indicator.go
Normal file
@@ -0,0 +1,226 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// StockFinaIndicator 财务指标模型
|
||||
type StockFinaIndicator struct {
|
||||
gorm.Model
|
||||
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:报告期数"`
|
||||
AnnDate string `gorm:"index:idx_ann_date;comment:公告日期"`
|
||||
EndDate string `gorm:"index:idx_end_date;comment:报告期"`
|
||||
|
||||
// 每股指标
|
||||
Eps float64 `gorm:"type:decimal(20,4);comment:基本每股收益"`
|
||||
DtEps float64 `gorm:"type:decimal(20,4);comment:稀释每股收益"`
|
||||
TotalRevenuePs float64 `gorm:"type:decimal(20,4);comment:每股营业总收入"`
|
||||
RevenuePs float64 `gorm:"type:decimal(20,4);comment:每股营业收入"`
|
||||
CapitalResePs float64 `gorm:"type:decimal(20,4);comment:每股资本公积"`
|
||||
SurplusResePs float64 `gorm:"type:decimal(20,4);comment:每股盈余公积"`
|
||||
UndistProfitPs float64 `gorm:"type:decimal(20,4);comment:每股未分配利润"`
|
||||
Diluted2Eps float64 `gorm:"type:decimal(20,4);comment:期末摊薄每股收益"`
|
||||
Bps float64 `gorm:"type:decimal(20,4);comment:每股净资产"`
|
||||
Ocfps float64 `gorm:"type:decimal(20,4);comment:每股经营活动产生的现金流量净额"`
|
||||
Retainedps float64 `gorm:"type:decimal(20,4);comment:每股留存收益"`
|
||||
Cfps float64 `gorm:"type:decimal(20,4);comment:每股现金流量净额"`
|
||||
EbitPs float64 `gorm:"type:decimal(20,4);comment:每股息税前利润"`
|
||||
FcffPs float64 `gorm:"type:decimal(20,4);comment:每股企业自由现金流量"`
|
||||
FcfePs float64 `gorm:"type:decimal(20,4);comment:每股股东自由现金流量"`
|
||||
|
||||
// 利润表相关
|
||||
ExtraItem float64 `gorm:"type:decimal(20,4);comment:非经常性损益"`
|
||||
ProfitDedt float64 `gorm:"type:decimal(20,4);comment:扣除非经常性损益后的净利润"`
|
||||
GrossMargin float64 `gorm:"type:decimal(20,4);comment:毛利"`
|
||||
OpIncome float64 `gorm:"type:decimal(20,4);comment:经营活动净收益"`
|
||||
ValuechangeIncome float64 `gorm:"type:decimal(20,4);comment:价值变动净收益"`
|
||||
InterstIncome float64 `gorm:"type:decimal(20,4);comment:利息费用"`
|
||||
Daa float64 `gorm:"type:decimal(20,4);comment:折旧与摊销"`
|
||||
Ebit float64 `gorm:"type:decimal(20,4);comment:息税前利润"`
|
||||
Ebitda float64 `gorm:"type:decimal(20,4);comment:息税折旧摊销前利润"`
|
||||
Fcff float64 `gorm:"type:decimal(20,4);comment:企业自由现金流量"`
|
||||
Fcfe float64 `gorm:"type:decimal(20,4);comment:股权自由现金流量"`
|
||||
RdExp float64 `gorm:"type:decimal(20,4);comment:研发费用"`
|
||||
FixedAssets float64 `gorm:"type:decimal(20,4);comment:固定资产合计"`
|
||||
ProfitPrefinExp float64 `gorm:"type:decimal(20,4);comment:扣除财务费用前营业利润"`
|
||||
NonOpProfit float64 `gorm:"type:decimal(20,4);comment:非营业利润"`
|
||||
|
||||
// 资产负债表相关
|
||||
CurrentExint float64 `gorm:"type:decimal(20,4);comment:无息流动负债"`
|
||||
NoncurrentExint float64 `gorm:"type:decimal(20,4);comment:无息非流动负债"`
|
||||
Interestdebt float64 `gorm:"type:decimal(20,4);comment:带息债务"`
|
||||
Netdebt float64 `gorm:"type:decimal(20,4);comment:净债务"`
|
||||
TangibleAsset float64 `gorm:"type:decimal(20,4);comment:有形资产"`
|
||||
WorkingCapital float64 `gorm:"type:decimal(20,4);comment:营运资金"`
|
||||
NetworkingCapital float64 `gorm:"type:decimal(20,4);comment:营运流动资本"`
|
||||
InvestCapital float64 `gorm:"type:decimal(20,4);comment:全部投入资本"`
|
||||
RetainedEarnings float64 `gorm:"type:decimal(20,4);comment:留存收益"`
|
||||
|
||||
// 偿债能力指标
|
||||
CurrentRatio float64 `gorm:"type:decimal(20,4);comment:流动比率"`
|
||||
QuickRatio float64 `gorm:"type:decimal(20,4);comment:速动比率"`
|
||||
CashRatio float64 `gorm:"type:decimal(20,4);comment:保守速动比率"`
|
||||
DebtToAssets float64 `gorm:"type:decimal(20,4);comment:资产负债率"`
|
||||
AssetsToEqt float64 `gorm:"type:decimal(20,4);comment:权益乘数"`
|
||||
DpAssetsToEqt float64 `gorm:"type:decimal(20,4);comment:权益乘数(杜邦分析)"`
|
||||
DebtToEqt float64 `gorm:"type:decimal(20,4);comment:产权比率"`
|
||||
EqtToDebt float64 `gorm:"type:decimal(20,4);comment:归属于母公司的股东权益/负债合计"`
|
||||
OcfToShortdebt float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/流动负债"`
|
||||
EbitToInterest float64 `gorm:"type:decimal(20,4);comment:已获利息倍数"`
|
||||
|
||||
// 运营能力指标
|
||||
InvturnDays float64 `gorm:"type:decimal(20,4);comment:存货周转天数"`
|
||||
ArturnDays float64 `gorm:"type:decimal(20,4);comment:应收账款周转天数"`
|
||||
InvTurn float64 `gorm:"type:decimal(20,4);comment:存货周转率"`
|
||||
ArTurn float64 `gorm:"type:decimal(20,4);comment:应收账款周转率"`
|
||||
CaTurn float64 `gorm:"type:decimal(20,4);comment:流动资产周转率"`
|
||||
FaTurn float64 `gorm:"type:decimal(20,4);comment:固定资产周转率"`
|
||||
AssetsTurn float64 `gorm:"type:decimal(20,4);comment:总资产周转率"`
|
||||
TurnDays float64 `gorm:"type:decimal(20,4);comment:营业周期"`
|
||||
TotalFaTrun float64 `gorm:"type:decimal(20,4);comment:固定资产合计周转率"`
|
||||
|
||||
// 盈利能力指标
|
||||
NetprofitMargin float64 `gorm:"type:decimal(20,4);comment:销售净利率"`
|
||||
GrossprofitMargin float64 `gorm:"type:decimal(20,4);comment:销售毛利率"`
|
||||
CogsOfSales float64 `gorm:"type:decimal(20,4);comment:销售成本率"`
|
||||
ExpenseOfSales float64 `gorm:"type:decimal(20,4);comment:销售期间费用率"`
|
||||
Roe float64 `gorm:"type:decimal(20,4);comment:净资产收益率"`
|
||||
RoeWaa float64 `gorm:"type:decimal(20,4);comment:加权平均净资产收益率"`
|
||||
RoeDt float64 `gorm:"type:decimal(20,4);comment:净资产收益率(扣除非经常损益)"`
|
||||
Roa float64 `gorm:"type:decimal(20,4);comment:总资产报酬率"`
|
||||
Npta float64 `gorm:"type:decimal(20,4);comment:总资产净利润"`
|
||||
Roic float64 `gorm:"type:decimal(20,4);comment:投入资本回报率"`
|
||||
RoaDp float64 `gorm:"type:decimal(20,4);comment:总资产净利率(杜邦分析)"`
|
||||
|
||||
// 结构指标
|
||||
CaToAssets float64 `gorm:"type:decimal(20,4);comment:流动资产/总资产"`
|
||||
NcaToAssets float64 `gorm:"type:decimal(20,4);comment:非流动资产/总资产"`
|
||||
TbassetsToTotalassets float64 `gorm:"type:decimal(20,4);comment:有形资产/总资产"`
|
||||
IntToTalcap float64 `gorm:"type:decimal(20,4);comment:带息债务/全部投入资本"`
|
||||
EqtToTalcapital float64 `gorm:"type:decimal(20,4);comment:归属于母公司的股东权益/全部投入资本"`
|
||||
CurrentdebtToDebt float64 `gorm:"type:decimal(20,4);comment:流动负债/负债合计"`
|
||||
LongdebToDebt float64 `gorm:"type:decimal(20,4);comment:非流动负债/负债合计"`
|
||||
TangibleassetToDebt float64 `gorm:"type:decimal(20,4);comment:有形资产/负债合计"`
|
||||
|
||||
// 单季度指标
|
||||
QOpincome float64 `gorm:"type:decimal(20,4);comment:经营活动单季度净收益"`
|
||||
QInvestincome float64 `gorm:"type:decimal(20,4);comment:价值变动单季度净收益"`
|
||||
QDtprofit float64 `gorm:"type:decimal(20,4);comment:扣除非经常损益后的单季度净利润"`
|
||||
QEps float64 `gorm:"type:decimal(20,4);comment:每股收益(单季度)"`
|
||||
QNetprofitMargin float64 `gorm:"type:decimal(20,4);comment:销售净利率(单季度)"`
|
||||
QGscaleprofitMargin float64 `gorm:"type:decimal(20,4);comment:销售毛利率(单季度)"`
|
||||
QExpToSales float64 `gorm:"type:decimal(20,4);comment:销售期间费用率(单季度)"`
|
||||
QRoe float64 `gorm:"type:decimal(20,4);comment:净资产收益率(单季度)"`
|
||||
QDtRoe float64 `gorm:"type:decimal(20,4);comment:净资产单季度收益率(扣除非经常损益)"`
|
||||
QNpta float64 `gorm:"type:decimal(20,4);comment:总资产净利润(单季度)"`
|
||||
|
||||
// 同比增长率
|
||||
BasicEpsYoy float64 `gorm:"type:decimal(20,4);comment:基本每股收益同比增长率(%)"`
|
||||
DtEpsYoy float64 `gorm:"type:decimal(20,4);comment:稀释每股收益同比增长率(%)"`
|
||||
CfpsYoy float64 `gorm:"type:decimal(20,4);comment:每股经营活动产生的现金流量净额同比增长率(%)"`
|
||||
OpYoy float64 `gorm:"type:decimal(20,4);comment:营业利润同比增长率(%)"`
|
||||
EbtYoy float64 `gorm:"type:decimal(20,4);comment:利润总额同比增长率(%)"`
|
||||
NetprofitYoy float64 `gorm:"type:decimal(20,4);comment:归属母公司股东的净利润同比增长率(%)"`
|
||||
DtNetprofitYoy float64 `gorm:"type:decimal(20,4);comment:归属母公司股东的净利润-扣除非经常损益同比增长率(%)"`
|
||||
OcfYoy float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额同比增长率(%)"`
|
||||
RoeYoy float64 `gorm:"type:decimal(20,4);comment:净资产收益率(摊薄)同比增长率(%)"`
|
||||
BpsYoy float64 `gorm:"type:decimal(20,4);comment:每股净资产相对年初增长率(%)"`
|
||||
AssetsYoy float64 `gorm:"type:decimal(20,4);comment:资产总计相对年初增长率(%)"`
|
||||
EqtYoy float64 `gorm:"type:decimal(20,4);comment:归属母公司的股东权益相对年初增长率(%)"`
|
||||
TrYoy float64 `gorm:"type:decimal(20,4);comment:营业总收入同比增长率(%)"`
|
||||
OrYoy float64 `gorm:"type:decimal(20,4);comment:营业收入同比增长率(%)"`
|
||||
EquityYoy float64 `gorm:"type:decimal(20,4);comment:净资产同比增长率"`
|
||||
|
||||
// 其他比率指标
|
||||
ProfitToGr float64 `gorm:"type:decimal(20,4);comment:净利润/营业总收入"`
|
||||
SaleexpToGr float64 `gorm:"type:decimal(20,4);comment:销售费用/营业总收入"`
|
||||
AdminexpOfGr float64 `gorm:"type:decimal(20,4);comment:管理费用/营业总收入"`
|
||||
FinaexpOfGr float64 `gorm:"type:decimal(20,4);comment:财务费用/营业总收入"`
|
||||
ImpaiTtm float64 `gorm:"type:decimal(20,4);comment:资产减值损失/营业总收入"`
|
||||
GcOfGr float64 `gorm:"type:decimal(20,4);comment:营业总成本/营业总收入"`
|
||||
OpOfGr float64 `gorm:"type:decimal(20,4);comment:营业利润/营业总收入"`
|
||||
EbitOfGr float64 `gorm:"type:decimal(20,4);comment:息税前利润/营业总收入"`
|
||||
OpincomeOfEbt float64 `gorm:"type:decimal(20,4);comment:经营活动净收益/利润总额"`
|
||||
InvestincomeOfEbt float64 `gorm:"type:decimal(20,4);comment:价值变动净收益/利润总额"`
|
||||
NOpProfitOfEbt float64 `gorm:"type:decimal(20,4);comment:营业外收支净额/利润总额"`
|
||||
TaxToEbt float64 `gorm:"type:decimal(20,4);comment:所得税/利润总额"`
|
||||
DtprofitToProfit float64 `gorm:"type:decimal(20,4);comment:扣除非经常损益后的净利润/净利润"`
|
||||
SalescashToOr float64 `gorm:"type:decimal(20,4);comment:销售商品提供劳务收到的现金/营业收入"`
|
||||
OcfToOr float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/营业收入"`
|
||||
OcfToOpincome float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/经营活动净收益"`
|
||||
CapitalizedToDa float64 `gorm:"type:decimal(20,4);comment:资本支出/折旧和摊销"`
|
||||
OcfToDebt float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/负债合计"`
|
||||
OcfToInterestdebt float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/带息债务"`
|
||||
OcfToNetdebt float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/净债务"`
|
||||
LongdebtToWorkingcapital float64 `gorm:"type:decimal(20,4);comment:长期债务与营运资金比率"`
|
||||
EbitdaToDebt float64 `gorm:"type:decimal(20,4);comment:息税折旧摊销前利润/负债合计"`
|
||||
OpToEbt float64 `gorm:"type:decimal(20,4);comment:营业利润/利润总额"`
|
||||
NopToEbt float64 `gorm:"type:decimal(20,4);comment:非营业利润/利润总额"`
|
||||
OcfToProfit float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/营业利润"`
|
||||
CashToLiqdebt float64 `gorm:"type:decimal(20,4);comment:货币资金/流动负债"`
|
||||
CashToLiqdebtWithinterest float64 `gorm:"type:decimal(20,4);comment:货币资金/带息流动负债"`
|
||||
OpToLiqdebt float64 `gorm:"type:decimal(20,4);comment:营业利润/流动负债"`
|
||||
OpToDebt float64 `gorm:"type:decimal(20,4);comment:营业利润/负债合计"`
|
||||
ProfitToOp float64 `gorm:"type:decimal(20,4);comment:利润总额/营业收入"`
|
||||
|
||||
// 年度化指标
|
||||
RoeYearly float64 `gorm:"type:decimal(20,4);comment:年化净资产收益率"`
|
||||
Roa2Yearly float64 `gorm:"type:decimal(20,4);comment:年化总资产报酬率"`
|
||||
RoaYearly float64 `gorm:"type:decimal(20,4);comment:年化总资产净利率"`
|
||||
RoicYearly float64 `gorm:"type:decimal(20,4);comment:年化投入资本回报率"`
|
||||
RoeAvg float64 `gorm:"type:decimal(20,4);comment:平均净资产收益率(增发条件)"`
|
||||
|
||||
// 单季度增长比率
|
||||
QGrYoy float64 `gorm:"type:decimal(20,4);comment:营业总收入同比增长率(%)(单季度)"`
|
||||
QGrQoq float64 `gorm:"type:decimal(20,4);comment:营业总收入环比增长率(%)(单季度)"`
|
||||
QSalesYoy float64 `gorm:"type:decimal(20,4);comment:营业收入同比增长率(%)(单季度)"`
|
||||
QSalesQoq float64 `gorm:"type:decimal(20,4);comment:营业收入环比增长率(%)(单季度)"`
|
||||
QOpYoy float64 `gorm:"type:decimal(20,4);comment:营业利润同比增长率(%)(单季度)"`
|
||||
QOpQoq float64 `gorm:"type:decimal(20,4);comment:营业利润环比增长率(%)(单季度)"`
|
||||
QProfitYoy float64 `gorm:"type:decimal(20,4);comment:净利润同比增长率(%)(单季度)"`
|
||||
QProfitQoq float64 `gorm:"type:decimal(20,4);comment:净利润环比增长率(%)(单季度)"`
|
||||
QNetprofitYoy float64 `gorm:"type:decimal(20,4);comment:归属母公司股东的净利润同比增长率(%)(单季度)"`
|
||||
QNetprofitQoq float64 `gorm:"type:decimal(20,4);comment:归属母公司股东的净利润环比增长率(%)(单季度)"`
|
||||
|
||||
// 单季度比率指标
|
||||
QProfitToGr float64 `gorm:"type:decimal(20,4);comment:净利润/营业总收入(单季度)"`
|
||||
QSaleexpToGr float64 `gorm:"type:decimal(20,4);comment:销售费用/营业总收入 (单季度)"`
|
||||
QAdminexpToGr float64 `gorm:"type:decimal(20,4);comment:管理费用/营业总收入 (单季度)"`
|
||||
QFinaexpToGr float64 `gorm:"type:decimal(20,4);comment:财务费用/营业总收入 (单季度)"`
|
||||
QImpairToGrTtm float64 `gorm:"type:decimal(20,4);comment:资产减值损失/营业总收入(单季度)"`
|
||||
QGcToGr float64 `gorm:"type:decimal(20,4);comment:营业总成本/营业总收入 (单季度)"`
|
||||
QOpToGr float64 `gorm:"type:decimal(20,4);comment:营业利润/营业总收入(单季度)"`
|
||||
QOpincomeToEbt float64 `gorm:"type:decimal(20,4);comment:经营活动净收益/利润总额(单季度)"`
|
||||
QInvestincomeToEbt float64 `gorm:"type:decimal(20,4);comment:价值变动净收益/利润总额(单季度)"`
|
||||
QDtprofitToProfit float64 `gorm:"type:decimal(20,4);comment:扣除非经常损益后的净利润/净利润(单季度)"`
|
||||
QSalescashToOr float64 `gorm:"type:decimal(20,4);comment:销售商品提供劳务收到的现金/营业收入(单季度)"`
|
||||
QOcfToSales float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/营业收入(单季度)"`
|
||||
QOcfToOr float64 `gorm:"type:decimal(20,4);comment:经营活动产生的现金流量净额/经营活动净收益(单季度)"`
|
||||
|
||||
// 其他
|
||||
UpdateFlag string `gorm:"type:varchar(1);comment:更新标识"`
|
||||
}
|
||||
|
||||
// TableName 设置表名
|
||||
func (StockFinaIndicator) TableName() string {
|
||||
return "fina_indicator"
|
||||
}
|
||||
|
||||
// Key 与表 uniqueIndex un_fi_code_date 一致:ts_code + period。
|
||||
func (f *StockFinaIndicator) Key() string {
|
||||
if f.TsCode == "" && f.Period == 0 {
|
||||
return ""
|
||||
}
|
||||
return f.TsCode + "#" + strconv.Itoa(f.Period)
|
||||
}
|
||||
|
||||
// RowLabel 便于日志/调试:ts_code + 报告期 end_date + 公告 ann_date。
|
||||
func (f *StockFinaIndicator) RowLabel() string {
|
||||
if f.EndDate != "" || f.AnnDate != "" {
|
||||
return f.TsCode + " end=" + f.EndDate + " ann=" + f.AnnDate
|
||||
}
|
||||
return f.Key()
|
||||
}
|
||||
49
schema/stock_indicator.go
Normal file
49
schema/stock_indicator.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package schema
|
||||
|
||||
import "strconv"
|
||||
|
||||
// StockIndicator 每日基本面指标(采用 dataset/stock 的 decimal 定义,与采集端迁移一致)。
|
||||
type StockIndicator struct {
|
||||
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"`
|
||||
TradeDate int `gorm:"index:si_trade_date;uniqueIndex:un_si_code_date;comment:交易日期" json:"trade_date"`
|
||||
Close float64 `gorm:"type:decimal(20,4);comment:当日收盘价"`
|
||||
TurnoverRate float64 `gorm:"type:decimal(20,4);comment:换手率(%)"`
|
||||
TurnoverRateF float64 `gorm:"type:decimal(20,4);comment:换手率(自由流通股)"`
|
||||
VolumeRatio float64 `gorm:"type:decimal(20,4);comment:量比"`
|
||||
Pe float64 `gorm:"type:decimal(20,4);comment:市盈率(总市值/净利润)"`
|
||||
PeTtm float64 `gorm:"type:decimal(20,4);comment:市盈率(TTM)"`
|
||||
Pb float64 `gorm:"type:decimal(20,4);comment:市净率"`
|
||||
Ps float64 `gorm:"type:decimal(20,4);comment:市销率"`
|
||||
PsTtm float64 `gorm:"type:decimal(20,4);comment:市销率(TTM)"`
|
||||
DvRatio float64 `gorm:"type:decimal(20,4);comment:股息率(%)"`
|
||||
DvTtm float64 `gorm:"type:decimal(20,4);comment:股息率(TTM)(%)"`
|
||||
TotalShare float64 `gorm:"type:decimal(20,4);comment:总股本(万股)"`
|
||||
FloatShare float64 `gorm:"type:decimal(20,4);comment:流通股本(万股)"`
|
||||
FreeShare float64 `gorm:"type:decimal(20,4);comment:自由流通股本(万)"`
|
||||
TotalMv float64 `gorm:"type:decimal(20,4);comment:总市值(万元)"`
|
||||
CircMv float64 `gorm:"type:decimal(20,4);comment:流通市值(万元)"`
|
||||
Roe float64 `gorm:"type:decimal(20,4);comment:ROE(%) 净利润/股本"`
|
||||
}
|
||||
|
||||
func (StockIndicator) TableName() string {
|
||||
return "stock_indicator"
|
||||
}
|
||||
|
||||
// Key 业务主键:ts_code + 交易日。
|
||||
func (s *StockIndicator) Key() string {
|
||||
if s.TsCode == "" && s.TradeDate == 0 {
|
||||
return ""
|
||||
}
|
||||
return s.TsCode + "#" + strconv.Itoa(s.TradeDate)
|
||||
}
|
||||
|
||||
// HasTotalMV 总市值是否已填充(大于 0)。
|
||||
func (s *StockIndicator) HasTotalMV() bool {
|
||||
return s.TotalMv > 0
|
||||
}
|
||||
|
||||
// HasCircMV 流通市值是否已填充。
|
||||
func (s *StockIndicator) HasCircMV() bool {
|
||||
return s.CircMv > 0
|
||||
}
|
||||
Reference in New Issue
Block a user