Example #1
0
        public static void GetUsersByDepId(long depId, long offSet, long size)
        {
            try
            {
                DefaultDingTalkClient     client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage");
                OapiUserListbypageRequest request = new OapiUserListbypageRequest();
                request.DepartmentId = depId;
                request.Offset       = offSet;
                request.Size         = size;
                request.Order        = "entry_desc";
                request.SetHttpMethod("GET");
                OapiUserListbypageResponse execute = client.Execute(request, Get_Access_Token());
                if (execute != null && execute.Errcode == 0 && execute.Userlist != null && execute.Userlist.Count > 0)
                {
                    userlistDomains = userlistDomains.Union(execute.Userlist).ToList();

                    if (execute.HasMore)
                    {
                        GetUsersByDepId(depId, ++offSet * size, size);
                    }
                }
                //根据userid去重
                userlistDomains.Where((x, y) => userlistDomains.FindIndex(z => z.Userid == x.Userid) == y).ToList();
            }
            catch (Exception ex)
            {
                log.Info("部门下所有用户" + ex.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 获取某部门下的用户详情
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="departmentId">获取的部门id,1表示根部门</param>
        /// <param name="size">此参数代表分页大小,最大100</param>
        /// <param name="offset">此参数代表偏移量</param>
        /// <returns></returns>
        public static List <UserDetailInfo> GetUserInfoByPage(string accessToken, long departmentId = 1, long size = 100, long offset = 0)
        {
            try
            {
                IDingTalkClient           client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage");
                OapiUserListbypageRequest request = new OapiUserListbypageRequest();
                request.DepartmentId = departmentId;
                request.Offset       = offset;
                request.Size         = size;
                request.Order        = "entry_desc";
                request.SetHttpMethod("GET");

                OapiUserListbypageResponse response = client.Execute(request, accessToken);
                if (response != null)
                {
                    if (response.Errcode == 0)
                    {
                        List <UserDetailInfo> userlist = new List <UserDetailInfo>();
                        if (response.Userlist != null && response.Userlist.Count > 0)
                        {
                            foreach (OapiUserListbypageResponse.UserlistDomain info in response.Userlist)
                            {
                                UserDetailInfo user = new UserDetailInfo();
                                user.UserId   = info.Userid;
                                user.UserName = info.Name;
                                user.Unionid  = info.Unionid;
                                user.IsAdmin  = info.IsAdmin;
                                user.IsBoss   = info.IsBoss;
                                user.Active   = info.Active;
                                //user.Department = info.Department;
                                user.Email     = info.Email;
                                user.HiredDate = info.HiredDate;
                                user.IsHide    = info.IsHide;
                                user.IsLeader  = info.IsLeader;
                                user.JobNumber = info.Jobnumber;
                                user.Mobile    = info.Mobile;
                                user.Order     = info.Order;
                                userlist.Add(user);
                            }
                        }
                        return(userlist);
                    }
                    else
                    {
                        throw new Exception(response.Errmsg);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(null);
        }
Example #3
0
        /// <summary>
        /// 分页获取部门用户
        /// </summary>
        /// <param name="departId"  cref="DingDepartment">部门id</param>
        /// <param name="offset">页码</param>
        /// <param name="size">页数</param>
        /// <param name="order" cref="UserOrder">排序规则</param>
        public string GetListByPage(long departId, long offset = 0, long size = 100, UserOrder order = UserOrder.custom)
        {
            IDingTalkClient           client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage");
            OapiUserListbypageRequest request = new OapiUserListbypageRequest();

            request.DepartmentId = departId;
            request.Offset       = offset;
            request.Size         = size;
            request.Order        = Enum.GetName(typeof(UserOrder), order);
            request.SetHttpMethod("GET");
            OapiUserListbypageResponse response = client.Execute(request, base.AccessToken);

            return(response.Body);
        }
Example #4
0
        /// <summary>
        /// 获取部门用户详情
        /// </summary>
        /// <param name="accessToken">accessToken</param>
        /// <param name="departmentId">获取的部门id,1表示根部门</param>
        /// <param name="offSet">支持分页查询,与size参数同时设置时才生效,此参数代表偏移量,偏移量从0开始</param>
        /// <param name="size">支持分页查询,与offset参数同时设置时才生效,此参数代表分页大小,最大100</param>
        /// <param name="order">支持分页查询,部门成员的排序规则,默认 是按自定义排序;
        ///entry_asc:代表按照进入部门的时间升序,
        ///entry_desc:代表按照进入部门的时间降序,
        ///modify_asc:代表按照部门信息修改时间升序,
        ///modify_desc:代表按照部门信息修改时间降序,
        ///custom:代表用户定义(未定义时按照拼音)排序</param>
        /// <returns></returns>
        public OapiUserListbypageResponse ListByPage(string accessToken, long departmentId, long offSet, long size, string order = "entry_desc")
        {
            IDingTalkClient           client  = new DefaultDingTalkClient("https://oapi.dingtalk.com/user/listbypage");
            OapiUserListbypageRequest request = new OapiUserListbypageRequest();

            request.DepartmentId = departmentId;
            request.Offset       = offSet;
            request.Size         = size;
            request.Order        = order;
            request.SetHttpMethod("GET");
            OapiUserListbypageResponse res = client.Execute(request, accessToken);

            return(res);
        }