public ConsumerInfo GetConsumerInfo(string consumerId)
        {
            var          key    = "ConsumerInfo_" + consumerId;
            ConsumerInfo result = null;

            if (RedisCacheHelper.Exists(key))
            {
                result = RedisCacheHelper.GetCache <ConsumerInfo>(key);
            }
            if (result == null)
            {
                var doc           = dataOp.FindOneByQuery(MQConsumerInfo, Query.EQ("consumerId", consumerId));
                var ip            = doc.String("ip");
                var queueType     = doc.String("queueType");
                var id            = doc.String("consumerId");
                var isStart       = doc.Int("isStart");
                var lastStartTime = doc.Date("lastStartTime");
                var lastEndTime   = doc.Date("lastEndTime");
                var lastExecTime  = doc.Date("lastExecTime");
                result = new ConsumerInfo()
                {
                    consumerId    = id,
                    ip            = ip,
                    isStart       = isStart,
                    lastEndTime   = lastEndTime,
                    lastExecTime  = lastExecTime,
                    lastStartTime = lastStartTime,
                    queueType     = queueType
                };
                RedisCacheHelper.SetCache(key, result, DateTime.Now.AddDays(30));
            }
            return(result);
        }
        /// <summary>
        /// 记录用户成功登录的信息
        /// </summary>
        /// <param name="user"></param>
        /// <param name="rememberMe"></param>
        private void SetUserLoginInfo(BsonDocument user, string rememberMe)
        {
            string   strUserName = user.String("userId") + "\\" + user.String("name") + "\\" + user.String("cardNumber");
            Identity identity    = new Identity
            {
                AuthenticationType = "form",
                IsAuthenticated    = true,
                Name = strUserName
            };

            Principal principal = new Principal {
                Identity = identity
            };

            HttpContext.User     = principal;
            Session["UserId"]    = user.String("userId");
            Session["UserName"]  = user.String("name");
            Session["LoginName"] = user.String("loginName");
            Session["UserType"]  = user.String("type");
            Session["token"]     = user.String("token");
            Session["SessionId"] = Session.SessionID;
            var sessionToken = GetSessionToken(user);
            var userInfo     = new UserInfoDto()
            {
                UserId       = user.String("userId"),
                UserName     = user.String("name"),
                LoginName    = user.String("loginName"),
                UserType     = user.String("type"),
                token        = user.String("token"),
                sessionToken = sessionToken
            };

            Response.SetCookie(new HttpCookie("token", sessionToken));
            RedisCacheHelper.SetCache(sessionToken, userInfo, DateTime.Now.AddDays(7));

            if (rememberMe.ToLower() != "on")
            {
                FormsAuthentication.SetAuthCookie(strUserName, false);
            }
            else
            {
                FormsAuthentication.SetAuthCookie(strUserName, true);
                HttpCookie lcookie = Response.Cookies[FormsAuthentication.FormsCookieName];
                if (lcookie != null)
                {
                    lcookie.Expires = DateTime.Now.AddDays(7);
                }
            }
            #region 记录登录日志
            dataOp.LogSysBehavior(SysLogType.Login, HttpContext);
            #endregion
        }
        public string GetCustomerNameByJobId(string jobId)
        {
            var    key    = "JobIdCustomerName_" + jobId;
            string result = null;

            if (RedisCacheHelper.Exists(key))
            {
                result = RedisCacheHelper.GetCache <string>(key);
            }
            if (string.IsNullOrEmpty(result))
            {
                var doc  = dataOp.FindOneByQuery("BackgroundJob", Query.EQ("jobId", jobId));
                var code = doc.String("customerCode");
                doc    = dataOp.FindOneByQuery("CustomerInfo", Query.EQ("customerCode", code));
                result = doc.String("name");
                RedisCacheHelper.SetCache(key, result, DateTime.Now.AddDays(1));
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 生成客户session code
        /// </summary>
        /// <returns></returns>
        public ActionResult GetSystemCodeSession()
        {
            PageJson json         = new PageJson();
            var      customerCode = PageReq.GetString("customerCode");

            if (string.IsNullOrEmpty(customerCode))
            {
                json.Success = false;
                json.Message = "客户代码为设置";
                return(Json(json));
            }
            //Session["CustomerCode"] = customerCode;


            if (!string.IsNullOrEmpty(PageReq.GetSession("sessionToken")))
            {
                var cacheKey = $"CustomerCode_{PageReq.GetSession("sessionToken")}";
                RedisCacheHelper.SetCache(cacheKey, customerCode, DateTime.Now.AddDays(30));
                PageReq.SetSession("CustomerCode", customerCode);
            }
            json.Success = true;
            return(Json(json));
        }