household.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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-applete-gateway/errors"
  10. param_v1 "property-applete-gateway/param/v1"
  11. "property-applete-gateway/pb"
  12. "property-applete-gateway/pb/v1"
  13. "property-applete-gateway/utils"
  14. )
  15. //
  16. // @Summary 审核业主
  17. // @Description 审核业主
  18. // @Tags 业主管理
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param body body v1.HouseholdApproveBody true "信息"
  23. // @Success 200 {object} v1.HouseholdApproveResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/household/approve [put]
  26. func (c *Controller) HouseholdApprove(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.HouseholdApproveRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseholdApproveBody)
  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.GetSubjectValue(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.HouseholdApproveResponse{}
  47. rpcReq := &v1.HouseholdApproveRequest{
  48. Id: req.Id,
  49. Status: req.Status,
  50. Feedback: req.Feedback,
  51. }
  52. _, err = pb.Household.HouseholdApprove(ctx, rpcReq)
  53. if err != nil {
  54. s, _ := json.MarshalToString(req)
  55. logger.Error("func",
  56. zap.String("call", "pb.Household.HouseholdApprove"),
  57. zap.String("params", s),
  58. zap.String("error", err.Error()))
  59. return errors.ErrorTransForm(err)
  60. }
  61. ctx.JSON(http.StatusOK, resp)
  62. logReq := OperationLogRequest{
  63. Module: ModuleHousehold,
  64. Action: ActionHouseholdApprove,
  65. Origin: "",
  66. Target: req.HouseholdApproveBody,
  67. UserName: tokenInfo.UserName,
  68. Uid: tokenInfo.Uid,
  69. Cid: tokenInfo.Cid,
  70. GardenId: tokenInfo.GardenId,
  71. }
  72. go OperationLogAdd(&logReq)
  73. return nil
  74. }
  75. // 执行任务
  76. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  77. }
  78. //
  79. // @Summary 申请列表
  80. // @Description 申请列表
  81. // @Tags 业主管理
  82. // @Accept json
  83. // @Produce json
  84. // @Param token header string true "token"
  85. // @Param user_type query int false "业主身份类型"
  86. // @Param page query int false " "
  87. // @Param page_size query int false " "
  88. // @Param name query string false "业主姓名"
  89. // @Param approve_status query int false "0 未审核+未通过 1 未审核 2 已通过 3 未通过"
  90. // @Success 200 {object} v1.HouseholdListResponse
  91. // @Failure 500 {object} base.HTTPError
  92. // @Router /api/v1/household/list [get]
  93. func (c *Controller) HouseholdList(ctx *gin.Context) {
  94. // 解析参数
  95. req := &param_v1.HouseholdListRequest{}
  96. parseParamTask := func() error {
  97. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdListQuery, nil)
  98. if err != nil {
  99. logger.Error("func",
  100. zap.String("call", "util.ShouldBind"),
  101. zap.String("error", err.Error()))
  102. return errors.ParamsError
  103. }
  104. return nil
  105. }
  106. // 业务处理
  107. handleServiceTask := func() error {
  108. tokenInfo, err := utils.GetSubjectValue(ctx)
  109. if err != nil {
  110. return err
  111. }
  112. // 响应数据
  113. resp := param_v1.HouseholdListResponse{}
  114. if req.ApproveStatus == 2 {
  115. rpcReq := &v1.GardenHouseholdListRequest{
  116. GardenId: tokenInfo.GardenId,
  117. Name: req.Name,
  118. UserType: req.UserType,
  119. PageSize: req.PageSize,
  120. Page: req.Page,
  121. }
  122. rpcRsp, err := pb.Garden.GardenHouseholdList(ctx, rpcReq)
  123. if err != nil {
  124. s, _ := json.MarshalToString(req)
  125. logger.Error("func",
  126. zap.String("call", "pb.Household.HouseholdList"),
  127. zap.String("params", s),
  128. zap.String("error", err.Error()))
  129. return errors.ErrorTransForm(err)
  130. }
  131. if rpcRsp.List == nil {
  132. rpcRsp.List = make([]*v1.GardenHouseholdItem, 0)
  133. }
  134. data := v1.HouseholdListReply{}
  135. data.Page = rpcRsp.Page
  136. data.Total = rpcRsp.Total
  137. data.List = make([]*v1.HouseholdItem, len(rpcRsp.List))
  138. for i, v := range rpcRsp.List {
  139. data.List[i] = &v1.HouseholdItem{
  140. Id:v.Id,
  141. // 1业主 2家人 3租客
  142. UserType:v.UserType,
  143. Phone:v.Phone,
  144. Name:v.Name,
  145. Appendix:v.Appendix,
  146. // 1 身份证 2 护照
  147. IdType:v.IdType,
  148. // 证件号
  149. IdNumber:v.IdNumber,
  150. // 房号
  151. HouseName:v.HouseName,
  152. ApproveStatus:v.ApproveStatus,
  153. GardenName:v.GardenName,
  154. }
  155. }
  156. resp.Data = data
  157. ctx.JSON(http.StatusOK, resp)
  158. return nil
  159. }
  160. rpcReq := &v1.HouseholdListRequest{
  161. GardenId: tokenInfo.GardenId,
  162. Name: req.Name,
  163. UserType: req.UserType,
  164. ApproveStatus: req.ApproveStatus,
  165. PageSize: req.PageSize,
  166. Page: req.Page,
  167. }
  168. rpcRsp, err := pb.Household.HouseholdList(ctx, rpcReq)
  169. if err != nil {
  170. s, _ := json.MarshalToString(req)
  171. logger.Error("func",
  172. zap.String("call", "pb.Household.HouseholdList"),
  173. zap.String("params", s),
  174. zap.String("error", err.Error()))
  175. return errors.ErrorTransForm(err)
  176. }
  177. if rpcRsp.List == nil {
  178. rpcRsp.List = make([]*v1.HouseholdItem, 0)
  179. }
  180. resp.Data = *rpcRsp
  181. ctx.JSON(http.StatusOK, resp)
  182. return nil
  183. }
  184. // 执行任务
  185. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  186. }
  187. //
  188. // @Summary 业主信息
  189. // @Description 业主信息
  190. // @Tags 业主管理
  191. // @Accept json
  192. // @Produce json
  193. // @Param token header string true "token"
  194. // @Param user_type query int false "业主身份类型"
  195. // @Param page query int false " "
  196. // @Param page_size query int false " "
  197. // @Param name query string false "业主姓名"
  198. // @Param house_id query int false "房屋id"
  199. // @Success 200 {object} v1.HouseholdListResponse
  200. // @Failure 500 {object} base.HTTPError
  201. // @Router /api/v1/household/user_list [get]
  202. func (c *Controller) HouseholdUserList(ctx *gin.Context) {
  203. // 解析参数
  204. req := &param_v1.HouseholdUserListRequest{}
  205. parseParamTask := func() error {
  206. err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdUserListQuery, nil)
  207. if err != nil {
  208. logger.Error("func",
  209. zap.String("call", "util.ShouldBind"),
  210. zap.String("error", err.Error()))
  211. return errors.ParamsError
  212. }
  213. return nil
  214. }
  215. // 业务处理
  216. handleServiceTask := func() error {
  217. tokenInfo, err := utils.GetSubjectValue(ctx)
  218. if err != nil {
  219. return err
  220. }
  221. // 响应数据
  222. resp := param_v1.HouseholdUserListResponse{}
  223. rpcReq := &v1.GardenHouseholdUserListRequest{
  224. GardenId: tokenInfo.GardenId,
  225. Name: req.Name,
  226. UserType: req.UserType,
  227. PageSize: req.PageSize,
  228. Page: req.Page,
  229. HouseId:req.HouseId,
  230. }
  231. rpcRsp, err := pb.Garden.GardenHouseholdUserList(ctx, rpcReq)
  232. if err != nil {
  233. s, _ := json.MarshalToString(req)
  234. logger.Error("func",
  235. zap.String("call", "pb.Garden.GardenHouseholdUserList"),
  236. zap.String("params", s),
  237. zap.String("error", err.Error()))
  238. return errors.ErrorTransForm(err)
  239. }
  240. if rpcRsp.List == nil {
  241. rpcRsp.List = make([]*v1.GardenHouseholdUserItem, 0)
  242. }
  243. resp.Data = *rpcRsp
  244. ctx.JSON(http.StatusOK, resp)
  245. return nil
  246. }
  247. // 执行任务
  248. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  249. }