gl_data.go 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. package data_manage
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type GlClassify struct {
  9. BreedShortName string `orm:"column(BREED_SHORT_NAME)" description:"分类名称"`
  10. }
  11. func GetGlSurveyClassify() (items []*GlClassify, err error) {
  12. sql := ` SELECT CASE WHEN BREED_SHORT_NAME IS NULL THEN '无' ELSE BREED_SHORT_NAME END BREED_SHORT_NAME FROM mb_index_main_info GROUP BY BREED_SHORT_NAME ORDER BY BREED_SHORT_NAME ASC `
  13. o := orm.NewOrmUsingDB("gl")
  14. o.Raw(sql).QueryRows(&items)
  15. return
  16. }
  17. type GlFrequency struct {
  18. Frequency string `description:"频度:1-日度 2-周度 3-月度 4-季度 5-年度 99-无固定频率"`
  19. }
  20. func GetGlFrequencyByClassifyId(breedShortName string) (items []*GlFrequency, err error) {
  21. o := orm.NewOrmUsingDB("gl")
  22. if breedShortName == "无" {
  23. sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
  24. _, err = o.Raw(sql).QueryRows(&items)
  25. return
  26. } else {
  27. sql := ` SELECT FREQUENCY_NAME AS frequency FROM mb_index_main_info WHERE BREED_SHORT_NAME=? GROUP BY FREQUENCY_CODE ORDER BY FREQUENCY_CODE ASC `
  28. _, err = o.Raw(sql, breedShortName).QueryRows(&items)
  29. return
  30. }
  31. }
  32. type GlIndex struct {
  33. Id int `orm:"column(ID)"`
  34. IndexCode string `orm:"column(INDEX_CODE)"`
  35. IndexName string `orm:"column(INDEX_NAME)"`
  36. UnitName string `orm:"column(UNIT_NAME)"`
  37. FrequencyName string `orm:"column(FREQUENCY_NAME)"`
  38. UpdateTime string `orm:"column(UPDATE_TIME)"`
  39. }
  40. func GetGlIndex(breedShortName, frequency string) (items []*GlIndex, err error) {
  41. o := orm.NewOrmUsingDB("gl")
  42. if breedShortName == "无" {
  43. sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME IS NULL AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
  44. _, err = o.Raw(sql, frequency).QueryRows(&items)
  45. return
  46. } else {
  47. sql := ` SELECT * FROM mb_index_main_info WHERE BREED_SHORT_NAME=? AND FREQUENCY_NAME=? ORDER BY INDEX_CODE ASC `
  48. _, err = o.Raw(sql, breedShortName, frequency).QueryRows(&items)
  49. return
  50. }
  51. }
  52. func GetGlFrequency(productName string) (items []*string, err error) {
  53. sql := `SELECT DISTINCT FREQUENCY_NAME FROM mb_index_main_info WHERE BREED_SHORT_NAME=? ORDER BY FIELD(FREQUENCY_NAME,'日度','周度','旬度','月度','季度','半年','年度') `
  54. o := orm.NewOrmUsingDB("gl")
  55. _, err = o.Raw(sql, productName).QueryRows(&items)
  56. return
  57. }
  58. type GlIndexList struct {
  59. Id int `orm:"column(ID)"`
  60. IndexCode string `orm:"column(INDEX_CODE)"`
  61. IndexName string `orm:"column(INDEX_NAME)"`
  62. UnitName string `orm:"column(UNIT_NAME)"`
  63. FrequencyName string `orm:"column(FREQUENCY_NAME)"`
  64. UpdateTime string `orm:"column(UPDATE_TIME)"`
  65. Paging *paging.PagingItem `description:"分页数据"`
  66. DataList []*GlIndexData
  67. }
  68. type GlIndexData struct {
  69. InputValue string `orm:"column(DATA_VALUE)" description:"日期"`
  70. DataTime string `orm:"column(DATA_DATE)" description:"值"`
  71. }
  72. func GetGlIndexData(indexCode string, startSize, pageSize int) (items []*GlIndexData, err error) {
  73. //sql := ` SELECT * FROM mb_index_main_data WHERE INDEX_CODE=? ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC LIMIT ?,?`
  74. sql := ` SELECT * FROM (
  75. SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=? AND IS_DELETE=0
  76. ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
  77. )AS t
  78. GROUP BY t.DATA_DATE
  79. ORDER BY t.DATA_DATE DESC LIMIT ?,? `
  80. o := orm.NewOrmUsingDB("gl")
  81. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  82. return
  83. }
  84. func GetGlIndexByCode(indexCode string) (items *GlIndex, err error) {
  85. sql := ` SELECT * FROM mb_index_main_info WHERE INDEX_CODE=? `
  86. o := orm.NewOrmUsingDB("gl")
  87. err = o.Raw(sql, indexCode).QueryRow(&items)
  88. return
  89. }
  90. func GetGlIndexDataCount(indexCode string) (count int, err error) {
  91. o := orm.NewOrmUsingDB("gl")
  92. sql := `SELECT COUNT(1) AS count FROM (
  93. SELECT * FROM (
  94. SELECT DISTINCT a.INDEX_CODE,a.DATA_VALUE,a.DATA_DATE FROM mb_index_main_data AS a WHERE INDEX_CODE=? AND IS_DELETE=0
  95. ORDER BY DATA_DATE DESC,PUBLISH_TIME DESC
  96. )AS t
  97. GROUP BY t.DATA_DATE
  98. ORDER BY t.DATA_DATE DESC
  99. )AS n `
  100. err = o.Raw(sql, indexCode).QueryRow(&count)
  101. return
  102. }
  103. type GlSearchIndex struct {
  104. Id int `orm:"column(ID)"`
  105. IndexCode string `orm:"column(INDEX_CODE)"`
  106. IndexName string `orm:"column(INDEX_NAME)"`
  107. UnitName string `orm:"column(UNIT_NAME)"`
  108. FrequencyName string `orm:"column(FREQUENCY_NAME)"`
  109. UpdateTime string `orm:"column(UPDATE_TIME)"`
  110. BreedShortName string `orm:"column(BREED_SHORT_NAME)"`
  111. StartDate string `orm:"column(BEGIN_DATE)"`
  112. EndDate string `orm:"column(END_DATE)"`
  113. LatestValue float64 `orm:"column(DATA_VALUE)"`
  114. CreateTime string `orm:"column(CREATE_TIME)"`
  115. ModifyTime string `orm:"column(UPDATE_TIME)"`
  116. Source int
  117. SourceName string
  118. SearchText string `description:"搜索结果(含高亮)"`
  119. }
  120. // GetGlItemList 模糊查询隆众数据库指标列表
  121. func GetGlItemList(keyword string) (items []*GlSearchIndex, err error) {
  122. o := orm.NewOrmUsingDB("gl")
  123. sql := "SELECT * FROM mb_index_main_info WHERE CONCAT(INDEX_NAME,INDEX_CODE) LIKE ? "
  124. _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  125. return
  126. }
  127. func GetGlDataMaxCount(classifyName string) (count int, err error) {
  128. o := orm.NewOrmUsingDB("gl")
  129. sql := `SELECT MAX(t.num) AS count FROM (
  130. SELECT COUNT(1) AS num FROM mb_index_main_info AS a
  131. INNER JOIN mb_index_main_data AS b ON a.INDEX_CODE=b.INDEX_CODE
  132. WHERE a.BREED_SHORT_NAME=?
  133. GROUP BY a.INDEX_CODE
  134. )AS t `
  135. err = o.Raw(sql, classifyName).QueryRow(&count)
  136. return
  137. }
  138. func GetGlDataByCode(indexCode string) (items []*GlIndexData, err error) {
  139. o := orm.NewOrmUsingDB("gl")
  140. sql := `SELECT
  141. *
  142. FROM
  143. ( SELECT * FROM mb_index_main_data WHERE INDEX_CODE = ? GROUP BY UPDATE_TIME DESC, DATA_DATE DESC ) a
  144. GROUP BY
  145. a.DATA_DATE DESC `
  146. _, err = o.Raw(sql, indexCode).QueryRows(&items)
  147. return
  148. }
  149. // GlDataPageListResp 钢联原始指标库-分页列表
  150. type GlDataPageListResp struct {
  151. Paging *paging.PagingItem
  152. List []*GlSearchIndex
  153. }
  154. // GetGlItemListByIds IDs获取钢联原始指标库
  155. func GetGlItemListByIds(ids []int) (items []*GlSearchIndex, err error) {
  156. if len(ids) == 0 {
  157. return
  158. }
  159. o := orm.NewOrmUsingDB("gl")
  160. sql := fmt.Sprintf(`SELECT * FROM mb_index_main_info WHERE ID IN (%s)`, utils.GetOrmInReplace(len(ids)))
  161. _, err = o.Raw(sql, ids).QueryRows(&items)
  162. return
  163. }