/// <summary> /// 设置缓存 /// </summary> /// <param name="entity">用户实体</param> public static void SetCache(BaseUserEntity entity) { string key = string.Empty; if (entity != null && !string.IsNullOrWhiteSpace(entity.Id)) { System.Web.Caching.Cache cache = HttpRuntime.Cache; key = "user" + entity.Id; cache.Add(key, entity, null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Normal, null); key = "userByCode" + entity.Code; cache.Add(key, entity.Id.ToString(), null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Normal, null); key = "userByCompanyIdByCode" + entity.CompanyId + "_" + entity.Code; cache.Add(key, entity.Id.ToString(), null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Normal, null); string companyCode = BaseOrganizeManager.GetCodeByCache(entity.CompanyId); if (!string.IsNullOrEmpty(companyCode)) { key = "userByCompanyCodeByCode" + companyCode + "_" + entity.Code; cache.Add(key, entity.Id.ToString(), null, DateTime.Now.AddMinutes(30), TimeSpan.Zero, CacheItemPriority.Normal, null); } } }
/// <summary> /// 设置缓存 /// 20151007 吉日嘎拉,需要在一个连接上进行大量的操作 /// 20160128 吉日嘎拉,一些空调间的判断。 /// </summary> /// <param name="entity">用户实体</param> public static void SetCache(IRedisClient redisClient, BaseUserEntity entity) { string key = string.Empty; if (entity != null && !string.IsNullOrWhiteSpace(entity.Id)) { key = "User:"******"User:ByNickName:" + entity.NickName.ToLower(); redisClient.Set <string>(key, entity.Id, DateTime.Now.AddDays(7)); } if (!string.IsNullOrEmpty(entity.Code)) { key = "User:ByCode:" + entity.Code; redisClient.Set <string>(key, entity.Id, DateTime.Now.AddHours(8)); key = "User:ByCompanyId:ByCode" + entity.CompanyId + ":" + entity.Code; redisClient.Set <string>(key, entity.Id, DateTime.Now.AddHours(8)); } string companyCode = BaseOrganizeManager.GetCodeByCache(entity.CompanyId); if (!string.IsNullOrEmpty(companyCode)) { key = "User:ByCompanyCode:ByCode" + companyCode + ":" + entity.Code; redisClient.Set <string>(key, entity.Id, DateTime.Now.AddHours(8)); } System.Console.WriteLine(entity.Id + " : " + entity.RealName); } }
public static string AddLog(string systemCode, BaseUserEntity userEntity, string ipAddress, string ipAddressName, string macAddress, string loginStatus) { if (!BaseSystemInfo.RecordLogOnLog) { return(string.Empty); } if (userEntity == null) { return(null); } string result = string.Empty; BaseLoginLogEntity entity = new BaseLoginLogEntity(); entity.SystemCode = systemCode; entity.UserId = userEntity.Id; entity.UserName = userEntity.NickName; entity.RealName = userEntity.RealName; entity.CompanyId = userEntity.CompanyId; entity.CompanyName = userEntity.CompanyName; if (BaseSystemInfo.OnInternet && !string.IsNullOrEmpty(userEntity.CompanyId)) { entity.CompanyCode = BaseOrganizeManager.GetCodeByCache(userEntity.CompanyId); } entity.IPAddress = ipAddress; entity.IPAddressName = ipAddressName; entity.MACAddress = macAddress; entity.LoginStatus = loginStatus; entity.LogLevel = LoginStatusToLogLevel(loginStatus); entity.CreateOn = DateTime.Now; string tableName = GetSplitTableName(userEntity); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.LoginLogDbType, BaseSystemInfo.LoginLogDbConnection)) { BaseLoginLogManager loginLogManager = new BaseLoginLogManager(dbHelper, tableName); try { // 2015-07-13 把登录日志无法正常写入的,进行日志记录 result = loginLogManager.Add(entity, false, false); } catch (System.Exception ex) { FileUtil.WriteMessage("AddLogTask: 异常信息:" + ex.Message + System.Environment.NewLine + "错误源:" + ex.Source + System.Environment.NewLine + "堆栈信息:" + ex.StackTrace, System.Web.HttpContext.Current.Server.MapPath("~/Log/") + "Log" + DateTime.Now.ToString(BaseSystemInfo.DateFormat) + ".txt"); } } return(result); }
public int GetRemainingCount(DotNet.Model.BaseUserEntity userEntity, string applicationCode, string accountCode) { if (string.IsNullOrEmpty(applicationCode)) { if (userEntity != null) { applicationCode = BaseOrganizeManager.GetCodeByCache(userEntity.CompanyId); } } if (string.IsNullOrEmpty(accountCode)) { if (userEntity != null) { accountCode = userEntity.Code; } } return(GetRemainingCount(applicationCode, accountCode)); }