household.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. "property-household-gateway/utils"
  14. )
  15. //
  16. // @Summary 房屋认证申请
  17. // @Description 房屋认证申请
  18. // @Tags 业主房屋
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true " "
  22. // @Param body body v1.HouseholdApplyBody true "信息"
  23. // @Success 200 {object} v1.HouseholdApplyResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/household/apply [post]
  26. func (c *Controller) HouseholdApply(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.HouseholdApplyRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseholdApplyBody)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. resp := param_v1.HouseholdApplyResponse{}
  46. rpcReq := &v1.HouseholdApplyRequest{
  47. Uid: tokenInfo.Uid,
  48. // 1业主 2家人 3租客
  49. UserType: req.UserType,
  50. Phone: req.Phone,
  51. Name: req.Name,
  52. HouseId: req.HouseId,
  53. // 1 身份证 2 护照
  54. IdType: req.IdType,
  55. // 证件号
  56. IdNumber: req.IdNumber,
  57. Appendix: req.Appendix,
  58. GardenId: req.GardenId,
  59. }
  60. rpcRsp, err := pb.Household.HouseholdApply(ctx, rpcReq)
  61. if err != nil {
  62. s, _ := json.MarshalToString(req)
  63. logger.Error("func",
  64. zap.String("call", "Garden.HouseholdApply"),
  65. zap.String("params", s),
  66. zap.String("error", err.Error()))
  67. return errors.ErrorTransForm(err)
  68. }
  69. resp.Data = *rpcRsp
  70. ctx.JSON(http.StatusOK, resp)
  71. return nil
  72. }
  73. // 执行任务
  74. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  75. }
  76. //
  77. // @Summary 房屋列表
  78. // @Description 房屋列表
  79. // @Tags 业主房屋
  80. // @Accept json
  81. // @Produce json
  82. // @Param token header string true " "
  83. // @Param approve_status query int true "1 待审核 2 通过审核 3 未通过审核"
  84. // @Success 200 {object} v1.HouseholdListResponse
  85. // @Failure 500 {object} base.HTTPError
  86. // @Router /api/v1/household/house [get]
  87. func (c *Controller) HouseholdList(ctx *gin.Context) {
  88. // 解析参数
  89. req := &param_v1.HouseholdListRequest{}
  90. parseParamTask := func() error {
  91. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdListQuery, 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. resp := param_v1.HouseholdListResponse{}
  107. rpcReq := &v1.HouseholdListRequest{
  108. Uid: tokenInfo.Uid,
  109. ApproveStatus: req.ApproveStatus,
  110. PageSize: -1,
  111. Page: -1,
  112. }
  113. rpcRsp, err := pb.Household.HouseholdList(ctx, rpcReq)
  114. if err != nil {
  115. s, _ := json.MarshalToString(req)
  116. logger.Error("func",
  117. zap.String("call", "Garden.HouseholdList"),
  118. zap.String("params", s),
  119. zap.String("error", err.Error()))
  120. return errors.ErrorTransForm(err)
  121. }
  122. if rpcRsp.List == nil {
  123. rpcRsp.List = make([]*v1.HouseholdItem, 0)
  124. }
  125. resp.Data = *rpcRsp
  126. ctx.JSON(http.StatusOK, resp)
  127. return nil
  128. }
  129. // 执行任务
  130. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  131. }
  132. //
  133. // @Summary 解绑房屋
  134. // @Description 解绑房屋
  135. // @Tags 业主房屋
  136. // @Accept json
  137. // @Produce json
  138. // @Param token header string true " "
  139. // @Param garden_id query int true " "
  140. // @Param house_id query int true " "
  141. // @Success 200 {object} v1.HouseholdListResponse
  142. // @Failure 500 {object} base.HTTPError
  143. // @Router /api/v1/household/house [delete]
  144. func (c *Controller) HouseholdDelHouse(ctx *gin.Context) {
  145. // 解析参数
  146. req := &param_v1.GardenHouseholdDelHouseRequest{}
  147. parseParamTask := func() error {
  148. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenHouseholdDelHouseQuery, nil)
  149. if err != nil {
  150. logger.Error("func",
  151. zap.String("call", "util.ShouldBind"),
  152. zap.String("error", err.Error()))
  153. return errors.ParamsError
  154. }
  155. return nil
  156. }
  157. // 业务处理
  158. handleServiceTask := func() error {
  159. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  160. if err != nil {
  161. return err
  162. }
  163. resp := param_v1.GardenHouseholdDelHouseResponse{}
  164. rpcReq := &v1.GardenHouseholdDelHouseRequest{
  165. HouseholdUid: tokenInfo.Uid,
  166. GardenId: req.GardenId,
  167. HouseId: req.HouseId,
  168. }
  169. _, err = pb.Garden.GardenHouseholdDelHouse(ctx, rpcReq)
  170. if err != nil {
  171. s, _ := json.MarshalToString(req)
  172. logger.Error("func",
  173. zap.String("call", "Garden.HouseholdList"),
  174. zap.String("params", s),
  175. zap.String("error", err.Error()))
  176. return errors.ErrorTransForm(err)
  177. }
  178. ctx.JSON(http.StatusOK, resp)
  179. return nil
  180. }
  181. // 执行任务
  182. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  183. }