gl_data.go 5.7 KB

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