base_from_pb.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_index_lib/models"
  6. "eta/eta_index_lib/utils"
  7. "fmt"
  8. "github.com/rdlucklib/rdluck_tools/http"
  9. "net/url"
  10. )
  11. // GetEdbDataFromPb 获取Pb数据
  12. func GetEdbDataFromPb(edbCode, startDate, endDate string) (item *models.EdbDataFromPb, err error) {
  13. if utils.Hz_Pb_Data_Url == `` {
  14. err = errors.New("彭博接口未配置")
  15. return
  16. }
  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:" + bpUrl)
  21. body, err := http.Get(bpUrl)
  22. if err != nil {
  23. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  24. return
  25. }
  26. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  27. item = new(models.EdbDataFromPb)
  28. err = json.Unmarshal(body, &item)
  29. if err != nil {
  30. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  31. return
  32. }
  33. edbCode, _ = url.QueryUnescape(edbCode)
  34. return
  35. }
  36. // GetEdbDataFromPbFinance 获取Pb财务数据
  37. func GetEdbDataFromPbFinance(companyCode, edbCode, startDate, endDate string) (item *models.EdbDataFromPb, err error) {
  38. if utils.Hz_Pb_Data_Url == `` {
  39. err = errors.New("彭博接口未配置")
  40. return
  41. }
  42. companyCode = url.QueryEscape(companyCode)
  43. edbCode = url.QueryEscape(edbCode)
  44. bpUrl := utils.Hz_Pb_Data_Url + `edbInfo/pb/finance?CompanyCode=%s&EdbCode=%s&StartDate=%s&EndDate=%s`
  45. bpUrl = fmt.Sprintf(bpUrl, companyCode, edbCode, startDate, endDate)
  46. utils.FileLog.Info("bpUrl:" + bpUrl)
  47. body, err := http.Get(bpUrl)
  48. if err != nil {
  49. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  50. return
  51. }
  52. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  53. item = new(models.EdbDataFromPb)
  54. err = json.Unmarshal(body, &item)
  55. if err != nil {
  56. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  57. return
  58. }
  59. edbCode, _ = url.QueryUnescape(edbCode)
  60. return
  61. }