package models import ( "time" "gorm.io/gorm" ) // StockDailyQuote 存储每日行情快照(盘后同步)。 type StockDailyQuote struct { ID string `json:"id" gorm:"type:uuid;primaryKey;default:gen_random_uuid()"` Symbol string `json:"symbol" gorm:"size:32;not null;uniqueIndex:idx_stock_daily_symbol_date"` Name string `json:"name" gorm:"size:128"` TradeDate time.Time `json:"trade_date" gorm:"type:date;not null;uniqueIndex:idx_stock_daily_symbol_date"` Open float64 `json:"open"` High float64 `json:"high"` Low float64 `json:"low"` Close float64 `json:"close"` PrevClose float64 `json:"prev_close"` Volume int64 `json:"volume"` Amount float64 `json:"amount"` ChangePct float64 `json:"change_pct"` TurnoverRate float64 `json:"turnover_rate"` Region string `json:"region" gorm:"size:16"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } // StockSyncJob 记录每次盘后同步任务的状态。 type StockSyncJob struct { ID string `json:"id" gorm:"type:uuid;primaryKey;default:gen_random_uuid()"` JobDate time.Time `json:"job_date" gorm:"type:date;not null"` Status string `json:"status" gorm:"size:16;not null"` // running / success / failed RecordsCount int `json:"records_count"` StartedAt time.Time `json:"started_at"` FinishedAt *time.Time `json:"finished_at"` ErrorMessage string `json:"error_message"` TriggerBy string `json:"trigger_by" gorm:"size:16"` // schedule / manual } // AutoMigrateStock 迁移股票数据表。 func AutoMigrateStock(db *gorm.DB) error { return db.AutoMigrate(&StockDailyQuote{}, &StockSyncJob{}) }