factor_edb_series_calculate_func.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package models
  2. import (
  3. "eta/eta_index_lib/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // FactorEdbSeriesCalculateFunc 多因子系列-计算方式表
  10. type FactorEdbSeriesCalculateFunc struct {
  11. FactorEdbSeriesCalculateFuncId int `orm:"column(factor_edb_series_calculate_func_id);pk"`
  12. CalculateName string `description:"计算方式名称"`
  13. Source int `description:"计算方式来源"`
  14. EdbInfoType int `description:"指标计算类型:0-普通指标;1-预测指标"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. }
  18. func (m *FactorEdbSeriesCalculateFunc) TableName() string {
  19. return "factor_edb_series_calculate_func"
  20. }
  21. type FactorEdbSeriesCalculateFuncCols struct {
  22. PrimaryId string
  23. CalculateName string
  24. Source string
  25. EdbInfoType string
  26. CreateTime string
  27. ModifyTime string
  28. }
  29. func (m *FactorEdbSeriesCalculateFunc) Cols() FactorEdbSeriesCalculateFuncCols {
  30. return FactorEdbSeriesCalculateFuncCols{
  31. PrimaryId: "factor_edb_series_calculate_func_id",
  32. CalculateName: "calculate_name",
  33. Source: "source",
  34. EdbInfoType: "edb_info_type",
  35. CreateTime: "create_time",
  36. ModifyTime: "modify_time",
  37. }
  38. }
  39. func (m *FactorEdbSeriesCalculateFunc) Create() (err error) {
  40. o := orm.NewOrm()
  41. id, err := o.Insert(m)
  42. if err != nil {
  43. return
  44. }
  45. m.FactorEdbSeriesCalculateFuncId = int(id)
  46. return
  47. }
  48. func (m *FactorEdbSeriesCalculateFunc) CreateMulti(items []*FactorEdbSeriesCalculateFunc) (err error) {
  49. if len(items) == 0 {
  50. return
  51. }
  52. o := orm.NewOrm()
  53. _, err = o.InsertMulti(len(items), items)
  54. return
  55. }
  56. func (m *FactorEdbSeriesCalculateFunc) Update(cols []string) (err error) {
  57. o := orm.NewOrm()
  58. _, err = o.Update(m, cols...)
  59. return
  60. }
  61. func (m *FactorEdbSeriesCalculateFunc) Remove() (err error) {
  62. o := orm.NewOrm()
  63. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  64. _, err = o.Raw(sql, m.FactorEdbSeriesCalculateFuncId).Exec()
  65. return
  66. }
  67. func (m *FactorEdbSeriesCalculateFunc) MultiRemove(ids []int) (err error) {
  68. if len(ids) == 0 {
  69. return
  70. }
  71. o := orm.NewOrm()
  72. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  73. _, err = o.Raw(sql, ids).Exec()
  74. return
  75. }
  76. func (m *FactorEdbSeriesCalculateFunc) GetItemById(id int) (item *FactorEdbSeriesCalculateFunc, err error) {
  77. o := orm.NewOrm()
  78. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  79. err = o.Raw(sql, id).QueryRow(&item)
  80. return
  81. }
  82. func (m *FactorEdbSeriesCalculateFunc) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FactorEdbSeriesCalculateFunc, err error) {
  83. o := orm.NewOrm()
  84. order := ``
  85. if orderRule != "" {
  86. order = ` ORDER BY ` + orderRule
  87. }
  88. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  89. err = o.Raw(sql, pars).QueryRow(&item)
  90. return
  91. }
  92. func (m *FactorEdbSeriesCalculateFunc) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  93. o := orm.NewOrm()
  94. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  95. err = o.Raw(sql, pars).QueryRow(&count)
  96. return
  97. }
  98. func (m *FactorEdbSeriesCalculateFunc) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FactorEdbSeriesCalculateFunc, err error) {
  99. o := orm.NewOrm()
  100. fields := strings.Join(fieldArr, ",")
  101. if len(fieldArr) == 0 {
  102. fields = `*`
  103. }
  104. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  105. if orderRule != "" {
  106. order = ` ORDER BY ` + orderRule
  107. }
  108. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  109. _, err = o.Raw(sql, pars).QueryRows(&items)
  110. return
  111. }
  112. func (m *FactorEdbSeriesCalculateFunc) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FactorEdbSeriesCalculateFunc, err error) {
  113. o := orm.NewOrm()
  114. fields := strings.Join(fieldArr, ",")
  115. if len(fieldArr) == 0 {
  116. fields = `*`
  117. }
  118. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  119. if orderRule != "" {
  120. order = ` ORDER BY ` + orderRule
  121. }
  122. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  123. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  124. return
  125. }
  126. // FactorEdbSeriesCalculateFuncItem 多因子系列-计算方式
  127. type FactorEdbSeriesCalculateFuncItem struct {
  128. CalculateName string `description:"计算方式名称"`
  129. Source int `description:"计算方式来源"`
  130. }
  131. func (m *FactorEdbSeriesCalculateFunc) Format2Item() (item *FactorEdbSeriesCalculateFuncItem) {
  132. item = new(FactorEdbSeriesCalculateFuncItem)
  133. item.CalculateName = m.CalculateName
  134. item.Source = m.Source
  135. return
  136. }