Exemplo n.º 1
0
        /// <summary>
        /// 登录失败此处递增
        /// </summary>
        /// <param name="account"></param>
        void _IncrementLoginFaildCount(string account)
        {
            var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.User_AccountLoginFail, account);

            CacheKey.Increment();
            CacheKey.ExpireEntryAt(DateTime.Now.AddHours(1) - DateTime.Now);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 检查WEB用户是否还有心跳
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public bool HasUserWebHeartbeat(string UserID)
        {
            var cacheKey_Heartbeat_Web = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_Web, $"{UserID}");
            var webHeartbeat           = Manager.UseDb(getDbNum(userOnLineStateDbNum)).StringGet <DateTime?>(cacheKey_Heartbeat_Web.KeyName);

            if (webHeartbeat != null)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据手机号码查询用户编号
        /// </summary>
        /// <param name="UserID"></param>
        /// <returns></returns>
        public string GetUserIDByMobile(string Mobile, EnumUserType userType)
        {
            var GetUserIDByMobile_CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.MAP_GetUserIDByMobile, $"{Mobile}:{userType}");

            var UserID = GetUserIDByMobile_CacheKey.FromCache <string>();

            //缓存没有命中,则查询数据库获取医生编号并设置缓存(缓存不过期)
            if (string.IsNullOrEmpty(UserID))
            {
                using (var db = new DBEntities())
                {
                    //TODO:这里需要优惠如果不是手机号码类型不需要这样查询
                    string currentUserID = "";

                    if (userType == EnumUserType.User)
                    {
                        currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.Mobile == Mobile) &&
                                                       (p.UserType == EnumUserType.User || p.UserType == EnumUserType.Drugstore)).Select(t => t.UserID).FirstOrDefault();

                        //避免使用Or条件而采用次查询
                        if (string.IsNullOrEmpty(currentUserID))
                        {
                            currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.UserAccount == Mobile) &&
                                                           (p.UserType == EnumUserType.User || p.UserType == EnumUserType.Drugstore)).Select(t => t.UserID).FirstOrDefault();
                        }
                    }
                    else
                    {
                        currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.Mobile == Mobile) && p.UserType == userType).Select(t => t.UserID).FirstOrDefault();

                        //避免使用Or条件而采用次查询
                        if (string.IsNullOrEmpty(currentUserID))
                        {
                            currentUserID = db.Users.Where(p => p.IsDeleted == false && (p.UserAccount == Mobile) && p.UserType == userType).Select(t => t.UserID).FirstOrDefault();
                        }
                    }

                    if (!string.IsNullOrEmpty(currentUserID))
                    {
                        UserID = currentUserID;
                    }
                    else
                    {
                        //避免缓存穿透问题,有新用户注册时需要更新此缓存
                        UserID = "";
                    }

                    UserID.ToCache(GetUserIDByMobile_CacheKey, TimeSpan.FromMinutes(_GetUserInfoExpireMinutes()));
                }
            }

            return(UserID);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 检查验证码是否正确
        /// </summary>
        /// <param name="VerifyCode"></param>
        /// <param name="appToken"></param>
        /// <returns></returns>
        public bool CheckVerifyCode(string VerifyCode, string VerifyCodeID)
        {
            var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.VerifyCode, VerifyCodeID);
            var value    = CacheKey.FromCache <string>();

            CacheKey.RemoveCache();
            if (value != VerifyCode.Trim())
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
        public void SetAppHeartBeat(string UserID, bool flag = true, EnumUserType userType = EnumUserType.User)
        {
            var cacheKey_HeartbeatApp = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_App, $"{UserID}");

            if (flag)
            {
                //加入到在线用户set
                Manager.Instance.SetAdd(new XuHos.Common.Cache.Keys.StringCacheKey(StringCacheKeyType.Heartbeat_App, $"OnlineSet:{userType:G}").KeyName, UserID);
                Manager.UseDb(getDbNum(userOnLineStateDbNum)).StringSet(cacheKey_HeartbeatApp.KeyName, DateTime.Now);
            }
            else
            {
                Manager.Instance.SetRemove(new XuHos.Common.Cache.Keys.StringCacheKey(StringCacheKeyType.Heartbeat_App, $"OnlineSet:{userType:G}").KeyName, UserID);
                Manager.UseDb(getDbNum(userOnLineStateDbNum)).RemoveCache(cacheKey_HeartbeatApp.KeyName);
            }
        }
Exemplo n.º 6
0
        public void SetWebHeartBeat(string UserID, string type, bool flag = true, EnumUserType userType = EnumUserType.User)
        {
            var cacheKey_HeartbeatWeb      = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_Web, $"{UserID}");
            var cacheKey_HeartbeatWeb_Type = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_Web, $"{UserID}:{type}");

            if (flag)
            {
                //加入到在线用户set
                Manager.Instance.SetAdd(new XuHos.Common.Cache.Keys.StringCacheKey(StringCacheKeyType.Heartbeat_Web, $"OnlineSet:{userType:G}").KeyName, UserID);
                Manager.UseDb(getDbNum(userOnLineStateDbNum)).StringSet(cacheKey_HeartbeatWeb.KeyName, DateTime.Now, TimeSpan.FromSeconds(15));
                Manager.UseDb(getDbNum(userTypeStateDbNum)).StringSet(cacheKey_HeartbeatWeb_Type.KeyName, DateTime.Now, TimeSpan.FromSeconds(15));
            }
            else
            {
                Manager.Instance.SetRemove(new XuHos.Common.Cache.Keys.StringCacheKey(StringCacheKeyType.Heartbeat_Web, $"OnlineSet:{userType:G}").KeyName, UserID);
                Manager.UseDb(getDbNum(userOnLineStateDbNum)).RemoveCache(cacheKey_HeartbeatWeb.KeyName);
                Manager.UseDb(getDbNum(userTypeStateDbNum)).RemoveCache(cacheKey_HeartbeatWeb_Type.KeyName);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 检查某个用户是否在诊室
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="ChannelID"></param>
        /// <returns></returns>
        public bool HasChannelHeartBeat(string UserID, int ChannelID)
        {
            var roomService = new ConversationRoomService();

            var cacheKey_HeartbeatApp = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_App, $"{UserID}");

            if (Manager.UseDb(getDbNum(userOnLineStateDbNum)).StringGet <DateTime?>(cacheKey_HeartbeatApp.KeyName) != null)
            {
                return(true);
            }
            else
            {
                var cacheKey_Heartbeat_Web = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.Heartbeat_Web, $"{UserID}:user.room:{ChannelID}");

                if (Manager.UseDb(getDbNum(userTypeStateDbNum)).StringGet <DateTime?>(cacheKey_Heartbeat_Web.KeyName) != null)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 8
0
        void _ResetLoginFaildCount(string account)
        {
            var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.User_AccountLoginFail, account);

            CacheKey.RemoveCache();
        }
Exemplo n.º 9
0
        int?_GetLoginFaildCount(string account)
        {
            var CacheKey = new XuHos.Common.Cache.Keys.StringCacheKey(XuHos.Common.Cache.Keys.StringCacheKeyType.User_AccountLoginFail, account);

            return(CacheKey.FromCache <int?>());
        }