base_from_ccf.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type BaseFromCCFIndex struct {
  9. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
  10. ClassifyId int
  11. IndexCode string
  12. IndexName string
  13. Frequency string
  14. Unit string
  15. Sort int
  16. CreateTime time.Time
  17. ModifyTime time.Time
  18. }
  19. type BaseFromCCFIndexList struct {
  20. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
  21. ClassifyId int
  22. IndexCode string
  23. IndexName string
  24. Frequency string
  25. Unit string
  26. Sort int
  27. CreateTime string
  28. ModifyTime string
  29. DataList []*BaseFromCCFData
  30. Paging *paging.PagingItem `description:"分页数据"`
  31. }
  32. type CCFSingleDataResp struct {
  33. BaseFromCcfIndexId int
  34. ClassifyId int
  35. IndexCode string
  36. IndexName string
  37. Frequency string
  38. Unit string
  39. CreateTime string
  40. ModifyTime string
  41. Data []*CCFSingleData
  42. }
  43. type CCFSingleData struct {
  44. Value string `orm:"column(value)" description:"日期"`
  45. DataTime string `orm:"column(data_time)" description:"值"`
  46. }
  47. func GetCCFIndex(condition string, pars interface{}) (items []*BaseFromCCFIndexList, err error) {
  48. o := orm.NewOrmUsingDB("data")
  49. sql := ` SELECT * FROM base_from_ccf_index WHERE 1=1 `
  50. if condition != "" {
  51. sql += condition
  52. }
  53. sql += ` ORDER BY sort ASC, base_from_ccf_index_id asc`
  54. _, err = o.Raw(sql, pars).QueryRows(&items)
  55. return
  56. }
  57. func GetCCFIndexDataCount(indexCode string) (count int, err error) {
  58. o := orm.NewOrmUsingDB("data")
  59. sql := ` SELECT COUNT(1) AS count FROM base_from_ccf_data WHERE index_code=? `
  60. err = o.Raw(sql, indexCode).QueryRow(&count)
  61. return
  62. }
  63. type CCFIndexDataCountGroup struct {
  64. IndexCode string
  65. Count int
  66. }
  67. func GetCCFIndexDataCountGroup(indexCodes []string) (items []*CCFIndexDataCountGroup, err error) {
  68. if len(indexCodes) <= 0 {
  69. return
  70. }
  71. o := orm.NewOrmUsingDB("data")
  72. sql := ` SELECT COUNT(1) AS count, index_code FROM base_from_ccf_data WHERE index_code IN (` + utils.GetOrmInReplace(len(indexCodes)) + `) GROUP BY index_code`
  73. _, err = o.Raw(sql, indexCodes).QueryRows(&items)
  74. return
  75. }
  76. func GetCCFIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromCCFData, err error) {
  77. o := orm.NewOrmUsingDB("data")
  78. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  79. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  80. return
  81. }
  82. func GetCCFIndexDataByCodes(indexCode []string) (items []*BaseFromCCFData, err error) {
  83. if len(indexCode) <= 0 {
  84. return
  85. }
  86. o := orm.NewOrmUsingDB("data")
  87. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  88. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  89. return
  90. }
  91. type BaseFromCCFData struct {
  92. BaseFromCcfDataId int `orm:"column(base_from_ccf_data_id);pk"`
  93. BaseFromCcfIndexId int
  94. IndexCode string
  95. DataTime string
  96. Value string
  97. CreateTime string
  98. ModifyTime string
  99. DataTimestamp int64
  100. }
  101. type BaseFromCCFIndexSearchItem struct {
  102. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk"`
  103. ClassifyId int
  104. IndexCode string
  105. IndexName string
  106. }
  107. // GetCCFItemList 模糊查询CCF数据库指标列表
  108. func GetCCFItemList(condition string) (items []*BaseFromCCFIndexSearchItem, err error) {
  109. o := orm.NewOrmUsingDB("data")
  110. sql := "SELECT * FROM base_from_ccf_index WHERE 1=1"
  111. if condition != "" {
  112. sql += condition
  113. }
  114. _, err = o.Raw(sql).QueryRows(&items)
  115. return
  116. }
  117. func GetCCFIndexDataByCode(indexCode string) (list []*BaseFromCCFData, err error) {
  118. o := orm.NewOrmUsingDB("data")
  119. sql := `SELECT * FROM base_from_ccf_data WHERE index_code=? `
  120. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  121. return
  122. }
  123. func GetBaseFromCCFIndexByIndexCode(indexCode string) (list *BaseFromCCFIndex, err error) {
  124. o := orm.NewOrmUsingDB("data")
  125. sql := ` SELECT * FROM base_from_ccf_index WHERE index_code=? `
  126. err = o.Raw(sql, indexCode).QueryRow(&list)
  127. return
  128. }