edb_data_lt.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package data_manage
  2. import (
  3. "encoding/json"
  4. "eta/eta_task/utils"
  5. "fmt"
  6. "github.com/beego/beego/v2/client/orm"
  7. "github.com/rdlucklib/rdluck_tools/http"
  8. "time"
  9. )
  10. type EdbDataLt struct {
  11. EdbDataId int `orm:"column(edb_data_id);pk"`
  12. EdbInfoId int
  13. EdbCode string
  14. DataTime string
  15. Value float64
  16. Status int
  17. CreateTime time.Time
  18. ModifyTime time.Time
  19. DataTimestamp int64
  20. }
  21. // AddEdbDataLtBySql 执行添加数据的sql
  22. func AddEdbDataLtBySql(sqlStr string) (err error) {
  23. o := orm.NewOrm()
  24. _, err = o.Raw(sqlStr).Exec()
  25. return
  26. }
  27. // ModifyEdbDataLt 修改路透社数据
  28. func ModifyEdbDataLt(edbInfoId int64, dataTime string, value float64) (err error) {
  29. o := orm.NewOrm()
  30. sql := ` UPDATE edb_data_lt SET value=?,modify_time=NOW() WHERE edb_info_id=? AND data_time=? `
  31. _, err = o.Raw(sql, value, edbInfoId, dataTime).Exec()
  32. return
  33. }
  34. func GetEdbDataLtMaxOrMinDate(edbCode string) (min_date, max_date string, err error) {
  35. o := orm.NewOrm()
  36. sql := ` SELECT MIN(data_time) AS min_date,MAX(data_time) AS max_date FROM edb_data_lt WHERE edb_code=? `
  37. err = o.Raw(sql, edbCode).QueryRow(&min_date, &max_date)
  38. return
  39. }
  40. func GetEdbDataLtByCodeAndDate(edbCode string, startDate string) (count int, err error) {
  41. o := orm.NewOrm()
  42. sql := ` SELECT COUNT(1) AS count FROM edb_data_lt WHERE edb_code=? AND data_time=? `
  43. err = o.Raw(sql, edbCode, startDate).QueryRow(&count)
  44. return
  45. }
  46. func GetEdbDataLtByCode(edbCode string, size int) (items []*EdbInfoSearchData, err error) {
  47. o := orm.NewOrm()
  48. sql := ` SELECT * FROM edb_data_lt WHERE edb_code=? ORDER BY data_time DESC LIMIT ? `
  49. _, err = o.Raw(sql, edbCode, size).QueryRows(&items)
  50. return
  51. }
  52. type EdbDataFromLt struct {
  53. Close map[int64]interface{} `json:"CLOSE"`
  54. }
  55. // QueryEdbDataByLt 获取路透社数据
  56. func QueryEdbDataByLt(edbCode, startDate, endDate string) (dataList map[int64]interface{}, err error) {
  57. dataList = make(map[int64]interface{})
  58. ltUrl := utils.LtServerUrl + `edbInfo/ek?EdbCode=%s&StartDate=%s&EndDate=%s`
  59. ltUrl = fmt.Sprintf(ltUrl, edbCode, startDate, endDate)
  60. utils.FileLog.Info("ltUrl:%s", ltUrl)
  61. body, err := http.Get(ltUrl)
  62. utils.FileLog.Info("lt result:%s", string(body))
  63. if err != nil {
  64. return
  65. }
  66. //fmt.Println(string(body))
  67. item := new(EdbDataFromLt)
  68. err = json.Unmarshal(body, &item)
  69. if err != nil {
  70. return
  71. }
  72. dataList = item.Close
  73. return
  74. }