package services import ( "encoding/json" "eta/eta_hub/models/data_manage" "eta/eta_hub/utils" "fmt" "io/ioutil" "net/http" ) // GetChartDetailFromChartLibByUnicode 图库服务获取图表详情 func GetChartDetailFromChartLibByUnicode(unicode string) (detail *data_manage.ChartInfoDetailResp, err error) { if unicode == "" { err = fmt.Errorf("编码为空") return } defer func() { if err != nil { tips := fmt.Sprintf("获取图表详情失败, GetChartDetailFromChartLibByUnicode Err: %s", err.Error()) utils.FileLog.Info(tips) } }() apiDetail, e := CurlChartLibChartDetailApi(unicode) if e != nil { err = fmt.Errorf("CurlChartLibChartDetailApi Err: %s", e.Error()) return } detail = apiDetail return } // CurlChartLibChartDetailApi 请求图表详情接口 func CurlChartLibChartDetailApi(unicode string) (detail *data_manage.ChartInfoDetailResp, err error) { apiUrl := fmt.Sprint(utils.EdbChartLibUrl, utils.ChartLibChartDetailFromUnicodeApi, "?UniqueCode=", unicode) ret, e := http.Get(apiUrl) if e != nil { err = fmt.Errorf("http get err: %s", e.Error()) return } defer func() { _ = ret.Body.Close() }() body, e := ioutil.ReadAll(ret.Body) if e != nil { err = fmt.Errorf("read body err: %s", e.Error()) return } result := new(data_manage.ChartDetailApiResponse) if e = json.Unmarshal(body, &result); e != nil { err = fmt.Errorf("json unmarshal err: %s", e.Error()) return } if result.Ret != 200 { err = fmt.Errorf("result err: %s", result.ErrMsg) return } detail = result.Data return }