style_map_management.go 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package v1_0
  2. import (
  3. "adm-gateway/errors"
  4. param_v1 "adm-gateway/param/v1"
  5. "adm-gateway/pb"
  6. v1 "adm-gateway/pb/v1"
  7. "net/http"
  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. // 车型映射管理表 t_adm_dws13
  15. // StyleMap godoc
  16. // @Summary 车型映射管理
  17. // @Description 车型映射管理
  18. // @Tags style_map_management,v1.0
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "jwt token"
  22. // @Param source query string false "映射源"
  23. // @Param state query string false "映射状态"
  24. // @Param third_style_id query string false "映射源车型id"
  25. // @Param style_id query string false "车型id"
  26. // @Param page query int32 false "页码"
  27. // @Param page_size query int32 false "每页数量,默认10"
  28. // @Success 200 {object} param_v1.StyleMapResponse
  29. // @Failure 500 {object} base.HTTPError
  30. // @Router /api/v1.0/style_map_management [get]
  31. func (c *Controller) StyleMap(ctx *gin.Context) {
  32. // 解析参数
  33. req := &param_v1.StyleMapRequest{}
  34. parseParamTask := func() error {
  35. err := util.ShouldBind(ctx, nil, nil, &req.StyleMapQuery, nil)
  36. if err != nil {
  37. logger.Error("func",
  38. zap.String("call", "util.ShouldBind"),
  39. zap.String("error", err.Error()))
  40. return errors.ParamsError
  41. }
  42. return nil
  43. }
  44. // 业务处理
  45. handleServiceTask := func() error {
  46. // 响应数据
  47. resp := &param_v1.StyleMapResponse{}
  48. r := v1.StyleMapRequest{
  49. Source: req.Source,
  50. State: req.State,
  51. ThirdStyleId: req.ThirdStyleId,
  52. StyleId: req.StyleId,
  53. Page: req.Page,
  54. PageSize: req.PageSize,
  55. }
  56. reply, err := pb.Management.StyleMap(ctx.Request.Context(), &r)
  57. if err != nil {
  58. s, _ := json.MarshalToString(r)
  59. logger.Error("func",
  60. zap.String("call", "pb.management.StyleMap"),
  61. zap.String("params", s),
  62. zap.String("error", err.Error()))
  63. return errors.ErrorTransForm(err)
  64. }
  65. if reply.List == nil {
  66. reply.List = make([]*v1.StyleMap, 0)
  67. }
  68. resp.Data = reply
  69. ctx.JSON(http.StatusOK, resp)
  70. return nil
  71. }
  72. // 执行任务
  73. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  74. }
  75. // EditMap godoc
  76. // @Summary 编辑
  77. // @Description 编辑
  78. // @Tags style_map_management,v1.0
  79. // @Accept json
  80. // @Produce json
  81. // @Param token header string true "jwt token"
  82. // @Param body body param_v1.EditMapBody true "body"
  83. // @Success 200 {object} param_v1.EditMapResponse
  84. // @Failure 500 {object} base.HTTPError
  85. // @Router /api/v1.0/style_map_management/ [put]
  86. func (c *Controller) EditMap(ctx *gin.Context) {
  87. // 解析参数
  88. req := &param_v1.EditMapRequest{}
  89. parseParamTask := func() error {
  90. err := util.ShouldBind(ctx, nil, nil, nil, &req.EditMapBody)
  91. if err != nil {
  92. logger.Error("func",
  93. zap.String("call", "util.ShouldBind"),
  94. zap.String("error", err.Error()))
  95. return errors.ParamsError
  96. }
  97. return nil
  98. }
  99. // 业务处理
  100. handleServiceTask := func() error {
  101. // 响应数据
  102. resp := &param_v1.EditMapResponse{}
  103. r := v1.EditMapRequest{
  104. ThirdStyleId: req.ThirdStyleId,
  105. StyleId: req.StyleId,
  106. }
  107. reply, err := pb.Management.EditMap(ctx.Request.Context(), &r)
  108. if err != nil {
  109. s, _ := json.MarshalToString(r)
  110. logger.Error("func",
  111. zap.String("call", "pb.management.EditMap"),
  112. zap.String("params", s),
  113. zap.String("error", err.Error()))
  114. return errors.ErrorTransForm(err)
  115. }
  116. resp.Data = reply
  117. ctx.JSON(http.StatusOK, resp)
  118. return nil
  119. }
  120. // 执行任务
  121. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  122. }
  123. // AllSource godoc
  124. // @Summary 映射源列表
  125. // @Description 映射源列表
  126. // @Tags style_map_management,v1.0
  127. // @Accept json
  128. // @Produce json
  129. // @Param token header string true "jwt token"
  130. // @Param all_source query string false "映射源"
  131. // @Success 200 {object} param_v1.AllSourceResponse
  132. // @Failure 500 {object} base.HTTPError
  133. // @Router /api/v1.0/style_map_management/all_source [get]
  134. func (c *Controller) AllSource(ctx *gin.Context) {
  135. // 解析参数
  136. req := &param_v1.AllSourceRequest{}
  137. parseParamTask := func() error {
  138. err := util.ShouldBind(ctx, nil, nil, &req.AllSourceQuery, nil)
  139. if err != nil {
  140. logger.Error("func",
  141. zap.String("call", "util.ShouldBind"),
  142. zap.String("error", err.Error()))
  143. return errors.ParamsError
  144. }
  145. return nil
  146. }
  147. // 业务处理
  148. handleServiceTask := func() error {
  149. // 响应数据
  150. resp := &param_v1.AllSourceResponse{}
  151. r := v1.AllSourceRequest{
  152. AllSource: req.AllSource,
  153. }
  154. reply, err := pb.Management.AllSource(ctx.Request.Context(), &r)
  155. if err != nil {
  156. s, _ := json.MarshalToString(r)
  157. logger.Error("func",
  158. zap.String("call", "pb.management.AllSource"),
  159. zap.String("params", s),
  160. zap.String("error", err.Error()))
  161. return errors.ErrorTransForm(err)
  162. }
  163. resp.Data = reply.List
  164. if resp.Data == nil {
  165. resp.Data = make([]string, 0)
  166. }
  167. ctx.JSON(http.StatusOK, resp)
  168. return nil
  169. }
  170. // 执行任务
  171. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  172. }