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-system-gateway/errors" param_v1 "property-system-gateway/param/v1" "property-system-gateway/pb" "property-system-gateway/pb/v1" "property-system-gateway/utils" ) // // @Summary 审核业主 // @Description 审核业主 // @Tags 业主管理 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.HouseholdApproveBody true "信息" // @Success 200 {object} v1.HouseholdApproveResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/household/approve [put] func (c *Controller) HouseholdApprove(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseholdApproveRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.HouseholdApproveBody) 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.HouseholdApproveResponse{} rpcReq := &v1.HouseholdApproveRequest{ Id: req.Id, Status: req.Status, Feedback: req.Feedback, } _, err = pb.Household.HouseholdApprove(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseholdApprove"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) logReq := OperationLogRequest{ Module: ModuleHousehold, Action: ActionHouseholdApprove, Origin: "", Target: req.HouseholdApproveBody, 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 user_type query int false "业主身份类型" // @Param page query int false " " // @Param page_size query int false " " // @Param name query string false "业主姓名" // @Param approve_status query int false "0 未审核+未通过 1 未审核 2 已通过 3 未通过" // @Success 200 {object} v1.HouseholdListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/household/list [get] func (c *Controller) HouseholdList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseholdListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdListQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetSubjectValue(ctx) if err != nil { return err } // 响应数据 resp := param_v1.HouseholdListResponse{} if req.ApproveStatus == 2 { rpcReq := &v1.GardenHouseholdListRequest{ GardenId: tokenInfo.GardenId, Name: req.Name, UserType: req.UserType, PageSize: req.PageSize, Page: req.Page, } rpcRsp, err := pb.Garden.GardenHouseholdList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseholdList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.GardenHouseholdItem, 0) } data := v1.HouseholdListReply{} data.Page = rpcRsp.Page data.Total = rpcRsp.Total data.List = make([]*v1.HouseholdItem, len(rpcRsp.List)) for i, v := range rpcRsp.List { if v.Appendix == nil { v.Appendix = make([]string, 0) } data.List[i] = &v1.HouseholdItem{ Id: v.Id, // 1业主 2家人 3租客 UserType: v.UserType, Phone: v.Phone, Name: v.Name, Appendix: v.Appendix, // 1 身份证 2 护照 IdType: v.IdType, // 证件号 IdNumber: v.IdNumber, // 房号 HouseName: v.HouseName, ApproveStatus: v.ApproveStatus, GardenName: v.GardenName, HouseId: v.HouseId, Uid: v.Uid, } } resp.Data = data ctx.JSON(http.StatusOK, resp) return nil } rpcReq := &v1.HouseholdListRequest{ GardenId: tokenInfo.GardenId, Name: req.Name, UserType: req.UserType, ApproveStatus: req.ApproveStatus, PageSize: req.PageSize, Page: req.Page, } rpcRsp, err := pb.Household.HouseholdList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Household.HouseholdList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.HouseholdItem, 0) } for i, _ := range rpcRsp.List { if rpcRsp.List[i].Appendix == nil { rpcRsp.List[i].Appendix = make([]string, 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 user_type query int false "业主身份类型" // @Param page query int false " " // @Param page_size query int false " " // @Param name query string false "业主姓名" // @Param house_id query int false "房屋id" // @Param building_id query int false "楼栋id" // @Param unit_id query int false "单元id" // @Param gate_id query string false "门禁设备id" // @Success 200 {object} v1.HouseholdListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/household/user_list [get] func (c *Controller) HouseholdUserList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.HouseholdUserListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.HouseholdUserListQuery, 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 } excludeUids := []int64{} if req.GateId != "" { /*mReq := &v1.GateWhiteHouseholdListRequest{ Page: -1, PageSize: -1, DeviceId: req.GateId, GardenId: tokenInfo.GardenId, } mRsp, err := pb.Device.GateWhiteHouseholdList(ctx, mReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "Device.GateWhiteHouseholdList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } for _, v := range mRsp.List { excludeUids = append(excludeUids, v.HouseholdUid) }*/ } // 响应数据 resp := param_v1.HouseholdUserListResponse{} rpcReq := &v1.GardenHouseholdUserListRequest{ GardenId: tokenInfo.GardenId, Name: req.Name, UserType: req.UserType, PageSize: req.PageSize, Page: req.Page, HouseId: req.HouseId, ExcludeUids: excludeUids, BuildingId: req.BuildingId, UnitId: req.UnitId, Phone: req.Phone, } rpcRsp, err := pb.Garden.GardenHouseholdUserList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.GardenHouseholdUserList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.GardenHouseholdUserItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }