baiinfo_data.go 7.0 KB

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