Exemplo n.º 1
0
        /// <summary>
        /// 根据ID获取用户领域模型。
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="clear"></param>
        /// <returns></returns>
        public UserDomainModel GetUserDomainModelById(string userId, bool clear)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(null);
            }

            string          cacheKey = CacheKey.GetKeyDefine(CacheKey.USERDOMAIN_INFO, userId);
            UserDomainModel result   = CacheUtil.Get <UserDomainModel>(cacheKey);

            if (result == null || clear)
            {
                UserInfoModel basicInfo = GetUserModelByIdFromDatabase(userId);
                if (basicInfo != null)
                {
                    result             = new UserDomainModel();
                    result.BasicInfo   = basicInfo;
                    result.InGroupList = UserGroupInfoService.Instance.GetUserInGroupListFromDatabase(basicInfo.UserId);

                    CacheUtil.Set(cacheKey, result);
                }
            }

            return(result);
        }
        /// <summary>
        /// 根据ID获取领域模型。
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="clear"></param>
        /// <returns></returns>
        public CustomerAttributeGroupInfoModel GetGroupInfoById(string Id, bool clear)
        {
            string cacheKey = CacheKey.GetKeyDefine(CacheKey.CUSTOMER_GroupInfo_DICT, Id);
            CustomerAttributeGroupInfoModel result = CacheUtil.Get <CustomerAttributeGroupInfoModel>(cacheKey);

            if (result == null || clear)
            {
                CustomerAttributeGroupInfoModel basicInfo = GetCustomerGroupFromDatabase(Id);
                if (basicInfo != null)
                {
                    result = new CustomerAttributeGroupInfoModel();
                    result = basicInfo;
                    CacheUtil.Set(cacheKey, result);
                }
            }

            return(result);
        }
        /// <summary>
        /// 根据ID获取领域模型。
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="clear"></param>
        /// <returns></returns>
        public CustomerExtAttributesModel GetCustomerAttributeById(string Id, bool clear)
        {
            if (string.IsNullOrEmpty(Id))
            {
                return(null);
            }

            string cacheKey = CacheKey.GetKeyDefine(CacheKey.CUSTOMER_ATTRIBUTE_DICT, Id);
            CustomerExtAttributesModel result = CacheUtil.Get <CustomerExtAttributesModel>(cacheKey);

            if (result == null || clear)
            {
                CustomerExtAttributesModel basicInfo = GettCustomerAttributeFromDatabase(Id);
                if (basicInfo != null)
                {
                    result = new CustomerExtAttributesModel();
                    result = basicInfo;
                    CacheUtil.Set(cacheKey, result);
                }
            }

            return(result);
        }
        /// <summary>
        /// 根据ID获取用户领域模型。
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="clear"></param>
        /// <returns></returns>
        public SalesOrderTypeStatusDomainModel GetSalesOrderTypeStatusModelById(string salsorder_status_id, bool clear)
        {
            if (string.IsNullOrEmpty(salsorder_status_id))
            {
                return(null);
            }

            string cacheKey = CacheKey.GetKeyDefine(CacheKey.SALESORDER_TYPE_STATUS_INFO, salsorder_status_id);
            SalesOrderTypeStatusDomainModel result = CacheUtil.Get <SalesOrderTypeStatusDomainModel>(cacheKey);

            if (result == null || clear)
            {
                SalesorderTypeStatusInfoModel basicInfo = GetSalesOrderTypeStatusModelByIdFromDatabase(salsorder_status_id);
                if (basicInfo != null)
                {
                    result           = new SalesOrderTypeStatusDomainModel();
                    result.BasicInfo = basicInfo;

                    CacheUtil.Set(cacheKey, result);
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="loginInput"></param>
        /// <param name="loginPwd"></param>
        /// <returns></returns>
        /// <remarks>
        /// 用户可通过登录名及工号登录系统。
        /// </remarks>
        public LoginStatusEnum UserLogin(string loginInput, string loginPwd)
        {
            #region 为减少数据库请求,用户实体保存在缓存中,可通过登录名及工号登录系统

            // 使用2个缓存KEY保存指向用户ID的缓存KEY,从而获取用户实体。
            string loginNameKey   = CacheKey.GetKeyDefine(CacheKey.USER_LOGIN_NAME_KEY, loginInput);
            string loginWorkIdKey = CacheKey.GetKeyDefine(CacheKey.USER_WORKID_KEY, loginInput);

            // 通过登录名称获取指向用户实体的ID缓存KEY
            string userDomainInfoKey = CacheUtil.Get <string>(loginNameKey);
            if (userDomainInfoKey == null)
            {
                // 如果通过登录名称获取不到,说明可能输入的是工号,尝试通过工号获取指向用户实体的ID缓存KEY
                userDomainInfoKey = CacheUtil.Get <string>(loginWorkIdKey);
            }

            // 从缓存中获取用户领域模型
            UserDomainModel domainModel = CacheUtil.Get <UserDomainModel>(userDomainInfoKey);

            #endregion

            #region 如果缓存中没有用户领域模型,再从数据库中重新获取用户领域模型,并缓存

            if (domainModel == null)
            {
                domainModel = GetUserDomainModelFromDatabase(loginInput);

                if (domainModel == null)
                {
                    // 数据库中不存在该用户。
                    return(LoginStatusEnum.NotExists);
                }

                userDomainInfoKey = CacheKey.GetKeyDefine(CacheKey.USERDOMAIN_INFO, domainModel.BasicInfo.UserId);

                // 保存缓存KEY。
                CacheUtil.Set(userDomainInfoKey, domainModel);
                CacheUtil.Set(CacheKey.USER_LOGIN_NAME_KEY.GetKeyDefine(domainModel.BasicInfo.LoginName), CacheKey.GetKeyDefine(CacheKey.USER_LOGIN_NAME_KEY, domainModel.BasicInfo.LoginName));
                CacheUtil.Set(CacheKey.USER_WORKID_KEY.GetKeyDefine(domainModel.BasicInfo.WorkId), CacheKey.GetKeyDefine(CacheKey.USER_WORKID_KEY, domainModel.BasicInfo.WorkId));
            }

            #endregion

            #region 判断用户登录密码

            if (domainModel.BasicInfo.LoginPwd != loginPwd)
            {
                // 记录用户登录次数
                SessionUtil.LoginTryCount = (Convert.ToInt32(SessionUtil.LoginTryCount) + 1).ToString();
                if (Convert.ToInt32(SessionUtil.LoginTryCount.Substring(7, 2)) > ConfigUtil.GetLoginTryCountLimit())
                {
                    return(LoginStatusEnum.NameOrPwdErrorAndShowValidCode);
                }
                else
                {
                    return(LoginStatusEnum.NameOrPwdError);
                }
            }

            #endregion

            #region 判断用户状态

            if (domainModel.BasicInfo.Status == 1)
            {
                return(LoginStatusEnum.Disabled);
            }

            #endregion


            #region 保存Session信息

            SessionInfo sessionInfo = new SessionInfo();
            sessionInfo.UserId        = domainModel.BasicInfo.UserId;
            sessionInfo.LoginName     = domainModel.BasicInfo.LoginName;
            sessionInfo.CnName        = domainModel.BasicInfo.CnName;
            sessionInfo.EnName        = domainModel.BasicInfo.EnName;
            sessionInfo.IsLogin       = true;
            sessionInfo.RoleId        = domainModel.BasicInfo.RoleId;
            sessionInfo.LanguageCode  = IBP.Common.Consts.LANGUAGE_CN;
            sessionInfo.UserGroup     = domainModel.InGroupList;
            sessionInfo.ExtAttributes = new Dictionary <string, object>();

            // CTI 账号信息。
            sessionInfo.ExtAttributes["CtiUserId"]  = domainModel.BasicInfo.CtiUserId;
            sessionInfo.ExtAttributes["CtiUserPwd"] = domainModel.BasicInfo.CtiUserPwd;


            SessionUtil.Current = sessionInfo;

            SessionUtil.ResetLoginTryCount();

            #endregion

            return(LoginStatusEnum.Success);
        }