base_from_trade_eic.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package models
  2. import (
  3. "fmt"
  4. "hongze/hongze_data_crawler/utils"
  5. "rdluck_tools/orm"
  6. "time"
  7. )
  8. type BaseFromTradeEicIndex struct {
  9. BaseFromEicIndexId int `orm:"column(base_from_eic_index_id);pk"`
  10. Country string
  11. Type string
  12. EicCode string
  13. ShortName string
  14. Name string
  15. Status string
  16. GasDayStartedOn string
  17. GasInStorage float64
  18. Full float64
  19. Trend float64
  20. Injection float64
  21. Withdrawal float64
  22. WorkingGasVolume float64
  23. InjectionCapacity float64
  24. WithdrawalCapacity float64
  25. Info string
  26. CreateTime time.Time
  27. ModifyTime time.Time
  28. }
  29. type BaseFromTradeMapping struct {
  30. BaseFromTradeMappingId int `orm:"column(base_from_trade_mapping_id);pk"`
  31. IndexName string
  32. IndexCode string
  33. Exchange string
  34. }
  35. func AddBaseFromEicIndex(item *BaseFromTradeEicIndex) (lastId int64, err error) {
  36. o := orm.NewOrm()
  37. o.Using("data")
  38. lastId, err = o.Insert(item)
  39. return
  40. }
  41. func GetSSOFromEicIndexAll(name string) (list []*BaseFromTradeEicIndex, err error) {
  42. o := orm.NewOrm()
  43. o.Using("data")
  44. sql := `SELECT * FROM base_from_trade_eic_index where name=? and type='SSO'`
  45. _, err = o.Raw(sql, name).QueryRows(&list)
  46. return
  47. }
  48. func GetFacFromEicIndexAll(name string) (list []*BaseFromTradeEicIndex, err error) {
  49. o := orm.NewOrm()
  50. o.Using("data")
  51. sql := `SELECT * FROM base_from_trade_eic_index where name=? and type='Storage Facility'`
  52. _, err = o.Raw(sql, name).QueryRows(&list)
  53. return
  54. }
  55. func ModifyBaseFromEicIndex(gasInStorage, full, trend, injection, withdrawal float64, dataId int) (err error) {
  56. o := orm.NewOrm()
  57. o.Using("data")
  58. sql := `UPDATE base_from_trade_eic_index SET gas_in_storage=?,full=?,trend=?,injection=?,withdrawal=?,modify_time=NOW() WHERE base_from_eic_index_id=? `
  59. _, err = o.Raw(sql, gasInStorage, full, trend, injection, withdrawal, dataId).Exec()
  60. return
  61. }
  62. func GetCountryFromEicIndexAll(name string) (list []*BaseFromTradeEicIndex, err error) {
  63. o := orm.NewOrm()
  64. o.Using("data")
  65. sql := `SELECT * FROM base_from_trade_eic_index where country=? and (type='country' or type='continent')`
  66. _, err = o.Raw(sql, name).QueryRows(&list)
  67. return
  68. }
  69. func GetEicAddSql(item *BaseFromTradeEicIndex) (addSql string) {
  70. addSql += "('" + item.Country + "','" + item.Type + "','" + item.EicCode + "','" + item.ShortName + "','" + item.Name + "','" + item.Status + "','" + item.GasDayStartedOn + "','" + fmt.Sprintf("%f", item.GasInStorage) + "','" + fmt.Sprintf("%f", item.Full) + "','" + fmt.Sprintf("%f", item.Trend) + "','" + fmt.Sprintf("%f", item.Injection) + "','" + fmt.Sprintf("%f", item.Withdrawal) + "','" + fmt.Sprintf("%f", item.WorkingGasVolume) + "','" + fmt.Sprintf("%f", item.InjectionCapacity) + "','" + fmt.Sprintf("%f", item.WithdrawalCapacity) + "','" + item.Info + "','" + item.CreateTime.Format(utils.FormatDateTime) + "','" + item.ModifyTime.Format(utils.FormatDateTime) + "'),"
  71. return
  72. }
  73. func GetMappingAddSql(indexName, indexCode, exchange string) (addSql string) {
  74. addSql += "('" + indexName + "','" + indexCode + "','" + exchange + "'),"
  75. return
  76. }
  77. func AddEicDataMulti(items []*BaseFromTradeEicIndex) (successNums int64, err error) {
  78. o := orm.NewOrm()
  79. o.Using("data")
  80. successNums, err = o.InsertMulti(1, items)
  81. return
  82. }
  83. func AddEicCodeMulti(items []*BaseFromTradeMapping) (successNums int64, err error) {
  84. o := orm.NewOrm()
  85. o.Using("data")
  86. successNums, err = o.InsertMulti(1, items)
  87. return
  88. }