123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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 //修改时间
- }
- // GetAllBaseFromTradeClassify 获取所有的交易所分类列表
- func GetAllBaseFromTradeClassify() (list []*BaseFromTradeClassify, err error) {
- sql := `SELECT * FROM base_from_trade_classify `
- o := orm.NewOrmUsingDB("data")
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- func GetTradeTopLastDataTime(exchange string, classifyName, classifyType string) (item *BaseFromTradeClassify, err error) {
- sql := `SELECT * FROM base_from_trade_classify WHERE exchange = ? AND classify_name=? `
- pars := make([]interface{}, 0)
- pars = append(pars, exchange)
- if exchange == "zhengzhou" {
- pars = append(pars, classifyType)
- } else {
- pars = append(pars, classifyName)
- sql += ` AND classify_type=? `
- pars = append(pars, classifyType)
- }
- sql += ` ORDER BY latest_date desc`
- o := orm.NewOrmUsingDB("data")
- err = o.Raw(sql, pars...).QueryRow(&item)
- return
- }
- // GetClassifyTypeByClassifyName 根据分类名称获取分类类型
- func GetClassifyTypeByClassifyName(exchange, classifyName string) (item *TradeClassifyName, err error) {
- sql := `SELECT classify_name, classify_type FROM base_from_trade_classify WHERE exchange = ? AND classify_name=? `
- o := orm.NewOrmUsingDB("data")
- err = o.Raw(sql, exchange, classifyName).QueryRow(&item)
- return
- }
- 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.NewOrmUsingDB("data")
- 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.NewOrmUsingDB("data")
- 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
- }
- // BaseFromTradeClassifyItem 交易所品种信息
- type BaseFromTradeClassifyItem struct {
- ClassifyName string `description:"品种"`
- Exchange string `description:"交易所标识"`
- ExchangeName string `description:"交易所名称"`
- }
- // BaseFromTradeContractItem 交易所合约信息
- type BaseFromTradeContractItem struct {
- ClassifyName string `description:"品种"`
- Exchange string `description:"交易所标识"`
- ExchangeName string `description:"交易所名称"`
- ClassifyType string `description:"合约"`
- LatestDate string `description:"最近数据的日期"`
- CreateTime string `description:"创建时间"`
- }
|