123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "net/http"
- "smart-site-management-gateway/errors"
- param_v1 "smart-site-management-gateway/param/v1"
- "smart-site-management-gateway/pb"
- "smart-site-management-gateway/pb/v1"
- "smart-site-management-gateway/utils"
- "github.com/gin-gonic/gin"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "github.com/jaryhe/gopkgs/util"
- "go.uber.org/zap"
- )
- //
- // @Summary 车辆
- // @Description 车辆
- // @Tags 车辆进出场前台展示
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int false " "
- // @Param page_size query int false " "
- // @Param plate_no query string false " "
- // @Param start query int64 false " "
- // @Param end query int64 false " "
- // @Success 200 {object} v1.VehicleListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/vehicle/list [get]
- func (c *Controller) VehicleList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.VehicleListRequest{}
- var loginUid int64
- var userName string
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, nil, nil, &req.VehicleListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- _, projectId, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- // 响应数据
- resp := param_v1.VehicleListResponse{}
- rpcReq := &v1.VehicleListRequest{
- ProjectId: projectId,
- Page: req.Page,
- Type: req.Type,
- Start: req.Start,
- End: req.End,
- PlateNo:req.PlateNo,
- PageSize:req.PageSize,
- }
- rpcRsp, err := pb.Project.VehicleList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Project.VehicleList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- if resp.Data.List == nil {
- resp.Data.List = []*v1.Vehicle{}
- }
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|