123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_report/models"
- "eta/eta_report/services"
- "eta/eta_report/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- )
- // ExcelController 表格详情
- type ExcelController struct {
- BaseAuthController
- }
- // ExcelDetail
- // @Title 表格详情
- // @Description 表格详情
- // @Success 200 {object} models.EnglishReportShareDetailResp
- // @router /detail [post]
- func (this *ExcelController) ExcelDetail() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- this.Data["json"] = br
- this.ServeJSONNoEncryption()
- }()
- var req services.ExcelDetailReq
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- url := fmt.Sprintf(utils.ChartLibUrl+`/excel_info/detail?UniqueCode=%s&FromScene=%d`, req.UniqueCode,req.FromScene )
- 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
- }
|