/// <summary>
        /// 获取用户菜肴权重
        /// </summary>
        /// <param name="userIdx"></param>
        /// <returns></returns>
        public string GetUserCookPriority(string userIdx)
        {
            string priorityJson = string.Empty;

            DataAccessManager.ExecuteCommand("GetUserCookPriority", cmd => priorityJson = cmd.ExecuteScalar <string>(new { UserID = userIdx }));
            return(priorityJson);
        }
        public bool CheckSession(string uid, string session)
        {
            var reslut = false;

            DataAccessManager.ExecuteCommand("CheckSession", cmd =>
            {
                reslut = Boolean.TryParse(cmd.ExecuteScalar(new { UserID = uid, Session = session }).ToString(), out reslut) & reslut;
            });
            return(reslut);
        }
        public bool IsUserExists(string uid)
        {
            var reslut = false;

            DataAccessManager.ExecuteCommand("IsUserExists", cmd =>
            {
                reslut = Boolean.TryParse(cmd.ExecuteScalar(new { UserID = uid }).ToString(), out reslut) & reslut;
            });
            return(reslut);
        }
        public bool DeleteUser(string uid)
        {
            var execute = false;

            DataAccessManager.ExecuteCommand("DeleteUser", cmd =>
            {
                execute = cmd.ExecuteNonQuery(new { UserID = uid }) != 0;
            });
            return(execute);
        }
        public bool FindExists(SessionBase session)
        {
            bool result = false;

            DataAccessManager.ExecuteCommand("IsSessionExists", cmd =>
            {
                result = cmd.ExecuteScalar <bool>(new { Session = session.SessionText });
            });
            return(result);
        }
        private int OperationInvoke <T>(string cmdName, T entity, string operationType)
        {
            int returnValue = 0;

            DataAccessManager.ExecuteCommand(cmdName, cmd =>
            {
                dynamic o   = new { Entity = entity, OpType = operationType };
                returnValue = cmd.ExecuteNonQuery(o);
            });
            return(returnValue);
        }
        public string OperationUserLocation(ERUserLocationEntity location, string operationType)
        {
            string returnValue = string.Empty;

            DataAccessManager.ExecuteCommand("OperationUserLocation", cmd =>
            {
                dynamic o   = new { Entity = location, OpType = operationType };
                returnValue = cmd.ExecuteNonQuery(o) != 0 ? location.UserID : string.Empty;
            });
            return(returnValue);
        }
        public bool UpdateUser(IUserBase userEntity)
        {
            var fullUser = userEntity as ERUserEntity;
            var execute  = false;

            if (fullUser != null)
            {
                DataAccessManager.ExecuteCommand("UpdateUser", cmd =>
                {
                    execute = cmd.ExecuteNonQuery(userEntity) != 0;
                });
            }
            return(execute);
        }
        public string CreateUser(string uid, string pwd)
        {
            var session    = SessionBuilder.BuildSession(uid, uid, TimeSpan.FromDays(10));
            var execute    = false;
            var encryptPwd = CommonUtilities.Encrypt(pwd);

            DataAccessManager.ExecuteCommand("CreateUser", cmd =>
            {
                dynamic parameters =
                    new { UserID = uid, Password = encryptPwd, Session = session.SessionText };
                execute = cmd.ExecuteNonQuery(parameters) != 0;
            });

            return(execute ? session.SessionText : String.Empty);
        }
        /// <summary>
        /// 获取队伍操作信息
        /// </summary>
        /// <param name="teamId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public ERTeamOperationEntity GetTeamOperation(string teamId, string userId)
        {
            ERTeamOperationEntity teamOp = null;

            DataAccessManager.ExecuteCommand("GetTeamOperation", cmd =>
            {
                using (var reader = cmd.ExecuteDataReader(new { TeamID = teamId, UserID = userId }))
                {
                    while (reader.Read())
                    {
                        teamOp = new ERTeamOperationEntity();
                        teamOp.Build(reader);
                    }
                }
            });
            return(teamOp);
        }
        public IUserBase LoginForSession(string uid, string pwd)
        {
            var encryptPwd = CommonUtilities.Encrypt(pwd);
            var user       = new ERUserEntity {
                UserID = uid, Password = encryptPwd
            };

            DataAccessManager.ExecuteCommand("GetUserByIDAndPassword", cmd =>
            {
                using (var reader = cmd.ExecuteDataReader(user))
                {
                    reader.Read();
                    user.Build(reader);
                }
            });
            return(user);
        }
        private List <T> GetEntityList <T>(string cmdName, dynamic param) where T : AutoAssignValueDataBase
        {
            var  entities   = new List <T>();
            Type entityTpye = typeof(T);

            DataAccessManager.ExecuteCommand(cmdName, cmd =>
            {
                using (var reader = cmd.ExecuteDataReader(param))
                {
                    while (reader.Read())
                    {
                        var entity = (T)Activator.CreateInstance(entityTpye);
                        entity.Build(reader);
                        entities.Add(entity);
                    }
                }
            });
            return(entities);
        }
        /// <summary>
        /// 获取多个用户位置
        /// </summary>
        /// <param name="userIds"></param>
        /// <returns></returns>
        public List <ERUserLocationEntity> GetUsersLocation(List <string> userIds)
        {
            var usersLocation = new List <ERUserLocationEntity>();
            var sb            = new StringBuilder();

            foreach (string id in userIds)
            {
                sb.AppendFormat("'{0}',", id);
            }
            DataAccessManager.ExecuteCommand("GetUsersLocation", cmd =>
            {
                cmd.CommandText = cmd.CommandText.Replace("#IDs#", sb.ToString().TrimEnd(','));
                using (var reader = cmd.ExecuteDataReader())
                {
                    while (reader.Read())
                    {
                        var userLocation = new ERUserLocationEntity();
                        userLocation.Build(reader);
                        usersLocation.Add(userLocation);
                    }
                }
            });
            return(usersLocation);
        }