123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package controllers
- import (
- "encoding/json"
- "eta/eta_report/models"
- "eta/eta_report/services"
- "eta/eta_report/utils"
- "fmt"
- "io/ioutil"
- "net/http"
- "strings"
- )
- // ChartController 图表详情
- type ChartController struct {
- BaseAuthController
- }
- // ChartDetail
- // @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
- }
- // (为了兼容内网客户)需要判断是否替换资源地址
- var urlReplace models.Report2ImgReplace
- if req.IsReplace == 1 {
- conf, e := models.GetBusinessConf()
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取免责声明失败, Err: " + e.Error()
- return
- }
- if conf[models.BusinessConfReport2ImgReplace] != "" {
- if e := json.Unmarshal([]byte(conf[models.BusinessConfReport2ImgReplace]), &urlReplace); e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = fmt.Sprintf("获取报告替换配置失败, %v", e)
- return
- }
- }
- if urlReplace.IsReplace && urlReplace.OssUrlOrigin != "" {
- // 替换水印图片地址
- replaceFunc := func(data interface{}, originUrl, newUrl string) {
- if dataMap, ok := data.(map[string]interface{}); ok {
- if waterMark, ok := dataMap["WaterMark"].(string); ok {
- newWaterMark := strings.ReplaceAll(waterMark, originUrl, newUrl)
- dataMap["WaterMark"] = newWaterMark
- }
- }
- }
- replaceFunc(result.Data, urlReplace.OssUrlOrigin, urlReplace.OssUrlNew)
- }
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = result.Data
- }
|