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 page query int true " " // @Param page_size query int false " " // @Param group_id query int false "权限组id" // @Param user_name query string false "用户名" // @Param phone query string false "电话号" // @Success 200 {object} v1.UserListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/system_user [get] func (c *Controller) UserList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.UserListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.UserListQuery, 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.UserListResponse{} rpcReq := &v1.UserListRequest{ UserName:req.UserName, Phone:req.Phone, Cid:tokenInfo.Cid, GardenId:tokenInfo.GardenId, GroupId:req.GroupId, } rpcRsp, err := pb.System.UserList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.System.UserList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.UserItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }