From b4310c22cd03fccee390bba21054d15801a78af8 Mon Sep 17 00:00:00 2001 From: yanweidong Date: Sat, 31 Jan 2026 17:21:33 +0800 Subject: [PATCH] deving --- internal/models/strat_model.go | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 internal/models/strat_model.go diff --git a/internal/models/strat_model.go b/internal/models/strat_model.go new file mode 100644 index 0000000..e3accec --- /dev/null +++ b/internal/models/strat_model.go @@ -0,0 +1,64 @@ +package models + +import ( + "time" + + "git.apinb.com/bsm-sdk/core/database" + "git.apinb.com/bsm-sdk/core/utils" + "git.apinb.com/quant/gostock/internal/impl" + "gorm.io/gorm" +) + +// StartModel 策略模型 +type StratModel struct { + gorm.Model + StratKey string + Ymd int + Code string + UpDateMonth int //上市时间,月数 + IndustryScore int // 行业分组 + IsSt int + GtAmount int // 每日交易额大于设定值 + GtPrice int // 最近20日交易日价格大于设定值 + GtRoe int // ROE 是否大于设定值 + +} + +func init() { + database.AppendMigrate(&StratModel{}) +} + +// TableName 设置表名 +func (StratModel) TableName() string { + return "strat_model" +} + +func NewStratModel(key, code string) *StratModel { + obj := StratModel{ + StratKey: key, + Ymd: GetYmd(), + Code: code, + } + return &obj +} + +func (s *StratModel) Save() error { + var cnt int64 + impl.DBService.Model(&StratModel{}).Where("strat_key=? and ymd=? and code=?", s.StratKey, s.Ymd, s.Code).Count(&cnt) + + if cnt == 0 { + // create record. + return impl.DBService.Create(s).Error + } else { + // update record. + return impl.DBService.Model(&StratModel{}).Where("strat_key=? and ymd=? and code=?", s.StratKey, s.Ymd, s.Code).Updates(s).Error + } + + return nil + +} + +func GetYmd() int { + ymd := time.Now().Format("20060102") + return utils.String2Int(ymd) +}