package trade_analysis import ( "fmt" "github.com/beego/beego/v2/client/orm" "strings" "time" ) // BaseFromTradeClassify 交易所分类表 type BaseFromTradeClassify struct { Id uint64 `orm:"column(id);pk"` ClassifyName string //分类名称 ClassifyType string //分类名称下的类型 Exchange string //交易所 LatestDate time.Time //数据最近的日期 CreateTime time.Time //插入时间 ModifyTime time.Time //修改时间 } func (m *BaseFromTradeClassify) TableName() string { return "base_from_trade_classify" } type BaseFromTradeClassifyCols struct { PrimaryId string Exchange string ClassifyName string ClassifyType string LatestDate string CreateTime string ModifyTime string } func (m *BaseFromTradeClassify) Cols() BaseFromTradeClassifyCols { return BaseFromTradeClassifyCols{ PrimaryId: "id", Exchange: "exchange", ClassifyName: "classify_name", ClassifyType: "classify_type", LatestDate: "latest_date", CreateTime: "create_time", ModifyTime: "modify_time", } } func (m *BaseFromTradeClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromTradeClassify, err error) { o := orm.NewOrm() fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime) if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // GetClassifyItemsByCondition 获取品种信息 func (m *BaseFromTradeClassify) GetClassifyItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromTradeClassify, err error) { o := orm.NewOrm() fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime) if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s GROUP BY %s %s`, fields, m.TableName(), condition, m.Cols().ClassifyName, order) _, err = o.Raw(sql, pars).QueryRows(&items) return }