trade_classify.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package trade_analysis
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // BaseFromTradeClassify 交易所分类表
  7. type BaseFromTradeClassify struct {
  8. Id uint64 `orm:"column(id);pk"`
  9. ClassifyName string //分类名称
  10. ClassifyType string //分类名称下的类型
  11. Exchange string //交易所
  12. LatestDate time.Time //数据最近的日期
  13. CreateTime time.Time //插入时间
  14. ModifyTime time.Time //修改时间
  15. }
  16. // GetAllBaseFromTradeClassify 获取所有的交易所分类列表
  17. func GetAllBaseFromTradeClassify() (list []*BaseFromTradeClassify, err error) {
  18. sql := `SELECT * FROM base_from_trade_classify `
  19. o := orm.NewOrmUsingDB("data")
  20. _, err = o.Raw(sql).QueryRows(&list)
  21. return
  22. }
  23. func GetTradeTopLastDataTime(exchange string, classifyName, classifyType string) (item *BaseFromTradeClassify, err error) {
  24. sql := `SELECT * FROM base_from_trade_classify WHERE exchange = ? AND classify_name=? `
  25. pars := make([]interface{}, 0)
  26. pars = append(pars, exchange)
  27. if exchange == "zhengzhou" {
  28. pars = append(pars, classifyType)
  29. } else {
  30. pars = append(pars, classifyName)
  31. sql += ` AND classify_type=? `
  32. pars = append(pars, classifyType)
  33. }
  34. sql += ` ORDER BY latest_date desc`
  35. o := orm.NewOrmUsingDB("data")
  36. err = o.Raw(sql, pars...).QueryRow(&item)
  37. return
  38. }
  39. // GetClassifyTypeByClassifyName 根据分类名称获取分类类型
  40. func GetClassifyTypeByClassifyName(exchange, classifyName string) (item *TradeClassifyName, err error) {
  41. sql := `SELECT classify_name, classify_type FROM base_from_trade_classify WHERE exchange = ? AND classify_name=? `
  42. o := orm.NewOrmUsingDB("data")
  43. err = o.Raw(sql, exchange, classifyName).QueryRow(&item)
  44. return
  45. }