package v1 import ( "git.getensh.com/common/gopkgs/logger" "git.getensh.com/common/gopkgs/tasker/httptasker" "git.getensh.com/common/gopkgs/util" "github.com/gin-gonic/gin" "go.uber.org/zap" "net/http" "property-household-gateway/errors" param_v1 "property-household-gateway/param/v1" "property-household-gateway/pb" "property-household-gateway/pb/v1" "property-household-gateway/utils" ) // // @Summary 房屋认证申请 // @Description 房屋认证申请 // @Tags 业主房屋 // @Accept json // @Produce json // @Param token header string true " " // @Param body body v1.HouseholdApplyBody true "信息" // @Success 200 {object} v1.HouseholdApplyResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/household/apply [post] func (c *Controller) HouseholdApply(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseholdApplyRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseholdApplyBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetJwtTokenInfo(ctx) if err != nil { return err } resp := param_v1.HouseholdApplyResponse{} rpcReq := &v1.HouseholdApplyRequest{ Uid: tokenInfo.Uid, // 1业主 2家人 3租客 UserType: req.UserType, Phone: req.Phone, Name: req.Name, HouseId: req.HouseId, // 1 身份证 2 护照 IdType: req.IdType, // 证件号 IdNumber: req.IdNumber, Appendix: req.Appendix, GardenId: req.GardenId, } rpcRsp, err := pb.Household.HouseholdApply(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "Garden.HouseholdApply"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 房屋列表 // @Description 房屋列表 // @Tags 业主房屋 // @Accept json // @Produce json // @Param token header string true " " // @Param approve_status query int true "1 待审核 2 通过审核 3 未通过审核" // @Success 200 {object} v1.HouseholdListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/household/house [get] func (c *Controller) HouseholdList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseholdListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdListQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetJwtTokenInfo(ctx) if err != nil { return err } resp := param_v1.HouseholdListResponse{} rpcReq := &v1.HouseholdListRequest{ Uid: tokenInfo.Uid, ApproveStatus: req.ApproveStatus, PageSize: -1, Page: -1, } rpcRsp, err := pb.Household.HouseholdList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "Garden.HouseholdList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.HouseholdItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 解绑房屋 // @Description 解绑房屋 // @Tags 业主房屋 // @Accept json // @Produce json // @Param token header string true " " // @Param garden_id query int true " " // @Param house_id query int true " " // @Success 200 {object} v1.HouseholdListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/household/house [delete] func (c *Controller) HouseholdDelHouse(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenHouseholdDelHouseRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenHouseholdDelHouseQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetJwtTokenInfo(ctx) if err != nil { return err } resp := param_v1.GardenHouseholdDelHouseResponse{} rpcReq := &v1.GardenHouseholdDelHouseRequest{ HouseholdUid: tokenInfo.Uid, GardenId: req.GardenId, HouseId: req.HouseId, } _, err = pb.Garden.GardenHouseholdDelHouse(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "Garden.HouseholdList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }