gl_data.go 5.7 KB

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