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