excel.go 1.5 KB

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