static CheckLoginStatusService() { Task.Factory.StartNew(() => { try { var redisSubHelp = new RedisSubHelp((a, b) => { if (b.StartsWith(CacheKeyString.UserLoginAllKeyPre)) { LogWrite.Write("redisLog.txt", "redis key:" + b); try { string[] strArray = b.Split("#"); string ID = strArray[3]; int companyID = Convert.ToInt32(strArray[2]); string userID = strArray[1].ToString(); LoginLog loginLog = MongoDbUtil.GetDoc <LoginLog>(p => p.LoginID == ID, null).FirstOrDefault(); DateTime now = DateTime.Now; TimeSpan spendSpan = now.Subtract(loginLog.LoginTime); if (loginLog != null) { UpdateDefinition <LoginLog> update = Builders <LoginLog> . Update.Set(y => y.Seconds, spendSpan.TotalSeconds).Set(y => y.TimeSpan, DateUtil.parseTimeSeconds(spendSpan.TotalSeconds, 0)) .Set(y => y.Status, LoginStatusEum.LogOut); MongoDbUtil.UpdateOne <LoginLog>(p => p.LoginID == ID, update); } var redis = CacheFactory.Instance(CacheType.Redis) as RedisCache; string thisWeek = DateUtil.GetThisWeekString(); string strV = string.Format(CacheKeyString.StaOnlineUser, companyID, thisWeek); string strTimeV = string.Format(CacheKeyString.StaOnlineTimes, companyID, thisWeek); //累加登陆时长 redis.IncrementItemInSortedSet(strV, userID, spendSpan.TotalSeconds); redis.Client.ExpireAt(strV, DateUtil.ToUnixEpochDate(DateTime.Now.AddDays(15))); redis.IncrementItemInSortedSet(strTimeV, userID, 1); redis.Client.ExpireAt(strV, DateUtil.ToUnixEpochDate(DateTime.Now.AddDays(15))); } catch (Exception ex) { LogWrite.Write("redisLog", "错误:" + ex.Message); } } }); redisSubHelp.SubscribeToChannels("__keyevent@0__:expired"); } catch (Exception ex) { LogWrite.Write("redisLog.txt", "最外层线程:" + ex.Message); } }); }
public List <LoginLog> managoDB() { LoginLog loginLog = new LoginLog(); loginLog.LoginID = Guid.NewGuid().ToString(); loginLog.Account = "123"; loginLog.CompanyID = 1; loginLog.Description = LoginTypeEum.LoginSuccess; MongoDbUtil.AddDoc(loginLog); return(MongoDbUtil.GetDoc <LoginLog>((x) => true)); }
public ResponseObject <bool> Read(string Id, CurrentUser currentUser) { try { ToDoMgModel loginLog = MongoDbUtil.GetDoc <ToDoMgModel>(p => p.ToDoId == Id, null).FirstOrDefault(); if (loginLog != null) { UpdateDefinition <ToDoMgModel> update = Builders <ToDoMgModel> . Update.Set(y => y.IsRead, true); MongoDbUtil.UpdateOne <ToDoMgModel>(p => p.ToDoId == Id && p.CompanyID == currentUser.CompanyID, update); } return(ResponseUtil <bool> .SuccessResult(true)); } catch (Exception ex) { return(ResponseUtil <bool> .FailResult(false, $"{ex.Message}")); } }
public ResponseObject <List <ToDoMgModel> > GetToDoModel(RequestGet requestObject, CurrentUser currentUser) { ResponseObject <List <ToDoMgModel> > responseObject = new ResponseObject <List <ToDoMgModel> >(); responseObject.Code = 0; try { List <ToDoMgModel> result = new List <ToDoMgModel>(); Expression <Func <ToDoMgModel, bool> > queryConditionLam = (x) => x.To == currentUser.UserID && x.CompanyID == currentUser.CompanyID; if (requestObject.QueryConditions != null && requestObject.QueryConditions.Count > 0) { var conditionals = SqlSugarUtil.GetConditionalFull(requestObject.QueryConditions).Where(p => !string.IsNullOrWhiteSpace(p.FieldValue)).ToList(); var whereConditional = ConditionalModelToExpression.BuildExpression <ToDoMgModel>(conditionals); queryConditionLam = queryConditionLam.And(whereConditional); } SortDefinition <ToDoMgModel> sort = null; //排序条件 if (requestObject.OrderByConditions != null && requestObject.OrderByConditions.Count > 0) { foreach (var item in requestObject.OrderByConditions) { var exp = SqlSugarUtil.GetExpression <ToDoMgModel>(item.Column); if (exp == null) { continue; } if (item.Condition.ToLower() == "asc") { if (sort == null) { sort = Builders <ToDoMgModel> .Sort.Ascending(exp); } else { sort = sort.Ascending(exp); } } else if (item.Condition.ToLower() == "desc") { if (sort == null) { sort = Builders <ToDoMgModel> .Sort.Descending(exp); } else { sort = sort.Descending(exp); } } } } long totalNum = 0; if (requestObject.IsPaging == true) { result = MongoDbUtil.GetDoc <ToDoMgModel>(queryConditionLam, requestObject.PageIndex, requestObject.PageSize, sort, ref totalNum); } else { result = MongoDbUtil.GetDoc <ToDoMgModel>(queryConditionLam, sort).ToList(); } return(ResponseUtil <List <ToDoMgModel> > .SuccessResult(result, totalNum)); } catch (Exception ex) { return(ResponseUtil <List <ToDoMgModel> > .FailResult(null, ex.Message)); } }
/// <summary> /// 查询日志 /// </summary> /// <param name="requestObject"></param> /// <param name="UserId"></param> /// <returns></returns> public ResponseObject <LogQueryModel, List <OperateLog> > Get(RequestObject <LogQueryModel> requestObject, int UserId) { try { long totalNum = -1; SMUserInfo sMUserInfo = SMCurentUserManager.GetCurentUserID(UserId, _db.Instance); List <OperateLog> result = new List <OperateLog>(); Expression <Func <OperateLog, bool> > pression = p => p.CompanyID == sMUserInfo.CompanyId.Value; var queryEntiy = requestObject.PostData; if (queryEntiy != null) { if (!string.IsNullOrEmpty(queryEntiy.Account)) { pression = pression.And(p => p.Account.Contains(queryEntiy.Account)); } if (!string.IsNullOrEmpty(queryEntiy.Path)) { pression = pression.And(p => p.Path.Contains(queryEntiy.Path)); } if (!string.IsNullOrEmpty(queryEntiy.RealName)) { pression = pression.And(p => p.RealName.Contains(queryEntiy.RealName)); } if (!string.IsNullOrEmpty(queryEntiy.IpAddress)) { pression = pression.And(p => p.IpAddress == queryEntiy.IpAddress); } if (queryEntiy.CreateTimeBg != null) { pression = pression.And(p => p.CreateTime >= queryEntiy.CreateTimeBg.Value); } if (queryEntiy.CreateTimeEd != null) { DateTime eg = queryEntiy.CreateTimeEd.Value.AddDays(1); pression = pression.And(p => p.CreateTime < eg); } } var sort = Builders <OperateLog> .Sort.Descending(y => y.CreateTime); if (requestObject.IsPaging == true) { result = MongoDbUtil.GetDoc <OperateLog>(pression, requestObject.PageIndex, requestObject.PageSize, sort, ref totalNum); } else { result = MongoDbUtil.GetDoc <OperateLog>(pression, sort).ToList(); } return(ResponseUtil <LogQueryModel, List <OperateLog> > .SuccessResult(requestObject, result, totalNum)); } catch (Exception ex) { //返回查询异常结果 return(ResponseUtil <LogQueryModel, List <OperateLog> > .FailResult(requestObject, null, ex.Message)); } }