12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_report/models"
- "eta/eta_report/services"
- "eta/eta_report/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- )
- // ChartController 图表详情
- type ChartController struct {
- BaseAuthController
- }
- // ExcelDetail
- // @Title 表格详情
- // @Description 表格详情
- // @Success 200 {object} models.EnglishReportShareDetailResp
- // @router /detail [post]
- func (this *ChartController) ChartDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSONNoEncryption()
- }()
- var req services.ChartDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- if req.UniqueCode == "" {
- br.Msg = "参数不能为空!"
- br.ErrMsg = "参数不能为空!"
- return
- }
- url := utils.ChartLibUrl+`/chart/common/detail?UniqueCode=%s`
- url = fmt.Sprintf(url, req.UniqueCode)
- resp, e := http.Get(url)
- if e != nil {
- err = fmt.Errorf("http Get err: %s", e.Error())
- br.ErrMsg = err.Error()
- return
- }
- defer resp.Body.Close()
- b, e := ioutil.ReadAll(resp.Body)
- if e != nil {
- err = fmt.Errorf("resp body read err: %s", e.Error())
- br.ErrMsg = err.Error()
- return
- }
- if len(b) == 0 {
- err = fmt.Errorf("resp body is empty")
- br.ErrMsg = err.Error()
- return
- }
- result := new(models.BaseResponse)
- if e = json.Unmarshal(b, &result); e != nil {
- err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
- br.ErrMsg = err.Error()
- return
- }
- if result.Ret != 200 {
- err = fmt.Errorf("result: %s", string(b))
- br.ErrMsg = err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = result.Data
- return
- }
|