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-applete-gateway/errors" param_v1 "property-applete-gateway/param/v1" "property-applete-gateway/pb" "property-applete-gateway/pb/v1" "property-applete-gateway/utils" ) func BaseConfToBool(data int64) v1.HouseRentBaseConf { conf := v1.HouseRentBaseConf{} one := int64(1) if data & one > 0 { conf.Bed = true } if data & (one << 1) > 0{ conf.Gas = true } if data & (one << 2) > 0{ conf.WarmGas = true } if data & (one << 3) > 0{ conf.Broadband = true } if data & (one << 4) > 0{ conf.Refragerator = true } if data & (one << 5) > 0{ conf.Wardobe = true } if data & (one << 6) > 0{ conf.Sofa = true } if data & (one << 7) > 0{ conf.Aircondition = true } if data & (one << 8) > 0{ conf.Tv = true } if data & (one << 9) > 0{ conf.Heater = true } if data & (one << 10) > 0{ conf.Warshing = true } return conf } func SpecialConfToBool(data int64) v1.HouseRentSpecialConf { conf := v1.HouseRentSpecialConf{} one := int64(1) if data & one > 0 { conf.IntelligentLock = true } if data & (one << 1) > 0{ conf.Wifi = true } if data & (one << 2) > 0{ conf.Metro = true } if data & (one << 3) > 0{ conf.ParkSpace = true } if data & (one << 4) > 0{ conf.IndependentWc = true } if data & (one << 5) > 0{ conf.PrivateBalcony = true } if data & (one << 6) > 0{ conf.FirstRent = true } return conf } func BaseConfToBitmap(conf *v1.HouseRentBaseConf) int64 { ret := int64(0) one := int64(1) if conf.Bed { ret = ret |(one) } if conf.Gas { ret = ret |(one << 1) } if conf.WarmGas { ret = ret |(one << 2) } if conf.Broadband { ret = ret |(one << 3) } if conf.Refragerator { ret = ret |(one << 4) } if conf.Wardobe { ret = ret |(one << 5) } if conf.Sofa { ret = ret |(one << 6) } if conf.Aircondition { ret = ret |(one << 7) } if conf.Tv { ret = ret |(one << 8) } if conf.Heater { ret = ret |(one << 9) } if conf.Warshing { ret = ret |(one << 10) } return ret } func SpecialConfToBitmap(conf *v1.HouseRentSpecialConf) int64 { ret := int64(0) one := int64(1) if conf.IntelligentLock { ret = ret |(one) } if conf.Wifi { ret = ret |(one << 1) } if conf.Metro { ret = ret |(one << 2) } if conf.ParkSpace { ret = ret |(one << 3) } if conf.IndependentWc { ret = ret |(one << 4) } if conf.PrivateBalcony { ret = ret |(one << 5) } if conf.FirstRent { ret = ret |(one << 6) } return ret } /// // @Summary 租房列表 // @Description 租房列表 // @Tags 房屋租赁 // @Accept json // @Produce json // @Param token header string true "token" // @Param province_code query string false "省份代码" // @Param city_code query string false "城市代码" // @Param area_code query string false "区域代码" // @Param street_code query string false "街道代码" // @Param room_count query int false "几室" // @Param hall_count query int false "几厅" // @Param wc_count query int false "几卫" // @Param rent_price_greater query string false "租金大于" // @Param rent_price_less query string false "租金小于" // @Param approve_status query int false "审核状态 0 不过滤 1 待审核 2 通过 3 未通过" // @Param page query int false " " // @Param page_size query int false " " // @Param base_conf query int false "从低bit到高bit分别表示床 天然气 暖气 宽带 冰箱 衣柜 沙发 空调 电视机 热水器 洗衣机" // @Param special_conf query int false "从低到高分别表示 智能门锁 wifi 近地铁 停车位 独卫 私人阳台 首次出租" // @Success 200 {object} v1.HouseRentListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house [get] func (c *Controller) HouseRentList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentListQuery, 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentListResponse{} rpcReq := &v1.GardenHouseRentListRequest{ GardenId:tokenInfo.GardenId, ProvinceCode:req.ProvinceCode, CityCode:req.CityCode, AreaCode:req.AreaCode, StreetCode:req.StreetCode, RoomCount:req.RoomCount, HallCount:req.HallCount, WcCount:req.WcCount, RentPriceGreater:req.RentPriceGreater, RentPriceLess:req.RentPriceLess, ApproveStatus:req.ApproveStatus, Page:req.Page, PageSize:req.PageSize, //BaseConf: //SpecialConf } //baseConf := BaseConfToBool(req.BaseConf) //specialConf := SpecialConfToBool(req.SpecialConf) rpcReq.BaseConf = req.BaseConf rpcReq.SpecialConf = req.SpecialConf rpcRsp, err := pb.Garden.GardenHouseRentList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.GardenHouseRentList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.HouseRentItem, 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 "token" // @Param body body v1.HouseRentApplyBody true " " // @Success 200 {object} v1.HouseRentApplyResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house [post] func (c *Controller) HouseRentApply(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentApplyRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentApplyBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentApplyResponse{} rpcReq := &v1.HouseRentApplyRequest{ GardenId:tokenInfo.GardenId, WcCount:req.WcCount, HouseId:req.HouseId, // 朝向 Direction:req.Direction, // 1 精装 2 简装 3 清水 Decorating:req.Decorating, // 联系人 Contacter:req.Contacter, // 联系人电话 ContactPhone:req.ContactPhone, // 1 月付 2 季付 3 半年付 4 年付 PayTimeType:req.PayTimeType, // 1 整租 2 合租 3 转租 RentType:req.RentType, // 1 全部 2 主卧 3 次卧 RoomType:req.RoomType, // 房间面积 RoomArea:req.RoomArea, // 月租 RentPrice:req.RentPrice, // 押金 Desposit:req.Desposit, // 可入住时间 InTime:req.InTime, // 服务费 ServicePrice:req.ServicePrice, // 中介费 IntermediaryPrice:req.IntermediaryPrice, // 简介 Desc:req.Desc, // 房屋图片 HousePic:req.HousePic, // 房屋证件图片 CertPic:req.CertPic, // 是否直接通过审核 Approve:true, //BaseConf: //SpecialConf } //baseConf := BaseConfToBool(req.BaseConf) //specialConf := SpecialConfToBool(req.SpecialConf) rpcReq.BaseConf = req.BaseConf rpcReq.SpecialConf = req.SpecialConf rpcRsp, err := pb.Household.HouseRentApply(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseRentApply"), 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 "token" // @Param body body v1.HouseRentUpdateBody true " " // @Success 200 {object} v1.HouseRentUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house [put] func (c *Controller) HouseRentUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentUpdateBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentUpdateResponse{} rpcReq := &v1.HouseRentUpdateRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, WcCount:req.WcCount, HouseId:req.HouseId, // 朝向 Direction:req.Direction, // 1 精装 2 简装 3 清水 Decorating:req.Decorating, // 联系人 Contacter:req.Contacter, // 联系人电话 ContactPhone:req.ContactPhone, // 1 月付 2 季付 3 半年付 4 年付 PayTimeType:req.PayTimeType, // 1 整租 2 合租 3 转租 RentType:req.RentType, // 1 全部 2 主卧 3 次卧 RoomType:req.RoomType, // 房间面积 RoomArea:req.RoomArea, // 月租 RentPrice:req.RentPrice, // 押金 Desposit:req.Desposit, // 可入住时间 InTime:req.InTime, // 服务费 ServicePrice:req.ServicePrice, // 中介费 IntermediaryPrice:req.IntermediaryPrice, // 简介 Desc:req.Desc, // 房屋图片 HousePic:req.HousePic, // 房屋证件图片 CertPic:req.CertPic, } //baseConf := BaseConfToBool(req.BaseConf) //specialConf := SpecialConfToBool(req.SpecialConf) rpcReq.BaseConf = req.BaseConf rpcReq.SpecialConf = req.SpecialConf _, err = pb.Household.HouseRentUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseRentUpdate"), 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) } // // @Summary 审核 // @Description 审核 // @Tags 房屋租赁 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.HouseRentApproveBody true " " // @Success 200 {object} v1.HouseRentApproveResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/approve [put] func (c *Controller) HouseRentApprove(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentApproveRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentApproveBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentApproveResponse{} rpcReq := &v1.HouseRentApproveRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, Status:req.Status, Feedback:req.Feedback, } _, err = pb.Household.HouseRentApprove(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseRentApprove"), 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) } // // @Summary 下架 // @Description 下架 // @Tags 房屋租赁 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.HouseRentDownBody true " " // @Success 200 {object} v1.HouseRentDownResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/down [put] func (c *Controller) HouseRentDown(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentDownRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentDownBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentDownResponse{} rpcReq := &v1.HouseRentDownRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } _, err = pb.Household.HouseRentDown(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseRentDown"), 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) } // // @Summary 添加经纪人 // @Description 添加经纪人 // @Tags 房屋租赁 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.HouseRentAddManagerBody true " " // @Success 200 {object} v1.HouseRentAddManagerResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/manager [post] func (c *Controller) HouseRentAddManager(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentAddManagerRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseRentAddManagerBody) 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentAddManagerResponse{} rpcReq := &v1.HouseRentAddManagerRequest{ GardenId:tokenInfo.GardenId, RentId:req.RentId, ManagerUid:req.ManagerUid, } _, err = pb.Garden.HouseRentAddManager(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseRentAddManager"), 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) } // // @Summary 删除经纪人 // @Description 删除经纪人 // @Tags 房屋租赁 // @Accept json // @Produce json // @Param token header string true "token" // @Param id query int true "经纪人与房屋的关系id" // @Success 200 {object} v1.HouseRentDelManagerResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/manager [delete] func (c *Controller) HouseRentDelManager(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentDelManagerRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentDelManagerQuery,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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentDelManagerResponse{} rpcReq := &v1.HouseRentDelManagerRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } _, err = pb.Garden.HouseRentDelManager(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseRentDelManager"), 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) } // // @Summary 房屋的经纪人列表 // @Description 房屋的经纪人列表 // @Tags 房屋租赁 // @Accept json // @Produce json // @Param token header string true "token" // @Param rent_id query int true "租房信息id" // @Success 200 {object} v1.HouseRentManagerListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/manager [get] func (c *Controller) HouseRentManagerList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentManagerListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentManagerListQuery,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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentManagerListResponse{} rpcReq := &v1.HouseRentManagerListRequest{ GardenId:tokenInfo.GardenId, RentId:req.RentId, } rpcRsp, err := pb.Garden.HouseRentManagerList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseRentManagerList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.HouseRentManagerItem, 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 "token" // @Param house_name query string false "房屋全称" // @Param rent_id query int false "租房信息id" // @Param page query int false " " // @Param page_size query int false " " // @Success 200 {object} v1.HouseRentAppointmentListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/appointment [get] func (c *Controller) HouseRentAppointmentList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentAppointmentListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentAppointmentListQuery, 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentAppointmentListResponse{} rpcReq := &v1.HouseRentAppointmentListRequest{ GardenId:tokenInfo.GardenId, RentId:req.RentId, HouseName:req.HouseName, Page:req.Page, PageSize:req.PageSize, } rpcRsp, err := pb.Garden.HouseRentAppointmentList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseRentAppointmentList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.HouseRentAppointmentItem, 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 "token" // @Param id query int false "预约记录id" // @Success 200 {object} v1.HouseRentAppointmentDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/rent/house/appointment [delete] func (c *Controller) HouseRentAppointmentDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseRentAppointmentDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseRentAppointmentDelQuery, 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.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseRentAppointmentDelResponse{} rpcReq := &v1.HouseRentAppointmentDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } _, err = pb.Garden.HouseRentAppointmentDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseRentAppointmentDel"), 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) }