smm_data.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "strings"
  6. )
  7. type SmmClassify struct {
  8. TypeName string `orm:"column(type_name)" description:"分类名称"`
  9. TypeCode string `orm:"column(type_code)" description:"分类名称编码"`
  10. }
  11. func GetSmmClassify() (items []*SmmClassify, err error) {
  12. sql := `SELECT CONCAT(type_2,type_3) AS type_name,CONCAT(type_2,'#',type_3) type_code FROM base_from_smm_index GROUP BY CONCAT(type_2,type_3) ORDER BY CONCAT(type_2,type_3) ASC `
  13. o := orm.NewOrmUsingDB("data")
  14. o.Raw(sql).QueryRows(&items)
  15. return
  16. }
  17. type SmmFrequency struct {
  18. Frequency string `description:"频度"`
  19. }
  20. func GetSmmFrequencyByClassifyId(typeCode string) (items []*GlFrequency, err error) {
  21. o := orm.NewOrmUsingDB("data")
  22. var type2, type3 string
  23. if strings.Contains(typeCode, "#") {
  24. typeArr := strings.Split(typeCode, "#")
  25. type2 = typeArr[0]
  26. type3 = typeArr[1]
  27. } else {
  28. type2 = typeCode
  29. }
  30. var condition string
  31. var pars []interface{}
  32. if type2 != "" {
  33. condition += ` AND type_2=? `
  34. pars = append(pars, type2)
  35. }
  36. if type3 != "" {
  37. condition += ` AND type_3=? `
  38. pars = append(pars, type3)
  39. }
  40. sql := ` SELECT frequency FROM base_from_smm_index WHERE 1=1 `
  41. if condition != "" {
  42. sql += condition
  43. }
  44. sql += ` GROUP BY frequency ORDER BY frequency ASC `
  45. _, err = o.Raw(sql, pars).QueryRows(&items)
  46. return
  47. }
  48. type SmmIndex struct {
  49. BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
  50. Interface string
  51. Name string
  52. IndexCode string
  53. IndexName string
  54. Type1 string `orm:"column(type_1)"`
  55. Type2 string `orm:"column(type_2)"`
  56. Type3 string `orm:"column(type_3)"`
  57. Frequency string
  58. Unit string
  59. ApiStartTime string
  60. ApiUpdateTime string
  61. StartTime string
  62. FinishTime string
  63. CreateTime string
  64. ModifyTime string
  65. }
  66. func GetSmmIndex(condition string, pars interface{}) (items []*SmmIndex, err error) {
  67. o := orm.NewOrmUsingDB("data")
  68. sql := ` SELECT * FROM base_from_smm_index WHERE 1=1 `
  69. if condition != "" {
  70. sql += condition
  71. }
  72. sql += `ORDER BY INDEX_CODE ASC`
  73. _, err = o.Raw(sql, pars).QueryRows(&items)
  74. return
  75. }
  76. type SmmIndexList struct {
  77. BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
  78. Interface string
  79. Name string
  80. IndexCode string
  81. IndexName string
  82. Type1 string `orm:"column(type_1)"`
  83. Type2 string `orm:"column(type_2)"`
  84. Type3 string `orm:"column(type_3)"`
  85. Frequency string
  86. Unit string
  87. ApiStartTime string
  88. ApiUpdateTime string
  89. StartTime string
  90. FinishTime string
  91. ModifyTime string
  92. DataList []*SmmIndexData
  93. Paging *paging.PagingItem `description:"分页数据"`
  94. }
  95. type SmmIndexData struct {
  96. Value string `orm:"column(value)" description:"日期"`
  97. DataTime string `orm:"column(data_time)" description:"值"`
  98. }
  99. func GetSmmIndexData(indexCode string, startSize, pageSize int) (items []*SmmIndexData, err error) {
  100. o := orm.NewOrmUsingDB("data")
  101. sql := ` SELECT * FROM base_from_smm_data WHERE index_code=? ORDER BY data_time DESC LIMIT ?,? `
  102. _, err = o.Raw(sql, indexCode, startSize, pageSize).QueryRows(&items)
  103. return
  104. }
  105. func GetSmmIndexDataCount(indexCode string) (count int, err error) {
  106. o := orm.NewOrmUsingDB("data")
  107. sql := ` SELECT COUNT(1) AS count FROM base_from_smm_data WHERE index_code=? `
  108. err = o.Raw(sql, indexCode).QueryRow(&count)
  109. return
  110. }