factor_edb_series_mapping.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package models
  2. import (
  3. "eta_gn/eta_index_lib/global"
  4. "eta_gn/eta_index_lib/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. )
  9. // FactorEdbSeriesMapping 因子指标系列-指标关联表
  10. type FactorEdbSeriesMapping struct {
  11. FactorEdbSeriesMappingId int `gorm:"primaryKey;autoIncrement;column:factor_edb_series_mapping_id" description:"因子指标系列映射ID"`
  12. FactorEdbSeriesId int `gorm:"column:factor_edb_series_id" description:"因子指标系列ID"`
  13. EdbInfoId int `gorm:"column:edb_info_id" description:"指标ID"`
  14. EdbCode string `gorm:"column:edb_code" description:"指标编码"`
  15. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  16. ModifyTime time.Time `gorm:"column:modify_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. err = global.DEFAULT_DmSQL.Create(m).Error
  41. return
  42. }
  43. func (m *FactorEdbSeriesMapping) CreateMulti(items []*FactorEdbSeriesMapping) (err error) {
  44. if len(items) == 0 {
  45. return
  46. }
  47. err = global.DEFAULT_DmSQL.CreateInBatches(items, 500).Error
  48. return
  49. }
  50. func (m *FactorEdbSeriesMapping) Update(cols []string) (err error) {
  51. err = global.DEFAULT_DmSQL.Model(m).Select(cols).Updates(m).Error
  52. return
  53. }
  54. func (m *FactorEdbSeriesMapping) Remove() (err error) {
  55. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  56. err = global.DEFAULT_DmSQL.Exec(sql, m.FactorEdbSeriesMappingId).Error
  57. return
  58. }
  59. func (m *FactorEdbSeriesMapping) MultiRemove(ids []int) (err error) {
  60. if len(ids) == 0 {
  61. return
  62. }
  63. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  64. err = global.DEFAULT_DmSQL.Exec(sql, ids).Error
  65. return
  66. }
  67. func (m *FactorEdbSeriesMapping) RemoveByCondition(condition string, pars []interface{}) (err error) {
  68. if condition == "" {
  69. return
  70. }
  71. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
  72. err = global.DEFAULT_DmSQL.Exec(sql, pars...).Error
  73. return
  74. }
  75. func (m *FactorEdbSeriesMapping) GetItemById(id int) (item *FactorEdbSeriesMapping, err error) {
  76. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  77. err = global.DEFAULT_DmSQL.Raw(sql, id).First(&item).Error
  78. return
  79. }
  80. func (m *FactorEdbSeriesMapping) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *FactorEdbSeriesMapping, err error) {
  81. order := ``
  82. if orderRule != "" {
  83. order = ` ORDER BY ` + orderRule
  84. }
  85. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  86. err = global.DEFAULT_DmSQL.Raw(sql, pars...).First(&item).Error
  87. return
  88. }
  89. func (m *FactorEdbSeriesMapping) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  90. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  91. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&count).Error
  92. return
  93. }
  94. func (m *FactorEdbSeriesMapping) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*FactorEdbSeriesMapping, err error) {
  95. fields := strings.Join(fieldArr, ",")
  96. if len(fieldArr) == 0 {
  97. fields = `*`
  98. }
  99. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  100. if orderRule != "" {
  101. order = ` ORDER BY ` + orderRule
  102. }
  103. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  104. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error
  105. return
  106. }
  107. func (m *FactorEdbSeriesMapping) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*FactorEdbSeriesMapping, err error) {
  108. fields := strings.Join(fieldArr, ",")
  109. if len(fieldArr) == 0 {
  110. fields = `*`
  111. }
  112. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  113. if orderRule != "" {
  114. order = ` ORDER BY ` + orderRule
  115. }
  116. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  117. pars = append(pars, startSize, pageSize)
  118. err = global.DEFAULT_DmSQL.Raw(sql, pars...).Scan(&items).Error
  119. return
  120. }
  121. // FactorEdbSeriesMappingItem 因子指标系列-指标关联信息
  122. type FactorEdbSeriesMappingItem struct {
  123. SeriesId int `description:"因子指标系列ID"`
  124. EdbInfoId int `description:"指标ID"`
  125. EdbCode string `description:"指标编码"`
  126. EdbName string `description:"指标名称"`
  127. EdbNameEn string `description:"指标名称-英文"`
  128. }
  129. func (m *FactorEdbSeriesMapping) Format2Item() (item *FactorEdbSeriesMappingItem) {
  130. item = new(FactorEdbSeriesMappingItem)
  131. item.SeriesId = m.FactorEdbSeriesId
  132. item.EdbInfoId = m.EdbInfoId
  133. item.EdbCode = m.EdbCode
  134. return
  135. }
  136. func (m *FactorEdbSeriesMapping) GetItemBySeriesId(seriesId int) (items []*FactorEdbSeriesMapping, err error) {
  137. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? `, m.TableName(), m.Cols().FactorEdbSeriesId)
  138. err = global.DEFAULT_DmSQL.Raw(sql, seriesId).Scan(&items).Error
  139. return
  140. }