123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325 |
- 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"
- )
- // Brand godoc
- // @Summary 品牌列表
- // @Description 品牌列表
- // @Tags brand,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 initial query string false "首字母"
- // @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.GetBrandListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/brand [get]
- func (c *Controller) Brand(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetBrandListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetBrandListQuery, 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.GetBrandListResponse{}
- r := v1.BrandListRequest{
- BrandName: req.BrandName,
- BrandId: req.BrandId,
- Initial: req.Initial,
- HasImg: req.HasImg,
- Status: req.Status,
- Page: req.Page,
- PageSize: req.PageSize,
- OldBrandName: req.OldBrandName,
- }
- reply, err := pb.VehicleStyle.BrandList(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.BrandList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if reply == nil {
- reply.List = make([]*v1.BrandList, 0)
- }
- resp.Data = reply
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // Search godoc
- // @Summary 模糊搜索
- // @Description 模糊搜索
- // @Tags brand,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param type query int32 true "1:品牌 2:厂商 3:车系 4:车型"
- // @Param search query string false "关键字"
- // @Param brand_id query string false "brand_id"
- // @Param maker_id query string false "maker_id"
- // @Param series_id query string false "series_id"
- // @Success 200 {object} param_v1.SearchResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/brand/search [get]
- func (c *Controller) Search(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.SearchRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.SearchQuery, 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.SearchResponse{}
- r := v1.SearchRequest{
- Type: req.Type,
- Search: req.Search,
- BrandId: req.BrandId,
- MakerId: req.MakerId,
- SeriesId: req.SeriesId,
- }
- reply, err := pb.VehicleStyle.Search(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.Search"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply
- if resp.Data == nil {
- resp.Data = &v1.SearchReply{
- List: []*v1.SearchList{},
- }
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // UpdateBrand godoc
- // @Summary 更新车辆品牌信息
- // @Description 更新车辆品牌信息
- // @Tags brand,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.UpdateBrandBody true "body"
- // @Success 200 {object} param_v1.SearchResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/brand/ [put]
- func (c *Controller) UpdateBrand(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.UpdateBrandRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateBrandBody)
- 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.UpdateSYBrandRequest{
- Id: req.ID,
- BrandName: req.BrandName,
- Initial: req.Initial,
- Weight: req.Weight,
- Status: req.Status,
- HasImg: req.HasImg,
- OldBrandName: req.OldBrandName,
- }
- _, err := pb.VehicleStyle.UpdateSYBrand(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.UpdateSYBrand"),
- 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)
- }
- // Maker godoc
- // @Summary 厂商列表
- // @Description 厂商列表
- // @Tags brand,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param brand_id query string true "品牌id"
- // @Success 200 {object} param_v1.GetMakerResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/brand/maker [get]
- func (c *Controller) Maker(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GetMakerRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.GetMakerQuery, 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.GetMakerResponse{}
- r := v1.GetMakerRequest{
- BrandId: req.BrandId,
- }
- reply, err := pb.VehicleStyle.GetMaker(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.GetMaker"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = reply.List
- if resp.Data == nil {
- resp.Data = make([]*v1.MakerList, 0)
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- // UpdateMaker godoc
- // @Summary 更新厂商信息
- // @Description 更新厂商信息
- // @Tags brand,v1.0
- // @Accept json
- // @Produce json
- // @Param token header string true "jwt token"
- // @Param body body param_v1.UpdateMakerBody true "body"
- // @Success 200 {object} param_v1.SearchResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1.0/brand/maker [put]
- func (c *Controller) UpdateMaker(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.UpdateMakerRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, nil, &req.UpdateMakerBody)
- 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.UpdateMakerResponse{}
- r := v1.UpdateMakerRequest{
- MakerId: req.MakerId,
- Maker: req.Maker,
- }
- _, err := pb.VehicleStyle.UpdateMaker(ctx.Request.Context(), &r)
- if err != nil {
- s, _ := json.MarshalToString(r)
- logger.Error("func",
- zap.String("call", "pb.vehicleStyle.UpdateMaker"),
- 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)
- }
|