base_from_pb.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_index_lib/models"
  5. "eta/eta_index_lib/utils"
  6. "fmt"
  7. "github.com/rdlucklib/rdluck_tools/http"
  8. "net/url"
  9. )
  10. // GetEdbDataFromPb 获取Pb数据
  11. func GetEdbDataFromPb(edbCode, startDate, endDate, edbTerminalCode string) (item *models.EdbDataFromPb, err error) {
  12. /* if utils.Hz_Pb_Data_Url == `` {
  13. err = errors.New("彭博接口未配置")
  14. return
  15. }*/
  16. terminal, err := GetTerminal(utils.DATA_SOURCE_PB, edbTerminalCode)
  17. if err != nil {
  18. err = fmt.Errorf("获取彭博接口配置出错 Err: %s", err)
  19. return
  20. }
  21. if terminal.ServerUrl == "" {
  22. err = fmt.Errorf("彭博接口未配置")
  23. return
  24. }
  25. if edbTerminalCode == "" {
  26. // 设置指标与终端关系的缓存
  27. terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + edbCode
  28. _ = utils.Rc.Put(terminalCodeCacheKey, terminal.TerminalCode, utils.GetTodayLastSecond())
  29. }
  30. edbCode = url.QueryEscape(edbCode)
  31. bpUrl := terminal.ServerUrl + `edbInfo/pb?EdbCode=%s&StartDate=%s&EndDate=%s`
  32. bpUrl = fmt.Sprintf(bpUrl, edbCode, startDate, endDate)
  33. utils.FileLog.Info("bpUrl:" + bpUrl)
  34. body, err := http.Get(bpUrl)
  35. if err != nil {
  36. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  37. return
  38. }
  39. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  40. item = new(models.EdbDataFromPb)
  41. err = json.Unmarshal(body, &item)
  42. if err != nil {
  43. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  44. return
  45. }
  46. edbCode, _ = url.QueryUnescape(edbCode)
  47. return
  48. }
  49. // GetEdbDataFromPbFinance 获取Pb财务数据
  50. func GetEdbDataFromPbFinance(companyCode, edbCode, startDate, endDate, edbTerminalCode string) (item *models.EdbDataFromPb, err error) {
  51. /*if utils.Hz_Pb_Data_Url == `` {
  52. err = errors.New("彭博接口未配置")
  53. return
  54. }*/
  55. terminal, err := GetTerminal(utils.DATA_SOURCE_PB_FINANCE, edbTerminalCode)
  56. if err != nil {
  57. err = fmt.Errorf("获取彭博接口配置出错 Err: %s", err)
  58. return
  59. }
  60. if terminal.ServerUrl == "" {
  61. err = fmt.Errorf("彭博接口未配置")
  62. return
  63. }
  64. if edbTerminalCode == "" {
  65. // 设置指标与终端关系的缓存
  66. terminalCodeCacheKey := utils.CACHE_EDB_TERMINAL_CODE_URL + companyCode + "&&" + edbCode
  67. _ = utils.Rc.Put(terminalCodeCacheKey, terminal.TerminalCode, utils.GetTodayLastSecond())
  68. }
  69. companyCode = url.QueryEscape(companyCode)
  70. edbCode = url.QueryEscape(edbCode)
  71. bpUrl := terminal.ServerUrl + `edbInfo/pb/finance?CompanyCode=%s&EdbCode=%s&StartDate=%s&EndDate=%s`
  72. bpUrl = fmt.Sprintf(bpUrl, companyCode, edbCode, startDate, endDate)
  73. utils.FileLog.Info("bpUrl:" + bpUrl)
  74. body, err := http.Get(bpUrl)
  75. if err != nil {
  76. utils.FileLog.Info("GetEdbDataByPb Err:" + err.Error())
  77. return
  78. }
  79. utils.FileLog.Info("GetEdbDataByPb result:" + string(body))
  80. item = new(models.EdbDataFromPb)
  81. err = json.Unmarshal(body, &item)
  82. if err != nil {
  83. utils.FileLog.Info("GetEdbDataByPb Unmarshal Err:" + err.Error())
  84. return
  85. }
  86. edbCode, _ = url.QueryUnescape(edbCode)
  87. return
  88. }