package models import ( "github.com/beego/beego/v2/client/orm" "time" ) // BaseFromSci99Index 代表卓创资讯-原始指标表的结构 type BaseFromSci99Index struct { BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk"` // 主键,自动递增 IndexCode string // 指标编码 IndexName string // 指标名称 ClassifyId int // 分类Id Unit string // 单位 Frequency string // 频度 Describe string // 指标描述 CreateTime time.Time // 创建时间 ModifyTime time.Time // 修改时间 } // BaseFromSci99Data 代表卓创资讯-原始指标数据表的结构 type BaseFromSci99Data struct { BaseFromSciDataId int `orm:"column(base_from_sci_data_id);pk"` // 主键,自动递增 BaseFromSciIndexId int // 指标id IndexCode string // 指标编码 DataTime string // 数据日期 Value float64 // 数据值 CreateTime time.Time // 创建时间 ModifyTime time.Time // 修改时间 } // BaseFromSci99Classify 代表卓创资讯-原始指标分类表的结构 type BaseFromSci99Classify struct { BaseFromSciClassifyId int `orm:"column(base_from_sci_classify_id);pk"` // 主键,自动递增 ClassifyName string // 分类名称 Sort int // 排序 CreateTime time.Time // 创建时间 ModifyTime time.Time // 修改时间 } // 添加数据 func AddBaseFromSci99Index(item *BaseFromSci99Index) (lastId int64, err error) { o := orm.NewOrmUsingDB("data") lastId, err = o.Insert(item) return } func AddBaseFromSci99Classify(item *BaseFromSci99Classify) (lastId int64, err error) { o := orm.NewOrmUsingDB("data") lastId, err = o.Insert(item) return } func AddBaseFromSci99DataMulti(item []*BaseFromSci99Data) (err error) { o := orm.NewOrmUsingDB("data") _, err = o.InsertMulti(1000, item) return } func GetBaseFromSci99Index() (list []*BaseFromSci99Index, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_sci99_index ` _, err = o.Raw(sql).QueryRows(&list) return } func GetBaseFromSci99Classify() (list []*BaseFromSci99Classify, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_sci99_classify ` _, err = o.Raw(sql).QueryRows(&list) return } func GetBaseFromTradeSci99DataAll(dateStr string) (list []*BaseFromSci99Data, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_sci99_data where data_time=?` _, err = o.Raw(sql, dateStr).QueryRows(&list) return } func GetBaseFromTradeSci99IndexAll(indexCode string) (list []*BaseFromSci99Data, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT * FROM base_from_sci99_data where index_code=?` _, err = o.Raw(sql, indexCode).QueryRows(&list) return } func GetBaseFromTradeSci99LatestData(indexCode string) (date time.Time, err error) { o := orm.NewOrmUsingDB("data") sql := `SELECT data_time FROM base_from_sci99_data where index_code=? ORDER BY data_time DESC limit 1 ` err = o.Raw(sql, indexCode).QueryRow(&date) return } // UpdateBaseFromSci99Data func UpdateBaseFromSci99Data(value float64, indexCode, dataTime string) (err error) { o := orm.NewOrmUsingDB("data") sql := `UPDATE base_from_sci99_data SET value=?,modify_time=NOW() WHERE index_code = ? AND data_time = ? ` _, err = o.Raw(sql, value, indexCode, dataTime).Exec() return }