vehicle.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "net/http"
  6. "smart-site-management-gateway/errors"
  7. param_v1 "smart-site-management-gateway/param/v1"
  8. "smart-site-management-gateway/pb"
  9. "smart-site-management-gateway/pb/v1"
  10. "smart-site-management-gateway/utils"
  11. "github.com/gin-gonic/gin"
  12. "github.com/jaryhe/gopkgs/logger"
  13. "github.com/jaryhe/gopkgs/tasker/httptasker"
  14. "github.com/jaryhe/gopkgs/util"
  15. "go.uber.org/zap"
  16. )
  17. //
  18. // @Summary 车辆
  19. // @Description 车辆
  20. // @Tags 车辆进出场前台展示
  21. // @Accept json
  22. // @Produce json
  23. // @Param token header string true " "
  24. // @Param page query int false " "
  25. // @Param page_size query int false " "
  26. // @Param plate_no query string false " "
  27. // @Param start query int64 false " "
  28. // @Param end query int64 false " "
  29. // @Success 200 {object} v1.VehicleListResponse
  30. // @Failure 500 {object} base.HTTPError
  31. // @Router /api/v1/vehicle/list [get]
  32. func (c *Controller) VehicleList(ctx *gin.Context) {
  33. // 解析参数
  34. req := &param_v1.VehicleListRequest{}
  35. var loginUid int64
  36. var userName string
  37. parseParamTask := func() error {
  38. err := util.ShouldBind(ctx, nil, nil, &req.VehicleListQuery, nil)
  39. if err != nil {
  40. logger.Error("func",
  41. zap.String("call", "util.ShouldBind"),
  42. zap.String("error", err.Error()))
  43. return errors.ParamsError
  44. }
  45. loginUid, userName, err = utils.GetJwtIdFromCtx(ctx)
  46. return nil
  47. }
  48. // 业务处理
  49. handleServiceTask := func() error {
  50. _, projectId, err := utils.GetSubjectValue(ctx)
  51. if err != nil {
  52. return err
  53. }
  54. // 响应数据
  55. resp := param_v1.VehicleListResponse{}
  56. rpcReq := &v1.VehicleListRequest{
  57. ProjectId: projectId,
  58. Page: req.Page,
  59. Type: req.Type,
  60. Start: req.Start,
  61. End: req.End,
  62. PlateNo:req.PlateNo,
  63. PageSize:req.PageSize,
  64. }
  65. rpcRsp, err := pb.Project.VehicleList(ctx, rpcReq)
  66. if err != nil {
  67. s, _ := json.MarshalToString(req)
  68. logger.Error("func",
  69. zap.String("call", "pb.Project.VehicleList"),
  70. zap.String("params", s),
  71. zap.String("error", err.Error()))
  72. return errors.ErrorTransForm(err)
  73. }
  74. resp.Data = *rpcRsp
  75. if resp.Data.List == nil {
  76. resp.Data.List = []*v1.Vehicle{}
  77. }
  78. ctx.JSON(http.StatusOK, resp)
  79. return nil
  80. }
  81. // 执行任务
  82. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  83. }