chart_controller.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package chart
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/common/exception"
  5. "eta/eta_mini_ht_api/controllers"
  6. chart "eta/eta_mini_ht_api/service/media"
  7. )
  8. type ChartController struct {
  9. controllers.ListController
  10. }
  11. type ChartEsUpdateReq struct {
  12. ChartImage string `json:"chartImage"`
  13. ChartInfoId int `json:"chartInfoId"`
  14. }
  15. // UpdateChartImage 更新图表缩略图
  16. // @Description 更新图表缩略图
  17. // @Success 200 {object}
  18. // @router /updateChartImage [post]
  19. func (m *ChartController) UpdateChartImage() {
  20. controllers.Wrap(&m.BaseController, func() (result *controllers.WrapData, err error) {
  21. result = m.InitWrapData("更新图表缩略图成功")
  22. var chartEsUpdateReq ChartEsUpdateReq
  23. m.GetPostParams(&chartEsUpdateReq)
  24. if chartEsUpdateReq.ChartImage == "" {
  25. err = exception.New(exception.ChartImageEmptyError)
  26. m.FailedResult("更新图表缩略图失败", result)
  27. return
  28. }
  29. if chartEsUpdateReq.ChartInfoId == 0 {
  30. err = exception.New(exception.IllegalChartId)
  31. m.FailedResult("更新图表缩略图失败", result)
  32. return
  33. }
  34. success := chart.UpdateChartImage(chartEsUpdateReq.ChartImage, chartEsUpdateReq.ChartInfoId)
  35. if !success {
  36. err = exception.New(exception.UpdateChartImageFailed)
  37. logger.Error("更新图表缩略图失败,chartInfoId:%d", chartEsUpdateReq.ChartInfoId)
  38. m.FailedResult("更新图表缩略图失败", result)
  39. return
  40. }
  41. m.SuccessResult("更新图表缩略图成功", nil, result)
  42. return
  43. })
  44. }