factor_edb_series_mapping.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. // FactorEdbSeriesMapping 因子指标系列-指标关联表
  10. type FactorEdbSeriesMapping struct {
  11. FactorEdbSeriesMappingId int `orm:"column(factor_edb_series_mapping_id);pk"`
  12. FactorEdbSeriesId int `description:"因子指标系列ID"`
  13. EdbInfoId int `description:"指标ID"`
  14. EdbCode string `description:"指标编码"`
  15. CreateTime time.Time `description:"创建时间"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. }
  18. func (m *FactorEdbSeriesMapping) TableName() string {
  19. return "factor_edb_series_mapping"
  20. }
  21. type FactorEdbSeriesMappingCols struct {
  22. PrimaryId string
  23. FactorEdbSeriesId string
  24. EdbInfoId string
  25. EdbCode string
  26. CreateTime string
  27. ModifyTime string
  28. }
  29. func (m *FactorEdbSeriesMapping) Cols() FactorEdbSeriesMappingCols {
  30. return FactorEdbSeriesMappingCols{
  31. PrimaryId: "factor_edb_series_mapping_id",
  32. FactorEdbSeriesId: "factor_edb_series_id",
  33. EdbInfoId: "edb_info_id",
  34. EdbCode: "edb_code",
  35. CreateTime: "create_time",
  36. ModifyTime: "modify_time",
  37. }
  38. }
  39. func (m *FactorEdbSeriesMapping) Create() (err error) {
  40. o := orm.NewOrm()
  41. id, err := o.Insert(m)
  42. if err != nil {
  43. return
  44. }
  45. m.FactorEdbSeriesMappingId = int(id)
  46. return
  47. }
  48. func (m *FactorEdbSeriesMapping) CreateMulti(items []*FactorEdbSeriesMapping) (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 *FactorEdbSeriesMapping) Update(cols []string) (err error) {
  57. o := orm.NewOrm()
  58. _, err = o.Update(m, cols...)
  59. return
  60. }
  61. func (m *FactorEdbSeriesMapping) 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.FactorEdbSeriesMappingId).Exec()
  65. return
  66. }
  67. func (m *FactorEdbSeriesMapping) 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 *FactorEdbSeriesMapping) RemoveByCondition(condition string, pars []interface{}) (err error) {
  77. if condition == "" {
  78. return
  79. }
  80. o := orm.NewOrm()
  81. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
  82. _, err = o.Raw(sql, pars).Exec()
  83. return
  84. }
  85. func (m *FactorEdbSeriesMapping) GetItemById(id int) (item *FactorEdbSeriesMapping, err error) {
  86. o := orm.NewOrm()
  87. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  88. err = o.Raw(sql, id).QueryRow(&item)
  89. return
  90. }
  91. func (m *FactorEdbSeriesMapping) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FactorEdbSeriesMapping, err error) {
  92. o := orm.NewOrm()
  93. order := ``
  94. if orderRule != "" {
  95. order = ` ORDER BY ` + orderRule
  96. }
  97. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  98. err = o.Raw(sql, pars).QueryRow(&item)
  99. return
  100. }
  101. func (m *FactorEdbSeriesMapping) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  102. o := orm.NewOrm()
  103. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  104. err = o.Raw(sql, pars).QueryRow(&count)
  105. return
  106. }
  107. func (m *FactorEdbSeriesMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FactorEdbSeriesMapping, err error) {
  108. o := orm.NewOrm()
  109. fields := strings.Join(fieldArr, ",")
  110. if len(fieldArr) == 0 {
  111. fields = `*`
  112. }
  113. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  114. if orderRule != "" {
  115. order = ` ORDER BY ` + orderRule
  116. }
  117. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  118. _, err = o.Raw(sql, pars).QueryRows(&items)
  119. return
  120. }
  121. func (m *FactorEdbSeriesMapping) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FactorEdbSeriesMapping, err error) {
  122. o := orm.NewOrm()
  123. fields := strings.Join(fieldArr, ",")
  124. if len(fieldArr) == 0 {
  125. fields = `*`
  126. }
  127. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  128. if orderRule != "" {
  129. order = ` ORDER BY ` + orderRule
  130. }
  131. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  132. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  133. return
  134. }
  135. // FactorEdbSeriesMappingItem 因子指标系列-指标关联信息
  136. type FactorEdbSeriesMappingItem struct {
  137. SeriesId int `description:"因子指标系列ID"`
  138. EdbInfoId int `description:"指标ID"`
  139. EdbCode string `description:"指标编码"`
  140. EdbName string `description:"指标名称"`
  141. EdbNameEn string `description:"指标名称-英文"`
  142. }
  143. func (m *FactorEdbSeriesMapping) Format2Item() (item *FactorEdbSeriesMappingItem) {
  144. item = new(FactorEdbSeriesMappingItem)
  145. item.SeriesId = m.FactorEdbSeriesId
  146. item.EdbInfoId = m.EdbInfoId
  147. item.EdbCode = m.EdbCode
  148. return
  149. }
  150. func (m *FactorEdbSeriesMapping) GetItemBySeriesId(seriesId int) (items []*FactorEdbSeriesMapping, err error) {
  151. o := orm.NewOrm()
  152. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? `, m.TableName(), m.Cols().FactorEdbSeriesId)
  153. _, err = o.Raw(sql, seriesId).QueryRows(&items)
  154. return
  155. }