base_from_pb.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/http"
  6. "hongze/hongze_edb_lib/models"
  7. "hongze/hongze_edb_lib/utils"
  8. "net/url"
  9. )
  10. // GetEdbDataFromPb 获取Pb数据
  11. func GetEdbDataFromPb(edbCode, startDate, endDate string) (item *models.EdbDataFromPb, err error) {
  12. edbCode = url.QueryEscape(edbCode)
  13. bpUrl := utils.Hz_Pb_Data_Url + `edbInfo/pb?EdbCode=%s&StartDate=%s&EndDate=%s`
  14. bpUrl = fmt.Sprintf(bpUrl, edbCode, startDate, endDate)
  15. utils.FileLog.Info("bpUrl:" + bpUrl)
  16. body, err := http.Get(bpUrl)
  17. if err != nil {
  18. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  19. return
  20. }
  21. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  22. item = new(models.EdbDataFromPb)
  23. err = json.Unmarshal(body, &item)
  24. if err != nil {
  25. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  26. return
  27. }
  28. edbCode, _ = url.QueryUnescape(edbCode)
  29. return
  30. }
  31. // GetEdbDataFromPbFinance 获取Pb财务数据
  32. func GetEdbDataFromPbFinance(companyCode, edbCode, startDate, endDate string) (item *models.EdbDataFromPb, err error) {
  33. companyCode = url.QueryEscape(companyCode)
  34. edbCode = url.QueryEscape(edbCode)
  35. bpUrl := utils.Hz_Pb_Data_Url + `edbInfo/pb/finance?CompanyCode=%s&EdbCode=%s&StartDate=%s&EndDate=%s`
  36. bpUrl = fmt.Sprintf(bpUrl, companyCode, edbCode, startDate, endDate)
  37. utils.FileLog.Info("bpUrl:" + bpUrl)
  38. body, err := http.Get(bpUrl)
  39. if err != nil {
  40. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  41. return
  42. }
  43. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  44. item = new(models.EdbDataFromPb)
  45. err = json.Unmarshal(body, &item)
  46. if err != nil {
  47. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  48. return
  49. }
  50. edbCode, _ = url.QueryUnescape(edbCode)
  51. return
  52. }