service_phone.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  13. )
  14. //
  15. // @Summary 分类列表
  16. // @Description 分类列表
  17. // @Tags 服务电话
  18. // @Accept json
  19. // @Produce json
  20. // @Param token header string true "token"
  21. // @Param page query int false " "
  22. // @Param page_size query int false " "
  23. // @Param garden_id query int true "小区id"
  24. // @Success 200 {object} v1.ServicePhoneClassListResponse
  25. // @Failure 500 {object} base.HTTPError
  26. // @Router /api/v1/service_phone/class [get]
  27. func (c *Controller) ServicePhoneClassList(ctx *gin.Context) {
  28. // 解析参数
  29. req := &param_v1.ServicePhoneClassListRequest{}
  30. parseParamTask := func() error {
  31. err := util.ShouldBind(ctx, &req.Header, nil, &req.ServicePhoneClassListQuery, nil)
  32. if err != nil {
  33. logger.Error("func",
  34. zap.String("call", "util.ShouldBind"),
  35. zap.String("error", err.Error()))
  36. return errors.ParamsError
  37. }
  38. return nil
  39. }
  40. // 业务处理
  41. handleServiceTask := func() error {
  42. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  43. //if err != nil {
  44. // return err
  45. //}
  46. // 响应数据
  47. resp := param_v1.ServicePhoneClassListResponse{}
  48. rpcReq := &v1.ServicePhoneClassListRequest{
  49. GardenId:req.GardenId,
  50. PageSize:req.PageSize,
  51. Page:req.Page,
  52. Enable:1,
  53. }
  54. rpcRsp, err := pb.Garden.ServicePhoneClassList(ctx, rpcReq)
  55. if err != nil {
  56. s, _ := json.MarshalToString(req)
  57. logger.Error("func",
  58. zap.String("call", "pb.Garden.ServicePhoneClassList"),
  59. zap.String("params", s),
  60. zap.String("error", err.Error()))
  61. return errors.ErrorTransForm(err)
  62. }
  63. if rpcRsp.List == nil {
  64. rpcRsp.List = make([]*v1.ServicePhoneClassItem, 0)
  65. }
  66. resp.Data = *rpcRsp
  67. ctx.JSON(http.StatusOK, resp)
  68. return nil
  69. }
  70. // 执行任务
  71. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  72. }
  73. //
  74. // @Summary 电话列表
  75. // @Description 电话列表
  76. // @Tags 服务电话
  77. // @Accept json
  78. // @Produce json
  79. // @Param token header string true "token"
  80. // @Param page query int false " "
  81. // @Param page_size query int false " "
  82. // @Param class_id query int false "分类id"
  83. // @Param garden_id query int true "小区id"
  84. // @Success 200 {object} v1.ServicePhoneListResponse
  85. // @Failure 500 {object} base.HTTPError
  86. // @Router /api/v1/service_phone [get]
  87. func (c *Controller) ServicePhoneList(ctx *gin.Context) {
  88. // 解析参数
  89. req := &param_v1.ServicePhoneListRequest{}
  90. parseParamTask := func() error {
  91. err := util.ShouldBind(ctx, &req.Header, nil, &req.ServicePhoneListQuery, nil)
  92. if err != nil {
  93. logger.Error("func",
  94. zap.String("call", "util.ShouldBind"),
  95. zap.String("error", err.Error()))
  96. return errors.ParamsError
  97. }
  98. return nil
  99. }
  100. // 业务处理
  101. handleServiceTask := func() error {
  102. //tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  103. //if err != nil {
  104. // return err
  105. //}
  106. // 响应数据
  107. resp := param_v1.ServicePhoneListResponse{}
  108. rpcReq := &v1.ServicePhoneListRequest{
  109. GardenId:req.GardenId,
  110. PageSize:req.PageSize,
  111. Page:req.Page,
  112. ClassId:req.ClassId,
  113. Enable:1,
  114. }
  115. rpcRsp, err := pb.Garden.ServicePhoneList(ctx, rpcReq)
  116. if err != nil {
  117. s, _ := json.MarshalToString(req)
  118. logger.Error("func",
  119. zap.String("call", "pb.Garden.ServicePhoneList"),
  120. zap.String("params", s),
  121. zap.String("error", err.Error()))
  122. return errors.ErrorTransForm(err)
  123. }
  124. if rpcRsp.List == nil {
  125. rpcRsp.List = make([]*v1.ServicePhoneItem, 0)
  126. }
  127. resp.Data = *rpcRsp
  128. ctx.JSON(http.StatusOK, resp)
  129. return nil
  130. }
  131. // 执行任务
  132. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  133. }