brand.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. // Brand godoc
  15. // @Summary 品牌列表
  16. // @Description 品牌列表
  17. // @Tags brand,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 initial query string false "首字母"
  24. // @Param has_img query int32 false "-1:无图片, 1:有图片"
  25. // @Param status query int32 false "-1:下线 1:上线"
  26. // @Param page query int32 false "页码"
  27. // @Param page_size query int32 false "每页数量,默认10"
  28. // @Success 200 {object} param_v1.GetBrandListResponse
  29. // @Failure 500 {object} base.HTTPError
  30. // @Router /api/v1.0/brand [get]
  31. func (c *Controller) Brand(ctx *gin.Context) {
  32. // 解析参数
  33. req := &param_v1.GetBrandListRequest{}
  34. parseParamTask := func() error {
  35. err := util.ShouldBind(ctx, nil, nil, &req.GetBrandListQuery, 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.GetBrandListResponse{}
  48. r := v1.BrandListRequest{
  49. BrandName: req.BrandName,
  50. BrandId: req.BrandId,
  51. Initial: req.Initial,
  52. HasImg: req.HasImg,
  53. Status: req.Status,
  54. Page: req.Page,
  55. PageSize: req.PageSize,
  56. OldBrandName: req.OldBrandName,
  57. }
  58. reply, err := pb.VehicleStyle.BrandList(ctx.Request.Context(), &r)
  59. if err != nil {
  60. s, _ := json.MarshalToString(r)
  61. logger.Error("func",
  62. zap.String("call", "pb.vehicleStyle.BrandList"),
  63. zap.String("params", s),
  64. zap.String("error", err.Error()))
  65. return errors.ErrorTransForm(err)
  66. }
  67. if reply == nil {
  68. reply.List = make([]*v1.BrandList, 0)
  69. }
  70. resp.Data = reply
  71. ctx.JSON(http.StatusOK, resp)
  72. return nil
  73. }
  74. // 执行任务
  75. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  76. }
  77. // Search godoc
  78. // @Summary 模糊搜索
  79. // @Description 模糊搜索
  80. // @Tags brand,v1.0
  81. // @Accept json
  82. // @Produce json
  83. // @Param token header string true "jwt token"
  84. // @Param type query int32 true "1:品牌 2:厂商 3:车系 4:车型"
  85. // @Param search query string false "关键字"
  86. // @Param brand_id query string false "brand_id"
  87. // @Param maker_id query string false "maker_id"
  88. // @Param series_id query string false "series_id"
  89. // @Success 200 {object} param_v1.SearchResponse
  90. // @Failure 500 {object} base.HTTPError
  91. // @Router /api/v1.0/brand/search [get]
  92. func (c *Controller) Search(ctx *gin.Context) {
  93. // 解析参数
  94. req := &param_v1.SearchRequest{}
  95. parseParamTask := func() error {
  96. err := util.ShouldBind(ctx, nil, nil, &req.SearchQuery, nil)
  97. if err != nil {
  98. logger.Error("func",
  99. zap.String("call", "util.ShouldBind"),
  100. zap.String("error", err.Error()))
  101. return errors.ParamsError
  102. }
  103. return nil
  104. }
  105. // 业务处理
  106. handleServiceTask := func() error {
  107. // 响应数据
  108. resp := &param_v1.SearchResponse{}
  109. r := v1.SearchRequest{
  110. Type: req.Type,
  111. Search: req.Search,
  112. BrandId: req.BrandId,
  113. MakerId: req.MakerId,
  114. SeriesId: req.SeriesId,
  115. }
  116. reply, err := pb.VehicleStyle.Search(ctx.Request.Context(), &r)
  117. if err != nil {
  118. s, _ := json.MarshalToString(r)
  119. logger.Error("func",
  120. zap.String("call", "pb.vehicleStyle.Search"),
  121. zap.String("params", s),
  122. zap.String("error", err.Error()))
  123. return errors.ErrorTransForm(err)
  124. }
  125. resp.Data = reply
  126. if resp.Data == nil {
  127. resp.Data = &v1.SearchReply{
  128. List: []*v1.SearchList{},
  129. }
  130. }
  131. ctx.JSON(http.StatusOK, resp)
  132. return nil
  133. }
  134. // 执行任务
  135. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  136. }
  137. // UpdateBrand godoc
  138. // @Summary 更新车辆品牌信息
  139. // @Description 更新车辆品牌信息
  140. // @Tags brand,v1.0
  141. // @Accept json
  142. // @Produce json
  143. // @Param token header string true "jwt token"
  144. // @Param body body param_v1.UpdateBrandBody true "body"
  145. // @Success 200 {object} param_v1.SearchResponse
  146. // @Failure 500 {object} base.HTTPError
  147. // @Router /api/v1.0/brand/ [put]
  148. func (c *Controller) UpdateBrand(ctx *gin.Context) {
  149. // 解析参数
  150. req := &param_v1.UpdateBrandRequest{}
  151. parseParamTask := func() error {
  152. err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateBrandBody)
  153. if err != nil {
  154. logger.Error("func",
  155. zap.String("call", "util.ShouldBind"),
  156. zap.String("error", err.Error()))
  157. return errors.ParamsError
  158. }
  159. return nil
  160. }
  161. // 业务处理
  162. handleServiceTask := func() error {
  163. // 响应数据
  164. resp := &param_v1.UpdateBrandResponse{}
  165. r := v1.UpdateSYBrandRequest{
  166. Id: req.ID,
  167. BrandName: req.BrandName,
  168. Initial: req.Initial,
  169. Weight: req.Weight,
  170. Status: req.Status,
  171. HasImg: req.HasImg,
  172. OldBrandName: req.OldBrandName,
  173. }
  174. _, err := pb.VehicleStyle.UpdateSYBrand(ctx.Request.Context(), &r)
  175. if err != nil {
  176. s, _ := json.MarshalToString(r)
  177. logger.Error("func",
  178. zap.String("call", "pb.vehicleStyle.UpdateSYBrand"),
  179. zap.String("params", s),
  180. zap.String("error", err.Error()))
  181. return errors.ErrorTransForm(err)
  182. }
  183. ctx.JSON(http.StatusOK, resp)
  184. return nil
  185. }
  186. // 执行任务
  187. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  188. }
  189. // Maker godoc
  190. // @Summary 厂商列表
  191. // @Description 厂商列表
  192. // @Tags brand,v1.0
  193. // @Accept json
  194. // @Produce json
  195. // @Param token header string true "jwt token"
  196. // @Param brand_id query string true "品牌id"
  197. // @Success 200 {object} param_v1.GetMakerResponse
  198. // @Failure 500 {object} base.HTTPError
  199. // @Router /api/v1.0/brand/maker [get]
  200. func (c *Controller) Maker(ctx *gin.Context) {
  201. // 解析参数
  202. req := &param_v1.GetMakerRequest{}
  203. parseParamTask := func() error {
  204. err := util.ShouldBind(ctx, nil, nil, &req.GetMakerQuery, nil)
  205. if err != nil {
  206. logger.Error("func",
  207. zap.String("call", "util.ShouldBind"),
  208. zap.String("error", err.Error()))
  209. return errors.ParamsError
  210. }
  211. return nil
  212. }
  213. // 业务处理
  214. handleServiceTask := func() error {
  215. // 响应数据
  216. resp := &param_v1.GetMakerResponse{}
  217. r := v1.GetMakerRequest{
  218. BrandId: req.BrandId,
  219. }
  220. reply, err := pb.VehicleStyle.GetMaker(ctx.Request.Context(), &r)
  221. if err != nil {
  222. s, _ := json.MarshalToString(r)
  223. logger.Error("func",
  224. zap.String("call", "pb.vehicleStyle.GetMaker"),
  225. zap.String("params", s),
  226. zap.String("error", err.Error()))
  227. return errors.ErrorTransForm(err)
  228. }
  229. resp.Data = reply.List
  230. if resp.Data == nil {
  231. resp.Data = make([]*v1.MakerList, 0)
  232. }
  233. ctx.JSON(http.StatusOK, resp)
  234. return nil
  235. }
  236. // 执行任务
  237. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  238. }
  239. // UpdateMaker godoc
  240. // @Summary 更新厂商信息
  241. // @Description 更新厂商信息
  242. // @Tags brand,v1.0
  243. // @Accept json
  244. // @Produce json
  245. // @Param token header string true "jwt token"
  246. // @Param body body param_v1.UpdateMakerBody true "body"
  247. // @Success 200 {object} param_v1.SearchResponse
  248. // @Failure 500 {object} base.HTTPError
  249. // @Router /api/v1.0/brand/maker [put]
  250. func (c *Controller) UpdateMaker(ctx *gin.Context) {
  251. // 解析参数
  252. req := &param_v1.UpdateMakerRequest{}
  253. parseParamTask := func() error {
  254. err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateMakerBody)
  255. if err != nil {
  256. logger.Error("func",
  257. zap.String("call", "util.ShouldBind"),
  258. zap.String("error", err.Error()))
  259. return errors.ParamsError
  260. }
  261. return nil
  262. }
  263. // 业务处理
  264. handleServiceTask := func() error {
  265. // 响应数据
  266. resp := &param_v1.UpdateMakerResponse{}
  267. r := v1.UpdateMakerRequest{
  268. MakerId: req.MakerId,
  269. Maker: req.Maker,
  270. }
  271. _, err := pb.VehicleStyle.UpdateMaker(ctx.Request.Context(), &r)
  272. if err != nil {
  273. s, _ := json.MarshalToString(r)
  274. logger.Error("func",
  275. zap.String("call", "pb.vehicleStyle.UpdateMaker"),
  276. zap.String("params", s),
  277. zap.String("error", err.Error()))
  278. return errors.ErrorTransForm(err)
  279. }
  280. ctx.JSON(http.StatusOK, resp)
  281. return nil
  282. }
  283. // 执行任务
  284. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  285. }