smm_data.go 3.6 KB

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