package.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. "git.getensh.com/common/gopkgs/logger"
  6. "git.getensh.com/common/gopkgs/tasker/httptasker"
  7. "git.getensh.com/common/gopkgs/util"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. "net/http"
  11. "property-company-gateway/errors"
  12. param_v1 "property-company-gateway/param/v1"
  13. "property-company-gateway/pb"
  14. "property-company-gateway/pb/v1"
  15. )
  16. //
  17. // @Summary 套餐列表
  18. // @Description 套餐列表
  19. // @Tags 套餐
  20. // @Accept json
  21. // @Produce json
  22. // @Param token header string true " "
  23. // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
  24. // @Param page_size query int false "每页条数,-1 不分页返回所有"
  25. // @Param enable query int false "0不过滤,1已发布的 2 未发布的"
  26. // @Success 200 {object} v1.PackageListResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1/package [get]
  29. func (c *Controller) PackageList(ctx *gin.Context) {
  30. // 解析参数
  31. req := &param_v1.PackageListRequest{}
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, &req.Header, nil, &req.PackageListQuery, nil)
  34. if err != nil {
  35. logger.Error("func",
  36. zap.String("call", "util.ShouldBind"),
  37. zap.String("error", err.Error()))
  38. return errors.ParamsError
  39. }
  40. return nil
  41. }
  42. // 业务处理
  43. handleServiceTask := func() error {
  44. //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  45. //if err != nil {
  46. // return err
  47. //}
  48. // 响应数据
  49. resp := param_v1.PackageListResponse{}
  50. rpcReq := &v1.PackageListRequest{
  51. //PackageId: req.PackageId,
  52. PageSize: req.PageSize,
  53. Page: req.Page,
  54. Enable: 1,
  55. }
  56. rpcRsp, err := pb.Common.PackageList(ctx, rpcReq)
  57. if err != nil {
  58. s, _ := json.MarshalToString(req)
  59. logger.Error("func",
  60. zap.String("call", "pb.Common.PackageList"),
  61. zap.String("params", s),
  62. zap.String("error", err.Error()))
  63. return errors.ErrorTransForm(err)
  64. }
  65. if rpcRsp.List == nil {
  66. rpcRsp.List = make([]*v1.PackageItem, 0)
  67. }
  68. resp.Data = *rpcRsp
  69. ctx.JSON(http.StatusOK, resp)
  70. return nil
  71. }
  72. // 执行任务
  73. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  74. }