base_from_smm.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package data_manage
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/orm"
  4. "time"
  5. )
  6. type BaseFromSmm struct {
  7. BaseFromSmmId int `orm:"column(base_from_smm_id);pk"`
  8. Aid int
  9. Name string
  10. Interface string
  11. ApiUpdate int
  12. ApiUpdateType string
  13. ApiType int
  14. ApiTypeAll string
  15. Type1 string `orm:"column(type_1)"`
  16. Type2 string `orm:"column(type_2)"`
  17. Type3 string `orm:"column(type_3)"`
  18. ApiStartTime string
  19. ApiUpdateTime string
  20. StartTime string
  21. FinishTime string
  22. AuthModule string
  23. AuthLang string
  24. ApiLabel string
  25. Enable string
  26. EditPerson string
  27. EditTime string
  28. AuthDur int
  29. AuthDurType string
  30. }
  31. func AddBaseFromSmm(item *BaseFromSmm) (lastId int64, err error) {
  32. o := orm.NewOrm()
  33. o.Using("data")
  34. lastId, err = o.Insert(item)
  35. return
  36. }
  37. func GetBaseFromSmmList() (list []*BaseFromSmm, err error) {
  38. o := orm.NewOrm()
  39. o.Using("data")
  40. sql := `SELECT * FROM base_from_smm `
  41. _, err = o.Raw(sql).QueryRows(&list)
  42. return
  43. }
  44. func GetBaseFromSmmBySmmCode(smmCode string) (item *BaseFromSmm, err error) {
  45. o := orm.NewOrm()
  46. o.Using("data")
  47. sql := `SELECT * FROM base_from_smm WHERE interface=?`
  48. err = o.Raw(sql, smmCode).QueryRow(&item)
  49. return
  50. }
  51. type BaseFromSmmIndex struct {
  52. BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
  53. Interface string
  54. Name string
  55. IndexCode string
  56. IndexName string
  57. Type1 string `orm:"column(type_1)"`
  58. Type2 string `orm:"column(type_2)"`
  59. Type3 string `orm:"column(type_3)"`
  60. Frequency string
  61. Unit string
  62. ApiStartTime string
  63. ApiUpdateTime string
  64. StartTime string
  65. FinishTime string
  66. CreateTime time.Time
  67. ModifyTime time.Time
  68. }
  69. func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
  70. o := orm.NewOrm()
  71. o.Using("data")
  72. lastId, err = o.Insert(item)
  73. return
  74. }
  75. func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) {
  76. o := orm.NewOrm()
  77. o.Using("data")
  78. sql := `SELECT * FROM base_from_smm_index `
  79. _, err = o.Raw(sql).QueryRows(&list)
  80. return
  81. }
  82. type BaseFromSmmData struct {
  83. SmmDataId int `orm:"column(smm_data_id);pk"`
  84. BaseFromSmmIndexId int
  85. IndexCode string
  86. DataTime string
  87. Value string
  88. CreateTime time.Time
  89. ModifyTime time.Time
  90. DataTimestamp int64
  91. }
  92. func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) {
  93. o := orm.NewOrm()
  94. o.Using("data")
  95. lastId, err = o.Insert(item)
  96. return
  97. }
  98. func GetBaseFromSmmDataAll() (list []*BaseFromSmmData, err error) {
  99. o := orm.NewOrm()
  100. o.Using("data")
  101. sql := `SELECT * FROM base_from_smm_data `
  102. _, err = o.Raw(sql).QueryRows(&list)
  103. return
  104. }
  105. func ModifyBaseFromSmmData(smmDataId int, value string) (err error) {
  106. o := orm.NewOrm()
  107. o.Using("data")
  108. sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? `
  109. _, err = o.Raw(sql, value, smmDataId).Exec()
  110. return
  111. }
  112. func GetBaseFromSmmIndexBySmmCode(smmCode string) (list []*BaseFromSmmIndex, err error) {
  113. o := orm.NewOrm()
  114. o.Using("data")
  115. sql := ` SELECT * FROM base_from_smm_index WHERE interface=? `
  116. _, err = o.Raw(sql, smmCode).QueryRows(&list)
  117. return
  118. }
  119. func GetBaseFromSmmMaxOrMinDate(indexCode string) (min_date, max_date string, err error) {
  120. o := orm.NewOrm()
  121. o.Using("data")
  122. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? `
  123. err = o.Raw(sql, indexCode).QueryRow(&min_date, &max_date)
  124. return
  125. }
  126. func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId int, minDate, maxDate string) (err error) {
  127. o := orm.NewOrm()
  128. o.Using("data")
  129. sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? `
  130. _, err = o.Raw(sql, minDate, maxDate, baseFromSmmIndexId).Exec()
  131. return
  132. }
  133. func GetBaseFromSmmDataAllByIndexCode(indexCode string) (list []*BaseFromSmmData, err error) {
  134. o := orm.NewOrm()
  135. o.Using("data")
  136. sql := `SELECT * FROM base_from_smm_data WHERE index_code=? `
  137. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  138. return
  139. }
  140. func GetBaseFromSmmIndexByIndexCode(indexCode string) (list *BaseFromSmmIndex, err error) {
  141. o := orm.NewOrm()
  142. o.Using("data")
  143. sql := ` SELECT * FROM base_from_smm_index WHERE index_code=? `
  144. err = o.Raw(sql, indexCode).QueryRow(&list)
  145. return
  146. }