package v1_0 import ( "adm-gateway/errors" param_v1 "adm-gateway/param/v1" "adm-gateway/pb" v1 "adm-gateway/pb/v1" "net/http" "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" ) // 车型映射管理表 t_adm_dws13 // StyleMap godoc // @Summary 车型映射管理 // @Description 车型映射管理 // @Tags style_map_management,v1.0 // @Accept json // @Produce json // @Param token header string true "jwt token" // @Param source query string false "映射源" // @Param state query string false "映射状态" // @Param third_style_id query string false "映射源车型id" // @Param style_id query string false "车型id" // @Param page query int32 false "页码" // @Param page_size query int32 false "每页数量,默认10" // @Success 200 {object} param_v1.StyleMapResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1.0/style_map_management [get] func (c *Controller) StyleMap(ctx *gin.Context) { // 解析参数 req := ¶m_v1.StyleMapRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, &req.StyleMapQuery, 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.StyleMapResponse{} r := v1.StyleMapRequest{ Source: req.Source, State: req.State, ThirdStyleId: req.ThirdStyleId, StyleId: req.StyleId, Page: req.Page, PageSize: req.PageSize, } reply, err := pb.Management.StyleMap(ctx.Request.Context(), &r) if err != nil { s, _ := json.MarshalToString(r) logger.Error("func", zap.String("call", "pb.management.StyleMap"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if reply.List == nil { reply.List = make([]*v1.StyleMap, 0) } resp.Data = reply ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // EditMap godoc // @Summary 编辑 // @Description 编辑 // @Tags style_map_management,v1.0 // @Accept json // @Produce json // @Param token header string true "jwt token" // @Param body body param_v1.EditMapBody true "body" // @Success 200 {object} param_v1.EditMapResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1.0/style_map_management/ [put] func (c *Controller) EditMap(ctx *gin.Context) { // 解析参数 req := ¶m_v1.EditMapRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, nil, &req.EditMapBody) 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.EditMapResponse{} r := v1.EditMapRequest{ ThirdStyleId: req.ThirdStyleId, StyleId: req.StyleId, } reply, err := pb.Management.EditMap(ctx.Request.Context(), &r) if err != nil { s, _ := json.MarshalToString(r) logger.Error("func", zap.String("call", "pb.management.EditMap"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = reply ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // AllSource godoc // @Summary 映射源列表 // @Description 映射源列表 // @Tags style_map_management,v1.0 // @Accept json // @Produce json // @Param token header string true "jwt token" // @Param all_source query string false "映射源" // @Success 200 {object} param_v1.AllSourceResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1.0/style_map_management/all_source [get] func (c *Controller) AllSource(ctx *gin.Context) { // 解析参数 req := ¶m_v1.AllSourceRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, nil, nil, &req.AllSourceQuery, 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.AllSourceResponse{} r := v1.AllSourceRequest{ AllSource: req.AllSource, } reply, err := pb.Management.AllSource(ctx.Request.Context(), &r) if err != nil { s, _ := json.MarshalToString(r) logger.Error("func", zap.String("call", "pb.management.AllSource"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = reply.List if resp.Data == nil { resp.Data = make([]string, 0) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }