123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package v1_0
- import (
- "net/http"
- "adm-gateway/errors"
- param_v1 "adm-gateway/param/v1"
- "adm-gateway/pb"
- v1 "adm-gateway/pb/v1"
- "github.com/gin-gonic/gin"
- "git.getensh.com/common/gopkgsv2/logger"
- "git.getensh.com/common/gopkgsv2/tasker/httptasker"
- "git.getensh.com/common/gopkgsv2/util"
- "go.uber.org/zap"
- )
- // Series godoc
- // @Summary 车系列表
- // @Description 车系列表
- // @Tags series,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param brand_name query string false "品牌名称"
- // @Param brand_id query string false "品牌id"
- // @Param series_name query string false "车系名称"
- // @Param series_id query string false "车系id"
- // @Param has_img query int32 false "-1:无图片, 1:有图片"
- // @Param status query int32 false "-1:下线 1:上线"
- // @Param page query int32 false "页码"
- // @Param page_size query int32 false "每页数量,默认10"
- // @Success 200 {object} param_v1.GetSeriesListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/series/ [get]
- func (c *Controller) Series(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetSeriesListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetSeriesListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.GetSeriesListResponse{}
- r := v1.SeriesListRequest{
- BrandName: req.BrandName,
- BrandId: req.BrandId,
- SeriesName: req.SeriesName,
- SeriesId: req.SeriesId,
- HasImg: req.HasImg,
- Status: req.Status,
- Page: req.Page,
- PageSize: req.PageSize,
- OldSeriesName: req.OldSeriesName,
- }
- reply, err := pb.VehicleStyle.SeriesList(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.SeriesList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply == nil {
- reply.List = make([]*v1.SeriesList, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // UpdateSeries godoc
- // @Summary 更新车系信息
- // @Description 更新车系信息
- // @Tags series,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.UpdateSeriesBody true "body"
- // @Param file formData file false "图片"
- // @Success 200 {object} param_v1.SearchResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/series/ [put]
- func (c *Controller) UpdateSeries(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.UpdateSeriesRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateSeriesBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := ¶m_v1.UpdateBrandResponse{}
- r := v1.UpdateSeriesRequest{
- Id: req.ID,
- SeriesName: req.SeriesName,
- Maker: req.Maker,
- Status: req.Status,
- HasImg: req.HasImg,
- OldSeriesName: req.OldSeriesName,
- }
- _, err := pb.VehicleStyle.UpdateSeries(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.UpdateSeries"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|