Files
gostock/internal/models/strat_model.go
2026-02-24 16:29:28 +08:00

102 lines
2.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"strings"
"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
UpDateDay int //上市时间,天数
IndustryScore int // 行业分组
StScore int // 是否是ST
GtAmount int // 每日交易额大于设定值
GtPrice int // 最近20日交易日价格大于设定值
RoeScore int // ROE 是否大于设定值
ValRoe float64 // ROE 值
ScoreRsi int
RecommendDesc string // 推荐描述
Status int // 状态 -1:不推荐0:正常 1:推荐
// macd
MacdScore int
MacdVal float64
// 值
ValRsiOversold int
ValRsiPrve float64
ValRsiLast float64
//AI
AiSummary string
AiSummary2025 string
AiSummaryBase string
AiSummaryTech string
AiScore int
AiSupportLevel float64
AiResisLevel float64
AiAction string
AiRisk string
TotalDesc string
TotalScore float64 `gorm:"default:0"`
}
func init() {
database.AppendMigrate(&StratModel{})
}
// TableName 设置表名
func (StratModel) TableName() string {
return "strat_model"
}
var (
desc []string
)
func NewStratModel(key, code string, ymd int) *StratModel {
desc = []string{}
obj := StratModel{
StratKey: key,
Ymd: ymd,
Code: code,
}
return &obj
}
func (s *StratModel) AddDesc(d string) {
desc = append(desc, d)
}
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)
s.TotalDesc = strings.Join(desc, "||")
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)
}