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 async Task <bool> PostAsync(List <OperateLog> operateLog) { bool result = true; result = await Task.Factory.StartNew(() => { bool tempResult = true; try { MongoDbUtil.AddDoc(operateLog); } catch { tempResult = false; } return(tempResult); }); return(result); }
private void PushNotice(int UserId, int CompanyID, TSMUserAccountDbModel userAccount) { var permissUser = _db.Instance.Queryable <TSMUserAccountDbModel, TSMRoleUserRelationDbModel, TSMRolePermissionsDbModel, TSMRolesDbModel, TPMMenusDbModel>( (x, x1, x2, x3, x4) => new object[] { JoinType.Inner, x.ID == x1.UserId, JoinType.Inner, x1.RoleId == x2.RoleId, JoinType.Inner, x2.RoleId == x3.Id, JoinType.Inner, x2.MenuId == x4.Id }).Where((x, x1, x2, x3, x4) => x.CompanyId == CompanyID && x.Status == 1 && x4.MenuPath == "/views/SysSettings/UserAuth/index.vue") .Select((x, x1, x2, x3, x4) => x).ToList(); var adminUser = _db.Instance.Queryable <TSMUserAccountDbModel, TSMCompanyDbModel>((x, x1) => new object[] { JoinType.Inner, x.ID == x1.AdminId }).Where((x, x1) => x1.ID == CompanyID).Select((x, x1) => x).First(); if (!permissUser.Any(p => p.ID == adminUser.ID)) { permissUser.Add(adminUser); } var redis = CacheFactory.Instance(CacheType.Redis); List <ToDoMgModel> toDoMgModelList = new List <ToDoMgModel>(); foreach (var userTtem in permissUser) { ToDoMgModel toDoModel = new ToDoMgModel(); toDoModel.Title = "申请加入公司"; toDoModel.Content = $"姓名:{userAccount.AccountName} 电话:{userAccount.TelAccount},申请加入公司"; toDoModel.CreateBy = UserId; toDoModel.CreateDate = DateTime.Now; toDoModel.IsRead = false; toDoModel.MessageType = MessageTypeMgEnum.ToApplytoComplany; toDoModel.To = userTtem.ID; toDoModel.ToDoId = Guid.NewGuid().ToString(); toDoModel.CompanyID = CompanyID; toDoMgModelList.Add(toDoModel); } MongoDbUtil.AddDoc(toDoMgModelList); }
public async Task <ResponseObject <TSMUserLoginResult> > LoginPost(RequestPost <TSMUserAccountAddModel> requestObject) { ResponseObject <TSMUserLoginResult> result; result = await _service.LoginAsync(requestObject); var task = Task.Factory.StartNew(() => { try { bool isSucess = string.IsNullOrEmpty(result.Data.Token) ? false : true; if (isSucess == true) { string token = result.Data.Token.Split('.')[1]; var payLoad = JsonConvert.DeserializeObject <Dictionary <string, object> >(Base64UrlEncoder.Decode(token)); int userID = Convert.ToInt32(payLoad["UserID"]); string ID = payLoad["ID"].ToString(); int CompanyID = Convert.ToInt32(payLoad["CompanyID"]); if (CompanyID == 0) //没有加入公司的员工不保存登陆日志 { return; } //写 登陆状态到redis var redis = CacheFactory.Instance(CacheType.Redis); UserStatus userStatus = new UserStatus() { ID = ID, LastRefreshTime = DateTime.Now }; string redisKey = string.Format(CacheKeyString.UserLoginAllKey, userID, CompanyID, ID); redis.AddOrUpdateKey <UserStatus>(redisKey, userStatus, 90); //写登陆日志到 MangoDB SMUserInfo sMUserInfo = SMCurentUserManager.GetCurentUserID(userID, _db.Instance); string ipAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString(); LoginLog loginLog = new LoginLog(); loginLog.LoginID = ID; loginLog.Account = sMUserInfo.AccountName; loginLog.CompanyID = sMUserInfo.CompanyId.Value; loginLog.Description = isSucess ? LoginTypeEum.LoginSuccess : LoginTypeEum.LoginFail; loginLog.IpAddress = ipAddress; loginLog.LoginTime = DateTime.Now; loginLog.RealName = sMUserInfo == null ? "" : sMUserInfo.RealName; loginLog.RoleName = sMUserInfo == null ? "" : sMUserInfo.RoleName; loginLog.Status = isSucess ? LoginStatusEum.Logining : LoginStatusEum.LogOut; MongoDbUtil.AddDoc(loginLog); } else { //LoginLog loginLog = new LoginLog(); //loginLog.ID = Guid.NewGuid().ToString(); //loginLog.Account = sMUserInfo.AccountName; //loginLog.CompanyID = sMUserInfo.CompanyId.Value; //loginLog.Description = isSucess ? LoginTypeEum.LoginSuccess : LoginTypeEum.LoginFail; //loginLog.IpAddress = ipAddress; //loginLog.LoginTime = DateTime.Now; //loginLog.RealName = sMUserInfo?.RealName; //loginLog.RoleName = sMUserInfo?.RoleName; //loginLog.Status = isSucess ? LoginStatusEum.Logining : LoginStatusEum.LogOut; //MongoDbUtil.AddDoc(loginLog); } } catch (Exception EX) { } }); return(result); }