eta_forum_chart.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_report/models"
  5. "eta/eta_report/services"
  6. "eta/eta_report/utils"
  7. "fmt"
  8. "io/ioutil"
  9. "net/http"
  10. )
  11. // EtaForumChartController 图表详情
  12. type EtaForumChartController struct {
  13. BaseAuthController
  14. }
  15. // ChartDetail
  16. // @Title 表格详情
  17. // @Description 表格详情
  18. // @Success 200 {object} models.EnglishReportShareDetailResp
  19. // @router /chart/detail [post]
  20. func (this *EtaForumChartController) ChartDetail() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. if br.ErrMsg == "" {
  24. br.IsSendEmail = false
  25. }
  26. this.Data["json"] = br
  27. this.ServeJSONNoEncryption()
  28. }()
  29. var req services.ChartDetailReq
  30. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  31. if err != nil {
  32. br.Msg = "参数解析异常!"
  33. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  34. return
  35. }
  36. if req.UniqueCode == "" {
  37. br.Msg = "参数不能为空!"
  38. br.ErrMsg = "参数不能为空!"
  39. return
  40. }
  41. url := utils.ChartLibUrl + `/eta_forum/chart/common/detail?UniqueCode=%s`
  42. url = fmt.Sprintf(url, req.UniqueCode)
  43. resp, e := http.Get(url)
  44. if e != nil {
  45. err = fmt.Errorf("http Get err: %s", e.Error())
  46. br.ErrMsg = err.Error()
  47. return
  48. }
  49. defer resp.Body.Close()
  50. b, e := ioutil.ReadAll(resp.Body)
  51. if e != nil {
  52. err = fmt.Errorf("resp body read err: %s", e.Error())
  53. br.ErrMsg = err.Error()
  54. return
  55. }
  56. if len(b) == 0 {
  57. err = fmt.Errorf("resp body is empty")
  58. br.ErrMsg = err.Error()
  59. return
  60. }
  61. result := new(models.BaseResponse)
  62. if e = json.Unmarshal(b, &result); e != nil {
  63. err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
  64. br.ErrMsg = err.Error()
  65. return
  66. }
  67. if result.Ret != 200 {
  68. err = fmt.Errorf("result: %s", string(b))
  69. br.ErrMsg = err.Error()
  70. return
  71. }
  72. br.Ret = 200
  73. br.Success = true
  74. br.Msg = "获取成功"
  75. br.Data = result.Data
  76. }