excel.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // ExcelController 表格详情
  12. type ExcelController struct {
  13. BaseAuthController
  14. }
  15. // ExcelDetail
  16. // @Title 表格详情
  17. // @Description 表格详情
  18. // @Success 200 {object} models.EnglishReportShareDetailResp
  19. // @router /detail [post]
  20. func (this *ExcelController) ExcelDetail() {
  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.ExcelDetailReq
  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. url := fmt.Sprintf(utils.ChartLibUrl+`/excel_info/detail?UniqueCode=%s&FromScene=%d`, req.UniqueCode,req.FromScene )
  37. resp, e := http.Get(url)
  38. if e != nil {
  39. err = fmt.Errorf("http Get err: %s", e.Error())
  40. br.ErrMsg = err.Error()
  41. return
  42. }
  43. defer resp.Body.Close()
  44. b, e := ioutil.ReadAll(resp.Body)
  45. if e != nil {
  46. err = fmt.Errorf("resp body read err: %s", e.Error())
  47. br.ErrMsg = err.Error()
  48. return
  49. }
  50. if len(b) == 0 {
  51. err = fmt.Errorf("resp body is empty")
  52. br.ErrMsg = err.Error()
  53. return
  54. }
  55. result := new(models.BaseResponse)
  56. if e = json.Unmarshal(b, &result); e != nil {
  57. err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
  58. br.ErrMsg = err.Error()
  59. return
  60. }
  61. if result.Ret != 200 {
  62. err = fmt.Errorf("result: %s", string(b))
  63. br.ErrMsg = err.Error()
  64. return
  65. }
  66. br.Ret = 200
  67. br.Success = true
  68. br.Msg = "获取成功"
  69. br.Data = result.Data
  70. return
  71. }