chart.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package services
  2. import (
  3. "encoding/json"
  4. "eta/eta_hub/models/data_manage"
  5. "eta/eta_hub/utils"
  6. "fmt"
  7. "io/ioutil"
  8. "net/http"
  9. )
  10. // GetChartDetailFromChartLibByUnicode 图库服务获取图表详情
  11. func GetChartDetailFromChartLibByUnicode(unicode string) (detail *data_manage.ChartInfoDetailResp, err error) {
  12. if unicode == "" {
  13. err = fmt.Errorf("编码为空")
  14. return
  15. }
  16. defer func() {
  17. if err != nil {
  18. tips := fmt.Sprintf("获取图表详情失败, GetChartDetailFromChartLibByUnicode Err: %s", err.Error())
  19. utils.FileLog.Info(tips)
  20. }
  21. }()
  22. apiDetail, e := CurlChartLibChartDetailApi(unicode)
  23. if e != nil {
  24. err = fmt.Errorf("CurlChartLibChartDetailApi Err: %s", e.Error())
  25. return
  26. }
  27. detail = apiDetail
  28. return
  29. }
  30. // CurlChartLibChartDetailApi 请求图表详情接口
  31. func CurlChartLibChartDetailApi(unicode string) (detail *data_manage.ChartInfoDetailResp, err error) {
  32. apiUrl := fmt.Sprint(utils.EdbChartLibUrl, utils.ChartLibChartDetailFromUnicodeApi, "?UniqueCode=", unicode)
  33. ret, e := http.Get(apiUrl)
  34. if e != nil {
  35. err = fmt.Errorf("http get err: %s", e.Error())
  36. return
  37. }
  38. defer func() {
  39. _ = ret.Body.Close()
  40. }()
  41. body, e := ioutil.ReadAll(ret.Body)
  42. if e != nil {
  43. err = fmt.Errorf("read body err: %s", e.Error())
  44. return
  45. }
  46. result := new(data_manage.ChartDetailApiResponse)
  47. if e = json.Unmarshal(body, &result); e != nil {
  48. err = fmt.Errorf("json unmarshal err: %s", e.Error())
  49. return
  50. }
  51. if result.Ret != 200 {
  52. err = fmt.Errorf("result err: %s", result.ErrMsg)
  53. return
  54. }
  55. detail = result.Data
  56. return
  57. }