series.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package v1_0
  2. import (
  3. "net/http"
  4. "adm-gateway/errors"
  5. param_v1 "adm-gateway/param/v1"
  6. "adm-gateway/pb"
  7. v1 "adm-gateway/pb/v1"
  8. "github.com/gin-gonic/gin"
  9. "git.getensh.com/common/gopkgsv2/logger"
  10. "git.getensh.com/common/gopkgsv2/tasker/httptasker"
  11. "git.getensh.com/common/gopkgsv2/util"
  12. "go.uber.org/zap"
  13. )
  14. // Series godoc
  15. // @Summary 车系列表
  16. // @Description 车系列表
  17. // @Tags series,v1.0
  18. // @Accept json
  19. // @Produce json
  20. // @Param token header string true "jwt token"
  21. // @Param brand_name query string false "品牌名称"
  22. // @Param brand_id query string false "品牌id"
  23. // @Param series_name query string false "车系名称"
  24. // @Param series_id query string false "车系id"
  25. // @Param has_img query int32 false "-1:无图片, 1:有图片"
  26. // @Param status query int32 false "-1:下线 1:上线"
  27. // @Param page query int32 false "页码"
  28. // @Param page_size query int32 false "每页数量,默认10"
  29. // @Success 200 {object} param_v1.GetSeriesListResponse
  30. // @Failure 500 {object} base.HTTPError
  31. // @Router /api/v1.0/series/ [get]
  32. func (c *Controller) Series(ctx *gin.Context) {
  33. // 解析参数
  34. req := &param_v1.GetSeriesListRequest{}
  35. parseParamTask := func() error {
  36. err := util.ShouldBind(ctx, nil, nil, &req.GetSeriesListQuery, nil)
  37. if err != nil {
  38. logger.Error("func",
  39. zap.String("call", "util.ShouldBind"),
  40. zap.String("error", err.Error()))
  41. return errors.ParamsError
  42. }
  43. return nil
  44. }
  45. // 业务处理
  46. handleServiceTask := func() error {
  47. // 响应数据
  48. resp := &param_v1.GetSeriesListResponse{}
  49. r := v1.SeriesListRequest{
  50. BrandName: req.BrandName,
  51. BrandId: req.BrandId,
  52. SeriesName: req.SeriesName,
  53. SeriesId: req.SeriesId,
  54. HasImg: req.HasImg,
  55. Status: req.Status,
  56. Page: req.Page,
  57. PageSize: req.PageSize,
  58. OldSeriesName: req.OldSeriesName,
  59. }
  60. reply, err := pb.VehicleStyle.SeriesList(ctx.Request.Context(), &r)
  61. if err != nil {
  62. s, _ := json.MarshalToString(r)
  63. logger.Error("func",
  64. zap.String("call", "pb.vehicleStyle.SeriesList"),
  65. zap.String("params", s),
  66. zap.String("error", err.Error()))
  67. return errors.ErrorTransForm(err)
  68. }
  69. if reply == nil {
  70. reply.List = make([]*v1.SeriesList, 0)
  71. }
  72. resp.Data = reply
  73. ctx.JSON(http.StatusOK, resp)
  74. return nil
  75. }
  76. // 执行任务
  77. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  78. }
  79. // UpdateSeries godoc
  80. // @Summary 更新车系信息
  81. // @Description 更新车系信息
  82. // @Tags series,v1.0
  83. // @Accept json
  84. // @Produce json
  85. // @Param token header string true "jwt token"
  86. // @Param body body param_v1.UpdateSeriesBody true "body"
  87. // @Param file formData file false "图片"
  88. // @Success 200 {object} param_v1.SearchResponse
  89. // @Failure 500 {object} base.HTTPError
  90. // @Router /api/v1.0/series/ [put]
  91. func (c *Controller) UpdateSeries(ctx *gin.Context) {
  92. // 解析参数
  93. req := &param_v1.UpdateSeriesRequest{}
  94. parseParamTask := func() error {
  95. err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateSeriesBody)
  96. if err != nil {
  97. logger.Error("func",
  98. zap.String("call", "util.ShouldBind"),
  99. zap.String("error", err.Error()))
  100. return errors.ParamsError
  101. }
  102. return nil
  103. }
  104. // 业务处理
  105. handleServiceTask := func() error {
  106. // 响应数据
  107. resp := &param_v1.UpdateBrandResponse{}
  108. r := v1.UpdateSeriesRequest{
  109. Id: req.ID,
  110. SeriesName: req.SeriesName,
  111. Maker: req.Maker,
  112. Status: req.Status,
  113. HasImg: req.HasImg,
  114. OldSeriesName: req.OldSeriesName,
  115. }
  116. _, err := pb.VehicleStyle.UpdateSeries(ctx.Request.Context(), &r)
  117. if err != nil {
  118. s, _ := json.MarshalToString(r)
  119. logger.Error("func",
  120. zap.String("call", "pb.vehicleStyle.UpdateSeries"),
  121. zap.String("params", s),
  122. zap.String("error", err.Error()))
  123. return errors.ErrorTransForm(err)
  124. }
  125. ctx.JSON(http.StatusOK, resp)
  126. return nil
  127. }
  128. // 执行任务
  129. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  130. }