base_from_smm.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. package data_manage
  2. import (
  3. "github.com/beego/beego/v2/client/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. StartDate string
  31. EndDate string
  32. }
  33. func AddBaseFromSmm(item *BaseFromSmm) (lastId int64, err error) {
  34. o := orm.NewOrmUsingDB("data")
  35. lastId, err = o.Insert(item)
  36. return
  37. }
  38. func GetBaseFromSmmList() (list []*BaseFromSmm, err error) {
  39. o := orm.NewOrmUsingDB("data")
  40. //sql := `SELECT * FROM base_from_smm WHERE interface='cu_annual_copper_cathode_demand_supply_balance_in_china' `
  41. sql := `SELECT * FROM base_from_smm WHERE end_date IS NOT NULL `
  42. _, err = o.Raw(sql).QueryRows(&list)
  43. return
  44. }
  45. type BaseFromSmmIndex struct {
  46. BaseFromSmmIndexId int `orm:"column(base_from_smm_index_id);pk"`
  47. Interface string
  48. Name string
  49. IndexCode string
  50. IndexName string
  51. Type1 string `orm:"column(type_1)"`
  52. Type2 string `orm:"column(type_2)"`
  53. Type3 string `orm:"column(type_3)"`
  54. Frequency string
  55. Unit string
  56. ApiStartTime string
  57. ApiUpdateTime string
  58. StartTime string
  59. FinishTime string
  60. CreateTime time.Time
  61. ModifyTime time.Time
  62. }
  63. func AddBaseFromSmmIndex(item *BaseFromSmmIndex) (lastId int64, err error) {
  64. o := orm.NewOrmUsingDB("data")
  65. lastId, err = o.Insert(item)
  66. return
  67. }
  68. func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) {
  69. o := orm.NewOrmUsingDB("data")
  70. sql := `SELECT * FROM base_from_smm_index `
  71. _, err = o.Raw(sql).QueryRows(&list)
  72. return
  73. }
  74. type BaseFromSmmData struct {
  75. SmmDataId int `orm:"column(smm_data_id);pk"`
  76. BaseFromSmmIndexId int
  77. IndexCode string
  78. DataTime string
  79. Value string
  80. CreateTime time.Time
  81. ModifyTime time.Time
  82. DataTimestamp int64
  83. }
  84. func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) {
  85. o := orm.NewOrmUsingDB("data")
  86. lastId, err = o.Insert(item)
  87. return
  88. }
  89. func GetBaseFromSmmDataAll(indexCode string) (list []*BaseFromSmmData, err error) {
  90. o := orm.NewOrmUsingDB("data")
  91. sql := `SELECT * FROM base_from_smm_data WHERE index_code=?`
  92. _, err = o.Raw(sql, indexCode).QueryRows(&list)
  93. return
  94. }
  95. func ModifyBaseFromSmmData(smmDataId int, value string) (err error) {
  96. o := orm.NewOrmUsingDB("data")
  97. sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? `
  98. _, err = o.Raw(sql, value, smmDataId).Exec()
  99. return
  100. }
  101. func GetBaseFromSmmIndexByCode(smmCode string) (list []*BaseFromSmmIndex, err error) {
  102. o := orm.NewOrmUsingDB("data")
  103. sql := ` SELECT * FROM base_from_smm_index WHERE interface=? `
  104. _, err = o.Raw(sql, smmCode).QueryRows(&list)
  105. return
  106. }
  107. func GetBaseFromSmmMaxOrMinDate(indexCode string) (min_date, max_date string, err error) {
  108. o := orm.NewOrmUsingDB("data")
  109. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? `
  110. err = o.Raw(sql, indexCode).QueryRow(&min_date, &max_date)
  111. return
  112. }
  113. func ModifyBaseFromSmmSmmType(baseFromSmmId int, smmType string) (err error) {
  114. o := orm.NewOrmUsingDB("data")
  115. sql := ` UPDATE base_from_smm SET smm_type=? WHERE base_from_smm_id=? `
  116. _, err = o.Raw(sql, smmType, baseFromSmmId).Exec()
  117. return
  118. }
  119. func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId, baseFromSmmId int, minDate, maxDate string) (err error) {
  120. o := orm.NewOrmUsingDB("data")
  121. sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? `
  122. _, err = o.Raw(sql, minDate, maxDate, baseFromSmmIndexId).Exec()
  123. sql = ` UPDATE base_from_smm SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_id=? `
  124. _, err = o.Raw(sql, minDate, maxDate, baseFromSmmId).Exec()
  125. return
  126. }
  127. type BaseFromSmmDataSimple struct {
  128. SmmDataId int `orm:"column(smm_data_id);pk"`
  129. BaseFromSmmIndexId int
  130. IndexCode string
  131. DataTime string
  132. Value float64
  133. }
  134. func GetBaseFromSmmDataByCondition(condition string, pars []interface{}) (list []*BaseFromSmmDataSimple, err error) {
  135. o := orm.NewOrmUsingDB("data")
  136. sql := `SELECT * FROM base_from_smm_data WHERE 1=1 `
  137. if condition!="" {
  138. sql+=condition
  139. }
  140. _, err = o.Raw(sql, pars).QueryRows(&list)
  141. return
  142. }