trade_classify.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package trade_analysis
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. // BaseFromTradeClassify 交易所分类表
  9. type BaseFromTradeClassify struct {
  10. Id uint64 `orm:"column(id);pk"`
  11. ClassifyName string //分类名称
  12. ClassifyType string //分类名称下的类型
  13. Exchange string //交易所
  14. LatestDate time.Time //数据最近的日期
  15. CreateTime time.Time //插入时间
  16. ModifyTime time.Time //修改时间
  17. }
  18. func (m *BaseFromTradeClassify) TableName() string {
  19. return "base_from_trade_classify"
  20. }
  21. type BaseFromTradeClassifyCols struct {
  22. PrimaryId string
  23. Exchange string
  24. ClassifyName string
  25. ClassifyType string
  26. LatestDate string
  27. CreateTime string
  28. ModifyTime string
  29. }
  30. func (m *BaseFromTradeClassify) Cols() BaseFromTradeClassifyCols {
  31. return BaseFromTradeClassifyCols{
  32. PrimaryId: "id",
  33. Exchange: "exchange",
  34. ClassifyName: "classify_name",
  35. ClassifyType: "classify_type",
  36. LatestDate: "latest_date",
  37. CreateTime: "create_time",
  38. ModifyTime: "modify_time",
  39. }
  40. }
  41. func (m *BaseFromTradeClassify) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromTradeClassify, err error) {
  42. o := orm.NewOrm()
  43. fields := strings.Join(fieldArr, ",")
  44. if len(fieldArr) == 0 {
  45. fields = `*`
  46. }
  47. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  48. if orderRule != "" {
  49. order = ` ORDER BY ` + orderRule
  50. }
  51. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  52. _, err = o.Raw(sql, pars).QueryRows(&items)
  53. return
  54. }
  55. // GetClassifyItemsByCondition 获取品种信息
  56. func (m *BaseFromTradeClassify) GetClassifyItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromTradeClassify, err error) {
  57. o := orm.NewOrm()
  58. fields := strings.Join(fieldArr, ",")
  59. if len(fieldArr) == 0 {
  60. fields = `*`
  61. }
  62. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  63. if orderRule != "" {
  64. order = ` ORDER BY ` + orderRule
  65. }
  66. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s GROUP BY %s %s`, fields, m.TableName(), condition, m.Cols().ClassifyName, order)
  67. _, err = o.Raw(sql, pars).QueryRows(&items)
  68. return
  69. }