base_from_pb.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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:" + 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(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 *EdbDataFromPb, err error) {
  38. companyCode = url.QueryEscape(companyCode)
  39. edbCode = url.QueryEscape(edbCode)
  40. bpUrl := utils.Hz_Pb_Data_Url + `edbInfo/pb/finance?CompanyCode=%s&EdbCode=%s&StartDate=%s&EndDate=%s`
  41. bpUrl = fmt.Sprintf(bpUrl, companyCode, edbCode, startDate, endDate)
  42. utils.FileLog.Info("bpUrl:" + bpUrl)
  43. body, err := http.Get(bpUrl)
  44. if err != nil {
  45. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  46. return
  47. }
  48. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  49. item = new(EdbDataFromPb)
  50. err = json.Unmarshal(body, &item)
  51. if err != nil {
  52. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  53. return
  54. }
  55. edbCode, _ = url.QueryUnescape(edbCode)
  56. return
  57. }