base_from_smm.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package data_manage
  2. import (
  3. "eta_gn/eta_task/global"
  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.NewOrm()
  35. //lastId, err = o.Insert(item)
  36. err = global.DEFAULT_DmSQL.Create(item).Error
  37. if err != nil {
  38. return
  39. }
  40. lastId = int64(item.BaseFromSmmId)
  41. return
  42. }
  43. func GetBaseFromSmmList() (list []*BaseFromSmm, err error) {
  44. //o := orm.NewOrm()
  45. //sql := `SELECT * FROM base_from_smm WHERE interface='cu_annual_copper_cathode_demand_supply_balance_in_china' `
  46. sql := `SELECT * FROM base_from_smm WHERE end_date IS NOT NULL `
  47. //_, err = o.Raw(sql).QueryRows(&list)
  48. err = global.DEFAULT_DmSQL.Raw(sql).Find(&list).Error
  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. //lastId, err = o.Insert(item)
  72. err = global.DEFAULT_DmSQL.Create(item).Error
  73. if err != nil {
  74. return
  75. }
  76. lastId = int64(item.BaseFromSmmIndexId)
  77. return
  78. }
  79. func GetBaseFromSmmIndex() (list []*BaseFromSmmIndex, err error) {
  80. //o := orm.NewOrm()
  81. sql := `SELECT * FROM base_from_smm_index `
  82. //_, err = o.Raw(sql).QueryRows(&list)
  83. err = global.DEFAULT_DmSQL.Raw(sql).Find(&list).Error
  84. return
  85. }
  86. type BaseFromSmmData struct {
  87. SmmDataId int `orm:"column(smm_data_id);pk"`
  88. BaseFromSmmIndexId int
  89. IndexCode string
  90. DataTime string
  91. Value string
  92. CreateTime time.Time
  93. ModifyTime time.Time
  94. DataTimestamp int64
  95. }
  96. func AddBaseFromSmmData(item *BaseFromSmmData) (lastId int64, err error) {
  97. //o := orm.NewOrm()
  98. //lastId, err = o.Insert(item)
  99. err = global.DEFAULT_DmSQL.Create(item).Error
  100. if err != nil {
  101. return
  102. }
  103. lastId = int64(item.SmmDataId)
  104. return
  105. }
  106. func GetBaseFromSmmDataAll(indexCode string) (list []*BaseFromSmmData, err error) {
  107. //o := orm.NewOrm()
  108. sql := `SELECT * FROM base_from_smm_data WHERE index_code=?`
  109. //_, err = o.Raw(sql, indexCode).QueryRows(&list)
  110. err = global.DEFAULT_DmSQL.Raw(sql, indexCode).Find(&list).Error
  111. return
  112. }
  113. func ModifyBaseFromSmmData(smmDataId int, value string) (err error) {
  114. //o := orm.NewOrm()
  115. sql := `UPDATE base_from_smm_data SET value=?,modify_time=NOW() WHERE smm_data_id=? `
  116. //_, err = o.Raw(sql, value, smmDataId).Exec()
  117. err = global.DEFAULT_DmSQL.Exec(sql, value, smmDataId).Error
  118. return
  119. }
  120. func GetBaseFromSmmIndexByCode(smmCode string) (list []*BaseFromSmmIndex, err error) {
  121. //o := orm.NewOrm()
  122. sql := ` SELECT * FROM base_from_smm_index WHERE interface=? `
  123. //_, err = o.Raw(sql, smmCode).QueryRows(&list)
  124. err = global.DEFAULT_DmSQL.Raw(sql, smmCode).Find(&list).Error
  125. return
  126. }
  127. func GetBaseFromSmmMaxOrMinDate(indexCode string) (min_date, max_date string, err error) {
  128. //o := orm.NewOrm()
  129. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM base_from_smm_data WHERE index_code=? `
  130. //err = o.Raw(sql, indexCode).QueryRow(&min_date, &max_date)
  131. err = global.DEFAULT_DmSQL.Raw(sql, indexCode).First(min_date, &max_date).Error
  132. return
  133. }
  134. func ModifyBaseFromSmmSmmType(baseFromSmmId int, smmType string) (err error) {
  135. //o := orm.NewOrm()
  136. sql := ` UPDATE base_from_smm SET smm_type=? WHERE base_from_smm_id=? `
  137. //_, err = o.Raw(sql, smmType, baseFromSmmId).Exec()
  138. err = global.DEFAULT_DmSQL.Exec(sql, smmType, baseFromSmmId).Error
  139. return
  140. }
  141. func ModifyBaseFromSmmMinDateAndMaxDate(baseFromSmmIndexId, baseFromSmmId int, minDate, maxDate string) (err error) {
  142. to := global.DEFAULT_DmSQL.Begin()
  143. defer func() {
  144. if err != nil {
  145. _ = to.Rollback()
  146. } else {
  147. _ = to.Commit()
  148. }
  149. }()
  150. //o := orm.NewOrm()
  151. sql := ` UPDATE base_from_smm_index SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_index_id=? `
  152. //_, err = o.Raw(sql, minDate, maxDate, baseFromSmmIndexId).Exec()
  153. err = to.Exec(sql, minDate, maxDate, baseFromSmmIndexId).Error
  154. if err != nil {
  155. return
  156. }
  157. sql = ` UPDATE base_from_smm SET start_date=?,end_date=?,modify_time=NOW() WHERE base_from_smm_id=? `
  158. //_, err = o.Raw(sql, minDate, maxDate, baseFromSmmId).Exec()
  159. err = to.Exec(sql, minDate, maxDate, baseFromSmmId).Error
  160. return
  161. }
  162. type BaseFromSmmDataSimple struct {
  163. SmmDataId int `orm:"column(smm_data_id);pk"`
  164. BaseFromSmmIndexId int
  165. IndexCode string
  166. DataTime string
  167. Value float64
  168. }
  169. func GetBaseFromSmmDataByCondition(condition string, pars []interface{}) (list []*BaseFromSmmDataSimple, err error) {
  170. //o := orm.NewOrm()
  171. sql := `SELECT * FROM base_from_smm_data WHERE 1=1 `
  172. if condition != "" {
  173. sql += condition
  174. }
  175. //_, err = o.Raw(sql, pars).QueryRows(&list)
  176. err = global.DEFAULT_DmSQL.Raw(sql, pars).Find(&list).Error
  177. return
  178. }