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" ) // // @Summary 添加楼栋 // @Description 添加楼栋 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.BuildingAddBody true "信息" // @Success 200 {object} v1.BuildingAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/building [post] func (c *Controller) BuildingAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingAddBody) 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.BuildingAddResponse{} rpcReq := &v1.BuildingAddRequest{ GardenId:tokenInfo.GardenId, BuildingNumber:req.BuildingNumber, BuildingName:req.BuildingName, BuildingArea:req.BuildingArea, BuildingUsedArea:req.BuildingUsedArea, Comment:req.Comment, } rpcRsp, err := pb.Garden.BuildingAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingAdd"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenAddBuilding, Origin:nil, Target:req.BuildingAddBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 更改楼栋 // @Description 更改楼栋 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.BuildingUpdateBody true "信息" // @Success 200 {object} v1.BuildingUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/building [put] func (c *Controller) BuildingUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingUpdateBody) 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.BuildingUpdateResponse{} rpcReq := &v1.BuildingUpdateRequest{ GardenId:tokenInfo.GardenId, BuildingNumber:req.BuildingNumber, BuildingName:req.BuildingName, BuildingArea:req.BuildingArea, BuildingUsedArea:req.BuildingUsedArea, Comment:req.Comment, Id:req.Id, } rpcRsp, err := pb.Garden.BuildingUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingUpdate"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenUpdateBuilding, Origin:rpcRsp.Origin, Target:req.BuildingUpdateBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) 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.BuildingDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/building [delete] func (c *Controller) BuildingDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingDelQuery, 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.BuildingDelResponse{} rpcReq := &v1.BuildingDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } rpcRsp, err := pb.Garden.BuildingDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenDelBuilding, Origin:rpcRsp.Origin, Target:nil, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 楼栋列表 // @Description 楼栋列表 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param building_number query string false "楼栋编号" // @Success 200 {object} v1.BuildingListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/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 { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.BuildingListResponse{} rpcReq := &v1.BuildingListRequest{ GardenId:tokenInfo.GardenId, BuildingNumber:req.BuildingNumber, Page:req.Page, PageSize:req.PageSize, } 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 body body v1.UnitAddBody true "信息" // @Success 200 {object} v1.UnitAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/unit [post] func (c *Controller) UnitAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.UnitAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UnitAddBody) 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.UnitAddResponse{} rpcReq := &v1.UnitAddRequest{ GardenId:tokenInfo.GardenId, UnitNumber:req.UnitNumber, UnitName:req.UnitName, UnitLayers:req.UnitLayers, BuildingId:req.BuildingId, HasLift:req.HasLift, } rpcRsp, err := pb.Garden.UnitAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.UnitAdd"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenAddUnit, Origin:nil, Target:req.UnitAddBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 更改单元 // @Description 更改单元 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.UnitUpdateBody true "信息" // @Success 200 {object} v1.UnitUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/unit [put] func (c *Controller) UnitUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.UnitUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UnitUpdateBody) 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.UnitUpdateResponse{} rpcReq := &v1.UnitUpdateRequest{ GardenId:tokenInfo.GardenId, UnitNumber:req.UnitNumber, UnitName:req.UnitName, UnitLayers:req.UnitLayers, BuildingId:req.BuildingId, HasLift:req.HasLift, Id:req.Id, } rpcRsp, err := pb.Garden.UnitUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.UnitUpdate"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenUpdateUnit, Origin:rpcRsp.Origin, Target:req.UnitUpdateBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) 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.UnitDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/unit [delete] func (c *Controller) UnitDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.UnitDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.UnitDelQuery, 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.UnitDelResponse{} rpcReq := &v1.UnitDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } rpcRsp, err := pb.Garden.UnitDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.UnitDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenDelUnit, Origin:rpcRsp.Origin, Target:nil, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 单元列表 // @Description 单元列表 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param unit_number query int false "单元编号" // @Param building_id query int false "楼栋id" // @Success 200 {object} v1.UnitListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/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 { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.UnitListResponse{} rpcReq := &v1.UnitListRequest{ GardenId:tokenInfo.GardenId, UnitNumber:req.UnitNumber, BuildingId:req.BuildingId, Page:req.Page, PageSize:req.PageSize, } 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 body body v1.HouseAddBody true "信息" // @Success 200 {object} v1.HouseAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/house [post] func (c *Controller) HouseAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseAddBody) 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.HouseAddResponse{} rpcReq := &v1.HouseAddRequest{ GardenId:tokenInfo.GardenId, UnitId:req.UnitId, HouseNumber:req.HouseNumber, HouseType:req.HouseType, HouseUsedArea:req.HouseUsedArea, HouseArea:req.HouseArea, Layer:req.Layer, RoomCount:req.RoomCount, HallCount:req.HallCount, } rpcRsp, err := pb.Garden.HouseAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseAdd"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenAddHouse, Origin:nil, Target:req.HouseAddBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 更改房屋 // @Description 更改房屋 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.HouseUpdateBody true "信息" // @Success 200 {object} v1.HouseUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/house [put] func (c *Controller) HouseUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseUpdateBody) 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.HouseUpdateResponse{} rpcReq := &v1.HouseUpdateRequest{ GardenId:tokenInfo.GardenId, UnitId:req.UnitId, HouseNumber:req.HouseNumber, HouseType:req.HouseType, HouseUsedArea:req.HouseUsedArea, HouseArea:req.HouseArea, Layer:req.Layer, RoomCount:req.RoomCount, HallCount:req.HallCount, Id:req.Id, } rpcRsp, err := pb.Garden.HouseUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseUpdate"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenUpdateHouse, Origin:rpcRsp.Origin, Target:req.HouseUpdateBody, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) 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.HouseDelResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/house [delete] func (c *Controller) HouseDel(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseDelRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseDelQuery, 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.HouseDelResponse{} rpcReq := &v1.HouseDelRequest{ GardenId:tokenInfo.GardenId, Id:req.Id, } rpcRsp, err := pb.Garden.HouseDel(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.HouseDel"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module:ModuleGarden, Action:ActionGardenDelHouse, Origin:rpcRsp.Origin, Target:nil, UserName:tokenInfo.UserName, Uid:tokenInfo.Uid, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, } go OperationLogAdd(&logReq) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 房屋列表 // @Description 房屋列表 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param house_number query int false "门牌号" // @Param building_id query int false "楼栋id" // @Param unit_id query int false "单元id" // @Param household_id query int false "住户uid" // @Param house_type query int false "房屋类型 1 住宅 2 商铺 3 办公" // @Param house_rent query bool false "是否用于房屋租赁 true 是 false 否" // @Success 200 {object} v1.HouseListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/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 { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseListResponse{} rpcReq := &v1.HouseListRequest{ GardenId:tokenInfo.GardenId, HouseNumber:req.HouseNumber, HouseType:req.HouseType, BuildingId:req.BuildingId, UnitId:req.UnitId, Page:req.Page, PageSize:req.PageSize, Uid:req.HouseholdUid, 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) } // // @Summary 批量添加 // @Description 批量添加 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.BatchHouseAddBody true "信息" // @Success 200 {object} v1.HouseAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/batch [post] func (c *Controller) BatchHouseAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BatchHouseAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BatchHouseAddBody) 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.BatchHouseAddResponse{} rpcReq := &v1.BatchHouseAddRequest{ GardenId:tokenInfo.GardenId, } rpcReq.Buildings = make([]*v1.BatchBuildingItem, len(req.Buildings)) for i, _ := range req.Buildings { rpcReq.Buildings[i] = &req.Buildings[i] } rpcReq.Units = make([]*v1.BatchUnitItem, len(req.Units)) for i, _ := range req.Units { rpcReq.Units[i] = &req.Units[i] } rpcReq.Houses = make([]*v1.BatchHouseItem, len(req.Houses)) for i, _ := range req.Houses { rpcReq.Houses[i] = &req.Houses[i] } _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BatchHouseAdd"), 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 " " // @Success 200 {object} v1.GardenInfoResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden [get] func (c *Controller) GardenInfo(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenInfoRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, 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.GardenInfoResponse{} rpcReq := &v1.GardenInfosRequest{ Ids:[]int64{tokenInfo.GardenId}, } rpcRsp, err := pb.System.GardenInfos(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "Garden.GardenInfos"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { return errors.ErrRecordNotFound } 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 body body v1.GardenUpdateBody true "小区信息" // @Success 200 {object} v1.GardenUpdateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden [put] func (c *Controller) GardenUpdate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenUpdateRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenUpdateBody) 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.GardenUpdateResponse{} rpcReq := &v1.GardenUpdateRequest{ //Province: req.Province, //ProvinceCode: req.ProvinceCode, //City: req.City, //CityCode: req.CityCode, //Area: req.Area, //AreaCode: req.AreaCode, //Street: req.Street, //StreetCode: req.StreetCode, //Committee: req.Committee, //CommitteeCode: req.CommitteeCode, PropertyPerson: req.PropertyPerson, PropertyPhone: req.PropertyPhone, //GardenName: req.GardenName, GardenAddr: req.GardenAddr, Cid: tokenInfo.Cid, Id:tokenInfo.GardenId, GardenPic:req.GardenPic, GardenDesc:req.GardenDesc, Lnt:req.Lnt, Lat:req.Lat, } _, err = pb.System.GardenUpdate(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.GardenUpdate"), 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 " " // @Param body body v1.GardenKeyInfoChangeBody true "小区信息" // @Success 200 {object} v1.GardenKeyInfoChangeResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/key_info [put] func (c *Controller) GardenKeyInfoChange(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenKeyInfoChangeRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.GardenKeyInfoChangeBody) 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.GardenKeyInfoChangeResponse{} rpcReq := &v1.GardenKeyInfoChangeRequest{ Province: req.Province, ProvinceCode: req.ProvinceCode, City: req.City, CityCode: req.CityCode, Area: req.Area, AreaCode: req.AreaCode, Street: req.Street, StreetCode: req.StreetCode, Committee: req.Committee, CommitteeCode: req.CommitteeCode, Cid: tokenInfo.Cid, Id:tokenInfo.GardenId, GardenName:req.GardenName, } _, err = pb.System.GardenKeyInfoChange(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.GardenKeyInfoChange"), 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 " " // @Param page query int false " " // @Param page_size query int false " " // @Param status query int false "0不过率 1 待审核 2 审核通过 3 未通过 " // @Success 200 {object} v1.GardenKeyInfoChangeListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/garden/key_info [get] func (c *Controller) GardenKeyInfoChangeList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.GardenKeyInfoChangeListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenKeyInfoChangeListQuery, 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.GardenKeyInfoChangeListResponse{} rpcReq := &v1.GardenKeyInfoChangeListRequest{ Cid: tokenInfo.Cid, GardenId:tokenInfo.GardenId, Status:req.Status, Page:req.Page, PageSize:req.PageSize, } rpcRsp, err := pb.System.GardenKeyInfoChangeList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.GardenKeyInfoChangeList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.GardenKeyInfoData, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }