base_from_ccf.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package data_manage
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  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" gorm:"primaryKey" `
  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" gorm:"primaryKey" `
  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. sql := ` SELECT * FROM base_from_ccf_index WHERE 1=1 `
  49. if condition != "" {
  50. sql += condition
  51. }
  52. sql += ` ORDER BY sort ASC, base_from_ccf_index_id asc`
  53. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
  54. return
  55. }
  56. type CCFIndexDataCountGroup struct {
  57. IndexCode string
  58. Count int
  59. }
  60. func GetCCFIndexDataCountGroup(indexCodes []string) (items []*CCFIndexDataCountGroup, err error) {
  61. if len(indexCodes) <= 0 {
  62. return
  63. }
  64. 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`
  65. err = global.DmSQL["data"].Raw(sql, indexCodes).Scan(&items).Error
  66. return
  67. }
  68. func GetCCFIndexData(indexCode string, startSize, pageSize int) (items []*BaseFromCCFData, err error) {
  69. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  70. err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Scan(&items).Error
  71. return
  72. }
  73. func GetCCFIndexDataByCodes(indexCode []string) (items []*BaseFromCCFData, err error) {
  74. if len(indexCode) <= 0 {
  75. return
  76. }
  77. sql := ` SELECT * FROM base_from_ccf_data WHERE index_code in (` + utils.GetOrmInReplace(len(indexCode)) + `) ORDER BY data_time DESC `
  78. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&items).Error
  79. return
  80. }
  81. type BaseFromCCFData struct {
  82. BaseFromCcfDataId int `orm:"column(base_from_ccf_data_id);pk" gorm:"primaryKey" `
  83. BaseFromCcfIndexId int
  84. IndexCode string
  85. DataTime string
  86. Value string
  87. CreateTime string
  88. ModifyTime string
  89. DataTimestamp int64
  90. }
  91. type BaseFromCCFIndexSearchItem struct {
  92. BaseFromCcfIndexId int `orm:"column(base_from_ccf_index_id);pk" gorm:"primaryKey" `
  93. ClassifyId int
  94. IndexCode string
  95. IndexName string
  96. }
  97. // GetCCFItemList 模糊查询CCF数据库指标列表
  98. func GetCCFItemList(condition string) (items []*BaseFromCCFIndexSearchItem, err error) {
  99. sql := "SELECT * FROM base_from_ccf_index WHERE 1=1"
  100. if condition != "" {
  101. sql += condition
  102. }
  103. err = global.DmSQL["data"].Raw(sql).Scan(&items).Error
  104. return
  105. }
  106. func GetCCFIndexDataByCode(indexCode string) (list []*BaseFromCCFData, err error) {
  107. sql := `SELECT * FROM base_from_ccf_data WHERE index_code=? `
  108. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&list).Error
  109. return
  110. }
  111. func GetBaseFromCCFIndexByIndexCode(indexCode string) (list *BaseFromCCFIndex, err error) {
  112. sql := ` SELECT * FROM base_from_ccf_index WHERE index_code=? `
  113. err = global.DmSQL["data"].Raw(sql, indexCode).First(&list).Error
  114. return
  115. }