base_from_ths_hf_index.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. package data_manage
  2. import (
  3. "eta/eta_task/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "strings"
  7. "time"
  8. )
  9. // BaseFromThsHfIndex 同花顺高频数据
  10. type BaseFromThsHfIndex struct {
  11. BaseFromThsHfIndexId int `orm:"column(base_from_ths_hf_index_id);pk"`
  12. BaseFromThsHfClassifyId int `description:"分类ID"`
  13. IndexCode string `description:"指标编码"`
  14. IndexName string `description:"指标名称"`
  15. Unit string `description:"单位"`
  16. Source string `description:"数据来源"`
  17. Frequency string `description:"频度"`
  18. StartDate time.Time `description:"开始日期(至时分秒)"`
  19. EndDate time.Time `description:"结束日期(至时分秒)"`
  20. Describe string `description:"指标描述"`
  21. Sort int `description:"排序"`
  22. IsStop int `description:"是否停更:0-否;1-停更"`
  23. TerminalCode string `description:"所属终端编码"`
  24. StockCode string `description:"证券代码"`
  25. Indicator string `description:"同花顺指标代码"`
  26. ApiPars string `description:"API请求参数"`
  27. LatestValue float64 `description:"最新值"`
  28. SysUserId int `description:"创建人ID"`
  29. SysUserRealName string `description:"创建人姓名"`
  30. CreateTime time.Time `description:"创建时间"`
  31. ModifyTime time.Time `description:"修改时间"`
  32. }
  33. func (m *BaseFromThsHfIndex) TableName() string {
  34. return "base_from_ths_hf_index"
  35. }
  36. type BaseFromThsHfIndexCols struct {
  37. PrimaryId string
  38. BaseFromThsHfClassifyId string
  39. IndexCode string
  40. IndexName string
  41. Unit string
  42. Source string
  43. Frequency string
  44. StartDate string
  45. EndDate string
  46. Describe string
  47. Sort string
  48. IsStop string
  49. TerminalCode string
  50. StockCode string
  51. Indicator string
  52. ApiPars string
  53. LatestValue string
  54. SysUserId string
  55. SysUserRealName string
  56. CreateTime string
  57. ModifyTime string
  58. }
  59. func (m *BaseFromThsHfIndex) Cols() BaseFromThsHfIndexCols {
  60. return BaseFromThsHfIndexCols{
  61. PrimaryId: "base_from_ths_hf_index_id",
  62. BaseFromThsHfClassifyId: "base_from_ths_hf_classify_id",
  63. IndexCode: "index_code",
  64. IndexName: "index_name",
  65. Unit: "unit",
  66. Source: "source",
  67. Frequency: "frequency",
  68. StartDate: "start_date",
  69. EndDate: "end_date",
  70. Describe: "describe",
  71. Sort: "sort",
  72. IsStop: "is_stop",
  73. TerminalCode: "terminal_code",
  74. StockCode: "stock_code",
  75. Indicator: "indicator",
  76. ApiPars: "api_pars",
  77. LatestValue: "latest_value",
  78. SysUserId: "sys_user_id",
  79. SysUserRealName: "sys_user_real_name",
  80. CreateTime: "create_time",
  81. ModifyTime: "modify_time",
  82. }
  83. }
  84. func (m *BaseFromThsHfIndex) Create() (err error) {
  85. o := orm.NewOrm()
  86. id, err := o.Insert(m)
  87. if err != nil {
  88. return
  89. }
  90. m.BaseFromThsHfIndexId = int(id)
  91. return
  92. }
  93. func (m *BaseFromThsHfIndex) CreateMulti(items []*BaseFromThsHfIndex) (err error) {
  94. if len(items) == 0 {
  95. return
  96. }
  97. o := orm.NewOrm()
  98. _, err = o.InsertMulti(len(items), items)
  99. return
  100. }
  101. func (m *BaseFromThsHfIndex) Update(cols []string) (err error) {
  102. o := orm.NewOrm()
  103. _, err = o.Update(m, cols...)
  104. return
  105. }
  106. func (m *BaseFromThsHfIndex) Remove() (err error) {
  107. o := orm.NewOrm()
  108. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  109. _, err = o.Raw(sql, m.BaseFromThsHfIndexId).Exec()
  110. return
  111. }
  112. func (m *BaseFromThsHfIndex) MultiRemove(ids []int) (err error) {
  113. if len(ids) == 0 {
  114. return
  115. }
  116. o := orm.NewOrm()
  117. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  118. _, err = o.Raw(sql, ids).Exec()
  119. return
  120. }
  121. func (m *BaseFromThsHfIndex) RemoveByCondition(condition string, pars []interface{}) (err error) {
  122. if condition == "" {
  123. return
  124. }
  125. o := orm.NewOrm()
  126. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
  127. _, err = o.Raw(sql, pars).Exec()
  128. return
  129. }
  130. func (m *BaseFromThsHfIndex) GetItemById(id int) (item *BaseFromThsHfIndex, err error) {
  131. o := orm.NewOrm()
  132. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  133. err = o.Raw(sql, id).QueryRow(&item)
  134. return
  135. }
  136. func (m *BaseFromThsHfIndex) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *BaseFromThsHfIndex, err error) {
  137. o := orm.NewOrm()
  138. order := ``
  139. if orderRule != "" {
  140. order = ` ORDER BY ` + orderRule
  141. }
  142. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  143. err = o.Raw(sql, pars).QueryRow(&item)
  144. return
  145. }
  146. func (m *BaseFromThsHfIndex) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  147. o := orm.NewOrm()
  148. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  149. err = o.Raw(sql, pars).QueryRow(&count)
  150. return
  151. }
  152. func (m *BaseFromThsHfIndex) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BaseFromThsHfIndex, err error) {
  153. o := orm.NewOrm()
  154. fields := strings.Join(fieldArr, ",")
  155. if len(fieldArr) == 0 {
  156. fields = `*`
  157. }
  158. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  159. if orderRule != "" {
  160. order = ` ORDER BY ` + orderRule
  161. }
  162. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  163. _, err = o.Raw(sql, pars).QueryRows(&items)
  164. return
  165. }
  166. func (m *BaseFromThsHfIndex) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*BaseFromThsHfIndex, err error) {
  167. o := orm.NewOrm()
  168. fields := strings.Join(fieldArr, ",")
  169. if len(fieldArr) == 0 {
  170. fields = `*`
  171. }
  172. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  173. if orderRule != "" {
  174. order = ` ORDER BY ` + orderRule
  175. }
  176. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  177. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  178. return
  179. }