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" ) // // @Summary 楼栋管家列表 // @Description 楼栋管家列表 // @Tags 小区 // @Accept json // @Produce json // @Param token header string true "token" // @Param garden_id query int true "小区id 必填" // @Param house_id query int true "房屋id 必填" // @Success 200 {object} v1.BuildingManagerListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/buildings/manager [get] func (c *Controller) BuildingManagerList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingManagerListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingManagerListQuery, 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 { // 响应数据 resp := param_v1.BuildingManagerListResponse{} rpcReq := &v1.BuildingManagerListRequest{ GardenId: req.GardenId, HouseId: req.HouseId, } rpcRsp, err := pb.Garden.BuildingManagerList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingManagerList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.BuildingManagerItem, 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 "小区id" // @Success 200 {object} v1.GardenInfoResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/info [get] func (c *Controller) GardenInfo(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenInfoRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenInfoQuery, 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 { resp := param_v1.GardenInfoResponse{} rpcReq := &v1.GardenInfosRequest{ Ids: []int64{req.GardenId}, } rpcRsp, err := pb.System.GardenInfos(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "System.GardenInfos"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if len(rpcRsp.List) > 0 { resp.Data = *rpcRsp.List[0] } 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 province_code query string false "省份代码" // @Param city_code query string false "城市代码" // @Param area_code query string false "区域代码" // @Param committee_code query string false "社区代码" // @Param street_code query string false "街道代码" // @Param garden_name query string false "小区名字" // @Param building_type query int false " 1塔楼 2 板楼 3 塔板结合 4 其他" // @Param building_year_greater query int false " 楼龄年份大于" // @Param building_year_less query int false " 楼龄小于" // @Param price_greater query int false " 均价大于" // @Param price_less query int false " 均价小于" // @Success 200 {object} v1.GardenListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/list [get] func (c *Controller) GardenList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenListQuery, 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 { resp := param_v1.GardenListResponse{} rpcReq := &v1.GardenListRequest{ Page: -1, PageSize: -1, CommitteeCode: req.CommitteeCode, StreetCode: req.StreetCode, GardenName: req.GardenName, BuildingYearGreater: req.BuildingYearGreater, BuildingYearLess: req.BuildingYearLess, BuildingType: req.BuildingType, ProvinceCode: req.ProvinceCode, AreaCode: req.AreaCode, CityCode: req.CityCode, PriceGreater: req.PriceGreater, PriceLess: req.PriceLess, Household: true, } rpcRsp, err := pb.System.GardenList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "System.GardenList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } for i, v := range rpcRsp.List { if len(v.WaterType) == 0 { rpcRsp.List[i].WaterType = []int32{} } if len(v.ElectricType) == 0 { rpcRsp.List[i].ElectricType = []int32{} } if len(v.GardenPics) == 0 { rpcRsp.List[i].GardenPics = []string{} } } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.GardenItem, 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 garden_id query string true "小区id" // @Success 200 {object} v1.BuildingListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/building [get] func (c *Controller) BuildingList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingListQuery, 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 { // 响应数据 resp := param_v1.BuildingListResponse{} rpcReq := &v1.BuildingListRequest{ GardenId: req.GardenId, Page: -1, PageSize: -1, } rpcRsp, err := pb.Garden.BuildingList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.BuildingItem, 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 building_id query int true "楼栋id" // @Param garden_id query string true "小区id" // @Success 200 {object} v1.UnitListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/unit [get] func (c *Controller) UnitList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.UnitListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitListQuery, 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 { // 响应数据 resp := param_v1.UnitListResponse{} rpcReq := &v1.UnitListRequest{ GardenId: req.GardenId, BuildingId: req.BuildingId, Page: -1, PageSize: -1, } rpcRsp, err := pb.Garden.UnitList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.UnitList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.UnitItem, 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 unit_id query int true "单元id" // @Param garden_id query string true "小区id" // @Param house_rent query bool false "true只返回还可以发布租房的房屋" // @Success 200 {object} v1.HouseListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/house [get] func (c *Controller) HouseList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseListQuery, 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 { // 响应数据 resp := param_v1.HouseListResponse{} rpcReq := &v1.HouseListRequest{ GardenId: req.GardenId, UnitId: req.UnitId, Page: -1, PageSize: -1, HouseRent: req.HouseRent, } rpcRsp, err := pb.Garden.HouseList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.HouseItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }