package v1 import ( "fmt" "git.getensh.com/common/gopkgs/logger" "git.getensh.com/common/gopkgs/tasker/httptasker" "git.getensh.com/common/gopkgs/util" "github.com/gin-gonic/gin" "github.com/tealeg/xlsx" "go.uber.org/zap" "google.golang.org/grpc/status" "net/http" "os" "path" "property-system-gateway/errors" param_v1 "property-system-gateway/param/v1" "property-system-gateway/parser" "property-system-gateway/pb" "property-system-gateway/pb/v1" "property-system-gateway/utils" "strconv" "strings" "time" ) // // @Summary 添加楼栋管家 // @Description 添加楼栋管家 // @Tags 楼栋管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.BuildingAddManagerBody true " " // @Success 200 {object} v1.BuildingAddManagerResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/manager [post] func (c *Controller) BuildingAddManager(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingAddManagerRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.BuildingAddManagerBody) 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.BuildingAddManagerResponse{} rpcReq := &v1.BuildingAddManagerRequest{ GardenId: tokenInfo.GardenId, BuildingId: req.BuildingId, ManagerUid: req.ManagerUid, } _, err = pb.Garden.BuildingAddManager(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingAddManager"), 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.BuildingDelManagerResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/manager [delete] func (c *Controller) BuildingDelManager(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BuildingDelManagerRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.BuildingDelManagerQuery, 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.BuildingDelManagerResponse{} rpcReq := &v1.BuildingDelManagerRequest{ GardenId: tokenInfo.GardenId, Id: req.Id, } _, err = pb.Garden.BuildingDelManager(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.BuildingDelManager"), 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 building_id query int true "楼栋id" // @Success 200 {object} v1.BuildingManagerListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/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 { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.BuildingManagerListResponse{} rpcReq := &v1.BuildingManagerListRequest{ GardenId: tokenInfo.GardenId, BuildingId: req.BuildingId, } 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 "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, BuildingId: req.BuildingId, } 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) } func handleHouseName(ctx *gin.Context, houseName string, tokenInfo utils.TokenInfo) (int64, int64, string, bool, error) { array := strings.Split(houseName, "-") if len(array) != 3 && len(array) != 1 { return 0, 0, "", false, status.Error(10003, "总房号格式错误") } // 纯房号 if len(array) == 1 { return 0, 0, array[0], false, nil } // 先找楼栋 rpcReq := &v1.BuildingListRequest{ GardenId: tokenInfo.GardenId, BuildingNumber: array[0], Page: -1, PageSize: -1, } rpcRsp, err := pb.Garden.BuildingList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(rpcReq) logger.Error("func", zap.String("call", "pb.Garden.BuildingList"), zap.String("params", s), zap.String("error", err.Error())) return 0, 0, "", false, errors.ErrorTransForm(err) } if len(rpcRsp.List) == 0 { return 0, 0, "", true, nil } // 再找单元 buildingId := rpcRsp.List[0].Id unitNumber, _ := strconv.Atoi(array[1]) mReq := &v1.UnitListRequest{ GardenId: tokenInfo.GardenId, BuildingId: buildingId, UnitNumber: int64(unitNumber), Page: -1, PageSize: -1, } mRsp, err := pb.Garden.UnitList(ctx, mReq) if err != nil { s, _ := json.MarshalToString(mReq) logger.Error("func", zap.String("call", "pb.Garden.UnitList"), zap.String("params", s), zap.String("error", err.Error())) return 0, 0, "", false, errors.ErrorTransForm(err) } if len(mRsp.List) == 0 { return 0, 0, "", true, nil } return buildingId, mRsp.List[0].Id, array[2], false, nil } // // @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 "门牌号906" // @Param house_name query int false "总房号 1-2-906" // @Param building_id query int false "楼栋id" // @Param unit_id query int false "单元id" // @Param household_uid 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{} resp.Data = v1.HouseListReply{ Page: 1, Total: 0, List: make([]*v1.HouseItem, 0), } if req.HouseName != "" { shouldReturn := false var err error req.BuildingId, req.UnitId, req.HouseNumber, shouldReturn, err = handleHouseName(ctx, req.HouseName, tokenInfo) if err != nil { return err } if shouldReturn { ctx.JSON(http.StatusOK, resp) return nil } } // 响应数据 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) } */ var HouseTypeM = map[string]int{ "住宅": 1, "商铺": 2, "办公": 3, } func parseHouseImportContent(fileName string) ([]*v1.BatchHouseItem, error) { f, err := xlsx.OpenFile(fileName) if err != nil { return nil, status.Error(10003, "xlsx 打开失败") } if len(f.Sheets) == 0 { return nil, status.Error(10003, "参数文件没有sheet") } sheet := f.Sheets[0] if len(sheet.Rows) == 0 { return nil, status.Error(10003, "文件为空") } if len(sheet.Rows) > 1005 { return nil, status.Error(10003, "单次导入不能超过一千条记录, 请分批导入") } list := []*v1.BatchHouseItem{} for i, row := range sheet.Rows { if len(row.Cells) < 9 { return nil, status.Error(10003, fmt.Sprintf("第%d行", i)+"列数错误,请使用模板") } if i == 0 { if row.Cells[0].Value != "楼栋编号" || row.Cells[1].Value != "单元编号" || row.Cells[2].Value != "房屋号" || row.Cells[3].Value != "房屋建筑面积" || row.Cells[4].Value != "房屋使用面积" || row.Cells[5].Value != "楼层" || //row.Cells[6].Value != "房屋类型" || !strings.Contains(row.Cells[6].Value, "房屋类型") || row.Cells[7].Value != "几室" || row.Cells[8].Value != "几厅" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"标题错误,请使用模板") } continue } buidingNumber := strings.TrimSpace(row.Cells[0].Value) unitNumberStr := strings.TrimSpace(row.Cells[1].Value) houseNumber := strings.TrimSpace(row.Cells[2].Value) houseAreaStr := strings.TrimSpace(row.Cells[3].Value) houseUsedAreaStr := strings.TrimSpace(row.Cells[4].Value) houseLevelStr := strings.TrimSpace(row.Cells[5].Value) houseTypeStr := strings.TrimSpace(row.Cells[6].Value) roomStr := strings.TrimSpace(row.Cells[7].Value) hallStr := strings.TrimSpace(row.Cells[8].Value) if buidingNumber == "" && unitNumberStr == "" && houseNumber == "" && houseAreaStr == "" && houseUsedAreaStr == "" && houseLevelStr == "" && houseTypeStr == "" && roomStr == "" && hallStr == "" { continue } if buidingNumber == "" || unitNumberStr == "" || houseNumber == "" || houseAreaStr == "" || houseUsedAreaStr == "" || houseLevelStr == "" || houseTypeStr == "" && roomStr == "" && hallStr == "" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"参数不能为空") } unitNumber, err := strconv.Atoi(unitNumberStr) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"单元格式错误") } houseArea, err := strconv.ParseFloat(houseAreaStr, 64) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"房屋建筑面积格式错误") } houseUsedArea, err := strconv.ParseFloat(houseUsedAreaStr, 64) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"房屋使用面积面积格式错误") } houseLevel, err := strconv.Atoi(houseLevelStr) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"楼层格式错误") } roomCount, err := strconv.Atoi(roomStr) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"几室格式错误") } hallCount, err := strconv.Atoi(hallStr) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"几厅格式错误") } houseType := HouseTypeM[houseTypeStr] if houseType == 0 { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"不支持的房屋类型,房屋类型只支持住宅、公寓、商铺") } item := &v1.BatchHouseItem{ BuildingNumber: buidingNumber, UnitNumber: int64(unitNumber), HouseNumber: houseNumber, HouseArea: houseArea, HouseUsedArea: houseUsedArea, HouseType: int64(houseType), Layer: int64(houseLevel), RoomCount: int64(roomCount), HallCount: int64(hallCount), } list = append(list, item) } return list, nil } func parseUnitImportContent(fileName string) ([]*v1.BatchUnitItem, error) { f, err := xlsx.OpenFile(fileName) if err != nil { return nil, status.Error(10003, "xlsx 打开失败") } if len(f.Sheets) == 0 { return nil, status.Error(10003, "参数文件没有sheet") } sheet := f.Sheets[0] if len(sheet.Rows) == 0 { return nil, status.Error(10003, "文件为空") } if len(sheet.Rows) > 1005 { return nil, status.Error(10003, "单次导入不能超过一千条记录, 请分批导入") } list := []*v1.BatchUnitItem{} for i, row := range sheet.Rows { if len(row.Cells) < 5 { return nil, status.Error(10003, fmt.Sprintf("第%d行", i)+"列数错误,请使用模板") } if i == 0 { if row.Cells[0].Value != "楼栋编号" || row.Cells[1].Value != "单元编号" || row.Cells[2].Value != "单元名称" || row.Cells[3].Value != "层数" || row.Cells[4].Value != "是否有电梯" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"标题错误,请使用模板") } continue } buidingNumber := strings.TrimSpace(row.Cells[0].Value) unitNumberStr := strings.TrimSpace(row.Cells[1].Value) unitName := strings.TrimSpace(row.Cells[2].Value) layersStr := strings.TrimSpace(row.Cells[3].Value) hasLiftStr := strings.TrimSpace(row.Cells[4].Value) if buidingNumber == "" && unitNumberStr == "" && unitName == "" && layersStr == "" && hasLiftStr == "" { continue } if buidingNumber == "" || unitNumberStr == "" || unitName == "" || layersStr == "" || hasLiftStr == "" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"参数不能为空") } unitNumber, err := strconv.Atoi(unitNumberStr) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"单元格式错误") } layers, err := strconv.Atoi(layersStr) if err != nil { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"层数格式错误") } hasLift := true if hasLiftStr == "否" { hasLift = false } else if hasLiftStr != "是" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"是否有电梯格式错误") } item := &v1.BatchUnitItem{ BuildingNumber: buidingNumber, UnitNumber: int64(unitNumber), UnitLayers: int64(layers), UnitName: unitName, HasLift: hasLift, } list = append(list, item) } return list, nil } func parseBuildingImportContent(fileName string) ([]*v1.BatchBuildingItem, error) { f, err := xlsx.OpenFile(fileName) if err != nil { return nil, status.Error(10003, "xlsx 打开失败") } if len(f.Sheets) == 0 { return nil, status.Error(10003, "参数文件没有sheet") } sheet := f.Sheets[0] if len(sheet.Rows) == 0 { return nil, status.Error(10003, "文件为空") } if len(sheet.Rows) > 1005 { return nil, status.Error(10003, "单次导入不能超过一千条记录, 请分批导入") } list := []*v1.BatchBuildingItem{} for i, row := range sheet.Rows { if len(row.Cells) < 4 { return nil, status.Error(10003, fmt.Sprintf("第%d行", i)+"列数错误,请使用模板") } if i == 0 { if row.Cells[0].Value != "楼栋编号" || row.Cells[1].Value != "楼栋名称" || row.Cells[2].Value != "楼栋建筑面积" || row.Cells[3].Value != "楼栋使用面积" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"标题错误,请使用模板") } continue } buidingNumber := strings.TrimSpace(row.Cells[0].Value) buildingName := strings.TrimSpace(row.Cells[1].Value) buildingAreaStr := strings.TrimSpace(row.Cells[2].Value) buildingUsedAreaStr := strings.TrimSpace(row.Cells[3].Value) if buidingNumber == "" && buildingName == "" { continue } if buidingNumber == "" || buildingName == "" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"参数不能为空") } buildingArea, err := strconv.ParseFloat(buildingAreaStr, 64) if err != nil && buildingAreaStr != "" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"楼栋面积格式错误") } buildingUsedArea, err := strconv.ParseFloat(buildingUsedAreaStr, 64) if err != nil && buildingUsedAreaStr != "" { return nil, status.Error(10003, fmt.Sprintf("第%d行", i+1)+"楼栋使用面积格式错误") } item := &v1.BatchBuildingItem{ BuildingNumber: buidingNumber, BuildingName: buildingName, BuildingArea: buildingArea, BuildingUsedArea: buildingUsedArea, } list = append(list, item) } return list, nil } // // @Summary 房屋导入 // @Description 房屋导入 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param file formData file true "file" // @Success 200 {object} v1.BatchHouseAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/house/import [post] func (c Controller) HouseImport(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BatchHouseAddRequest{} newFile := "" var tokenInfo utils.TokenInfo parseParamTask := func() error { var err error tokenInfo, err = utils.GetSubjectValue(ctx) if err != nil { return err } file, err := ctx.FormFile("file") if err != nil { return errors.SystemError } if file.Size > 10*1024*1024 { return status.Error(10003, "文件过大") } ext := path.Ext(file.Filename) if ext != ".xlsx" { return status.Error(10003, "仅支持xlsx文件格式") } newFile = fmt.Sprintf("power-%s-%d-%d.xlsx", file.Filename, tokenInfo.Uid, time.Now().UnixNano()) err = ctx.SaveUploadedFile(file, newFile) if err != nil { logger.Error("func", zap.String("call", "ctx.SaveUploadedFile"), zap.String("error", err.Error())) return status.Error(10003, "保存文件失败") } return nil } // 业务处理 handleServiceTask := func() error { list, err := parseHouseImportContent(newFile) if err != nil { os.Remove(newFile) return err } os.Remove(newFile) if len(list) == 0 { return nil } // 响应数据 resp := param_v1.BatchHouseAddResponse{} rpcReq := &v1.BatchHouseAddRequest{ GardenId: tokenInfo.GardenId, Houses: list, } _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "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 "token" // @Param file formData file true "file" // @Success 200 {object} v1.BatchHouseAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/unit/import [post] func (c Controller) UnitImport(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BatchHouseAddRequest{} newFile := "" var tokenInfo utils.TokenInfo parseParamTask := func() error { var err error tokenInfo, err = utils.GetSubjectValue(ctx) if err != nil { return err } file, err := ctx.FormFile("file") if err != nil { return errors.SystemError } if file.Size > 10*1024*1024 { return status.Error(10003, "文件过大") } ext := path.Ext(file.Filename) if ext != ".xlsx" { return status.Error(10003, "仅支持xlsx文件格式") } newFile = fmt.Sprintf("power-%s-%d-%d.xlsx", file.Filename, tokenInfo.Uid, time.Now().UnixNano()) err = ctx.SaveUploadedFile(file, newFile) if err != nil { logger.Error("func", zap.String("call", "ctx.SaveUploadedFile"), zap.String("error", err.Error())) return status.Error(10003, "保存文件失败") } return nil } // 业务处理 handleServiceTask := func() error { list, err := parseUnitImportContent(newFile) if err != nil { os.Remove(newFile) return err } os.Remove(newFile) if len(list) == 0 { return nil } // 响应数据 resp := param_v1.BatchHouseAddResponse{} rpcReq := &v1.BatchHouseAddRequest{ GardenId: tokenInfo.GardenId, Units: list, } _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "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 "token" // @Param file formData file true "file" // @Success 200 {object} v1.BatchHouseAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/building/import [post] func (c Controller) BuildingImport(ctx *gin.Context) { // 解析参数 req := ¶m_v1.BatchHouseAddRequest{} newFile := "" var tokenInfo utils.TokenInfo parseParamTask := func() error { var err error tokenInfo, err = utils.GetSubjectValue(ctx) if err != nil { return err } file, err := ctx.FormFile("file") if err != nil { return errors.SystemError } if file.Size > 10*1024*1024 { return status.Error(10003, "文件过大") } ext := path.Ext(file.Filename) if ext != ".xlsx" { return status.Error(10003, "仅支持xlsx文件格式") } newFile = fmt.Sprintf("power-%s-%d-%d.xlsx", file.Filename, tokenInfo.Uid, time.Now().UnixNano()) err = ctx.SaveUploadedFile(file, newFile) if err != nil { logger.Error("func", zap.String("call", "ctx.SaveUploadedFile"), zap.String("error", err.Error())) return status.Error(10003, "保存文件失败") } return nil } // 业务处理 handleServiceTask := func() error { list, err := parseBuildingImportContent(newFile) if err != nil { os.Remove(newFile) return err } os.Remove(newFile) if len(list) == 0 { return nil } // 响应数据 resp := param_v1.BatchHouseAddResponse{} rpcReq := &v1.BatchHouseAddRequest{ GardenId: tokenInfo.GardenId, Buildings: list, } _, err = pb.Garden.BatchHouseAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "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 } 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{} } } 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, GardenPics: req.GardenPics, BuildingStart: req.BuildingStart, BuildingEnd: req.BuildingEnd, PropertyFeeStart: req.PropertyFeeStart, PropertyFeeEnd: req.PropertyFeeEnd, GasFeeStart: req.GasFeeStart, GasFeeEnd: req.GasFeeEnd, BuildingArea: req.BuildingArea, BuildingCompany: req.BuildingCompany, CoveredArea: req.CoveredArea, GreenPercent: req.GreenPercent, AreaPercent: req.AreaPercent, SpaceInfo: req.SpaceInfo, SpaceTotal: req.SpaceTotal, HouseTotal: req.HouseTotal, BuildingType: req.BuildingType, WaterType: req.WaterType, ElectricType: req.ElectricType, AvgPrice: req.AvgPrice, } _, 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) } // // @Summary 获取单元模板 // @Description 获取单元模板 // @Tags 楼盘管理 // @Accept json // @Produce json // @Param token header string true "token" // @Success 200 {object} v1.TemplateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/unit/template [get] func (c *Controller) UnitTemplate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.TemplateRequest{} 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 { // 响应数据 resp := param_v1.TemplateResponse{} resp.Data.Url = parser.Conf.Oss.UnitTempUrl 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" // @Success 200 {object} v1.TemplateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/building/template [get] func (c *Controller) BuildingTemplate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.TemplateRequest{} 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 { // 响应数据 resp := param_v1.TemplateResponse{} resp.Data.Url = parser.Conf.Oss.BuildingTempUrl 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" // @Success 200 {object} v1.TemplateResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/buildings/house/template [get] func (c *Controller) HouseTemplate(ctx *gin.Context) { // 解析参数 req := ¶m_v1.TemplateRequest{} 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 { // 响应数据 resp := param_v1.TemplateResponse{} resp.Data.Url = parser.Conf.Oss.HouseTempUrl ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }