baiinfo_data.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. )
  7. type BaiinfoClassify struct {
  8. TypeName string `orm:"column(type_name)" description:"分类名称"`
  9. TypeCode string `orm:"column(type_code)" description:"分类名称编码"`
  10. }
  11. type BaiinfoFrequency struct {
  12. Frequency string `description:"频度"`
  13. }
  14. func GetBaiinfoFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
  15. sql := ` SELECT frequency FROM base_from_baiinfo_index WHERE classify_id = ? `
  16. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  17. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&items).Error
  18. return
  19. }
  20. type BaiinfoIndex struct {
  21. BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_index_id);pk" gorm:"primaryKey" `
  22. Interface string
  23. Name string
  24. IndexCode string
  25. IndexName string
  26. Type1 string `orm:"column(type_1)"`
  27. Type2 string `orm:"column(type_2)"`
  28. Type3 string `orm:"column(type_3)"`
  29. Frequency string
  30. Unit string
  31. ApiStartTime string
  32. ApiUpdateTime string
  33. StartTime string
  34. FinishTime string
  35. CreateTime string
  36. ModifyTime string
  37. }
  38. func GetBaiinfoIndex(condition string, pars []interface{}) (items []*BaiinfoIndex, err error) {
  39. sql := ` SELECT * FROM base_from_baiinfo_index WHERE 1=1 `
  40. if condition != "" {
  41. sql += condition
  42. }
  43. sql += `ORDER BY sort ASC, base_from_baiinfo_index_id asc`
  44. err = global.DmSQL["data"].Raw(sql, pars...).Scan(&items).Error
  45. return
  46. }
  47. type BaiinfoExportIndex struct {
  48. TypeName string
  49. IndexCode string
  50. IndexName string
  51. Type1 string `orm:"column(type_1)"`
  52. Type2 string `orm:"column(type_2)"`
  53. Type3 string `orm:"column(type_3)"`
  54. Frequency string
  55. Unit string
  56. ModifyTime string
  57. }
  58. func GetExportBaiinfoIndex(typeCodes []string) (items []*BaiinfoExportIndex, err error) {
  59. if len(typeCodes) == 0 {
  60. return
  61. }
  62. sql := ` SELECT *,CONCAT(type_2, "#", type_3) AS type_name FROM base_from_baiinfo_index WHERE CONCAT(type_2, "#", type_3) IN (` + utils.GetOrmInReplace(len(typeCodes)) + `) ORDER BY frequency ASC,index_code ASC`
  63. err = global.DmSQL["data"].Raw(sql, typeCodes).Scan(&items).Error
  64. return
  65. }
  66. func GetBaiinfoFrequency(classifyId int) (items []*string, err error) {
  67. sql := `SELECT DISTINCT frequency FROM base_from_baiinfo_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  68. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&items).Error
  69. return
  70. }
  71. func GetBaiinfoFrequencyByCode(code string) (items []*string, err error) {
  72. sql := `SELECT DISTINCT frequency FROM base_from_baiinfo_index WHERE index_code=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  73. err = global.DmSQL["data"].Raw(sql, code).Scan(&items).Error
  74. return
  75. }
  76. type BaiinfoIndexList struct {
  77. BaseFromBaiinfoIndexId int `orm:"column(base_from_baiinfo_index_id);pk" gorm:"primaryKey" `
  78. Interface string
  79. Name string
  80. IndexCode string
  81. IndexName string
  82. Type1 string `orm:"column(type_1)"`
  83. Type2 string `orm:"column(type_2)"`
  84. Type3 string `orm:"column(type_3)"`
  85. Frequency string
  86. Unit string
  87. ApiStartTime string
  88. ApiUpdateTime string
  89. StartTime string
  90. FinishTime string
  91. ModifyTime string
  92. DataList []*BaiinfoIndexData
  93. Paging *paging.PagingItem `description:"分页数据"`
  94. }
  95. type BaiinfoIndexData struct {
  96. Value string `orm:"column(value)" description:"日期"`
  97. DataTime string `orm:"column(data_time)" description:"值"`
  98. }
  99. func GetBaiinfoIndexData(indexCode string, startSize, pageSize int) (items []*BaiinfoIndexData, err error) {
  100. sql := ` SELECT * FROM base_from_baiinfo_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  101. err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Scan(&items).Error
  102. return
  103. }
  104. func GetBaiinfoIndexDataCount(indexCode string) (count int, err error) {
  105. sql := ` SELECT COUNT(1) AS count FROM base_from_baiinfo_data WHERE index_code=? `
  106. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error
  107. return
  108. }
  109. // GetBaiinfoItemList 模糊查询Baiinfo数据库指标列表
  110. func GetBaiinfoItemList(keyword string) (items []*BaiinfoIndex, err error) {
  111. sql := "SELECT * FROM base_from_baiinfo_index WHERE CONCAT(index_name,index_code) LIKE ? "
  112. err = global.DmSQL["data"].Raw(sql, utils.GetLikeKeyword(keyword)).Scan(&items).Error
  113. return
  114. }
  115. func GetBaiinfoIndexDataByCode(indexCode string) (items []*BaiinfoIndexData, err error) {
  116. sql := ` SELECT * FROM base_from_baiinfo_data WHERE index_code=? ORDER BY data_time DESC `
  117. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&items).Error
  118. return
  119. }
  120. func GetBaiinfoDataMaxCount(classifyId int) (count int, err error) {
  121. sql := `SELECT COALESCE(MAX(t.num), 0) AS count FROM (
  122. SELECT COUNT(1) AS num FROM base_from_baiinfo_index AS a
  123. INNER JOIN base_from_baiinfo_data AS b ON a.index_code=b.index_code
  124. WHERE a.classify_id=?
  125. GROUP BY a.base_from_baiinfo_index_id
  126. )AS t `
  127. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error
  128. return
  129. }
  130. type ExportBaiinfoDataMaxCount struct {
  131. TypeName string
  132. Count int
  133. }
  134. type ExportBaiinfoIndexData struct {
  135. Value string `orm:"column(value)" description:"日期"`
  136. DataTime string `orm:"column(data_time)" description:"值"`
  137. IndexCode string `orm:"column(index_code)" description:"指标编码"`
  138. }