Example #1
0
        /// <summary>
        /// 从某个角色列表中轮循获取一个用户,在线的用户优先。
        /// </summary>
        /// <param name="roleCode">角色编号</param>
        /// <returns>用户主键</returns>
        public string GetRandomUserId(string systemCode, string roleCode)
        {
            string result = string.Empty;

            // 先不管是否在线,总需要能发一个人再说
            string[] userIds = GetUserIdsByRole(systemCode, roleCode);
            if (userIds != null && userIds.Length > 0)
            {
                int index = userIndex % userIds.Length;
                result = userIds[index];

                // 接着再判断是否有人在线,若有在线的,发给在线的用户
                BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(this.DbHelper);
                userIds = userLogOnManager.GetOnLineUserIds(userIds);
                if (userIds != null && userIds.Length > 0)
                {
                    index  = userIndex % userIds.Length;
                    result = userIds[index];
                }
            }
            userIndex++;

            return(result);
        }