sci_data.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 SciClassify struct {
  8. TypeName string `orm:"column(type_name)" description:"分类名称"`
  9. TypeCode string `orm:"column(type_code)" description:"分类名称编码"`
  10. }
  11. type SciFrequency struct {
  12. Frequency string `description:"频度"`
  13. }
  14. func GetSciFrequencyByClassifyId(classifyId int) (items []*GlFrequency, err error) {
  15. sql := ` SELECT frequency FROM base_from_sci_index WHERE classify_id = ? `
  16. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  17. err = global.DmSQL["data"].Raw(sql, classifyId).Find(&items).Error
  18. return
  19. }
  20. type SciIndex struct {
  21. BaseFromSciIndexId int `orm:"column(base_from_sci_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 GetSciIndex(condition string, pars []interface{}) (items []*SciIndex, err error) {
  39. sql := ` SELECT * FROM base_from_sci_index WHERE 1=1 `
  40. if condition != "" {
  41. sql += condition
  42. }
  43. sql += `ORDER BY sort ASC, base_from_sci_index_id asc`
  44. err = global.DmSQL["data"].Raw(sql, pars...).Find(&items).Error
  45. return
  46. }
  47. type SciExportIndex 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 GetSciFrequency(classifyId int) (items []*string, err error) {
  59. sql := `SELECT DISTINCT frequency FROM base_from_sci_index WHERE classify_id=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  60. err = global.DmSQL["data"].Raw(sql, classifyId).Find(&items).Error
  61. return
  62. }
  63. func GetSciFrequencyByCode(code string) (items []*string, err error) {
  64. sql := `SELECT DISTINCT frequency FROM base_from_sci_index WHERE index_code=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年','年度') `
  65. err = global.DmSQL["data"].Raw(sql, code).Find(&items).Error
  66. return
  67. }
  68. type SciIndexList struct {
  69. BaseFromSciIndexId int `orm:"column(base_from_sci_index_id);pk" gorm:"primaryKey" `
  70. Interface string
  71. Name string
  72. IndexCode string
  73. IndexName string
  74. Type1 string `orm:"column(type_1)"`
  75. Type2 string `orm:"column(type_2)"`
  76. Type3 string `orm:"column(type_3)"`
  77. Frequency string
  78. Unit string
  79. ApiStartTime string
  80. ApiUpdateTime string
  81. StartTime string
  82. FinishTime string
  83. ModifyTime string
  84. DataList []*SciIndexData
  85. Paging *paging.PagingItem `description:"分页数据"`
  86. }
  87. type SciIndexData struct {
  88. Value string `orm:"column(value)" description:"日期"`
  89. DataTime string `orm:"column(data_time)" description:"值"`
  90. }
  91. func GetSciIndexData(indexCode string, startSize, pageSize int) (items []*SciIndexData, err error) {
  92. sql := ` SELECT * FROM base_from_sci_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  93. err = global.DmSQL["data"].Raw(sql, indexCode, startSize, pageSize).Find(&items).Error
  94. return
  95. }
  96. func GetSciIndexDataCount(indexCode string) (count int, err error) {
  97. sql := ` SELECT COUNT(1) AS count FROM base_from_sci_data WHERE index_code=? `
  98. err = global.DmSQL["data"].Raw(sql, indexCode).Scan(&count).Error
  99. return
  100. }
  101. // GetSciItemList 模糊查询Sci数据库指标列表
  102. func GetSciItemList(keyword string) (items []*SciIndex, err error) {
  103. sql := "SELECT * FROM base_from_sci_index WHERE CONCAT(index_name,index_code) LIKE ? "
  104. err = global.DmSQL["data"].Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
  105. return
  106. }
  107. func GetSciIndexDataByCode(indexCode string) (items []*SciIndexData, err error) {
  108. sql := ` SELECT * FROM base_from_sci_data WHERE index_code=? ORDER BY data_time DESC `
  109. err = global.DmSQL["data"].Raw(sql, indexCode).Find(&items).Error
  110. return
  111. }
  112. func GetSciDataMaxCount(classifyId int) (count int, err error) {
  113. sql := `SELECT COALESCE(MAX(t.num), 0) AS count FROM (
  114. SELECT COUNT(1) AS num FROM base_from_sci_index AS a
  115. INNER JOIN base_from_sci_data AS b ON a.index_code=b.index_code
  116. WHERE a.classify_id=?
  117. GROUP BY a.base_from_sci_index_id
  118. )AS t `
  119. err = global.DmSQL["data"].Raw(sql, classifyId).Scan(&count).Error
  120. return
  121. }
  122. type ExportSciDataMaxCount struct {
  123. TypeName string
  124. Count int
  125. }
  126. type ExportSciIndexData struct {
  127. Value string `orm:"column(value)" description:"日期"`
  128. DataTime string `orm:"column(data_time)" description:"值"`
  129. IndexCode string `orm:"column(index_code)" description:"指标编码"`
  130. }