123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- 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)
- }
|