base_from_pb.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/http"
  6. "hongze/hongze_edb_lib/utils"
  7. "net/url"
  8. )
  9. type EdbDataFromPb struct {
  10. Date map[string]int64 `json:"date"`
  11. Ticker map[string]string `json:"ticker"`
  12. Field map[string]string `json:"field"`
  13. Value map[string]float64 `json:"value"`
  14. }
  15. // GetEdbDataFromPb 获取Pb数据
  16. func GetEdbDataFromPb(edbCode, startDate, endDate string) (item *EdbDataFromPb, err error) {
  17. edbCode = url.QueryEscape(edbCode)
  18. bpUrl := utils.Hz_Pb_Data_Url + `edbInfo/pb?EdbCode=%s&StartDate=%s&EndDate=%s`
  19. bpUrl = fmt.Sprintf(bpUrl, edbCode, startDate, endDate)
  20. utils.FileLog.Info("bpUrl:%s", bpUrl)
  21. body, err := http.Get(bpUrl)
  22. if err != nil {
  23. utils.FileLog.Info("GetEdbDataByPb Err:%s", err.Error())
  24. return
  25. }
  26. utils.FileLog.Info("GetEdbDataByPb result:%s", string(body))
  27. item = new(EdbDataFromPb)
  28. err = json.Unmarshal(body, &item)
  29. if err != nil {
  30. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:%s", err.Error())
  31. return
  32. }
  33. edbCode, _ = url.QueryUnescape(edbCode)
  34. return
  35. }