/// <summary> /// 设置缓存 /// 20151007 吉日嘎拉,需要在一个连接上进行大量的操作 /// 20160128 吉日嘎拉,一些空调间的判断。 /// </summary> /// <param name="entity">用户实体</param> public static void SetCache(BaseUserEntity entity) { var key = string.Empty; if (entity != null && entity.Id > 0) { key = "User:"******"User:ByNickName:" + entity.NickName.ToLower(); CacheUtil.Set <string>(key, entity.Id.ToString()); } if (!string.IsNullOrEmpty(entity.Code)) { key = "User:ByCode:" + entity.Code; CacheUtil.Set <string>(key, entity.Id.ToString()); key = "User:ByCompanyId:ByCode" + entity.CompanyId + ":" + entity.Code; CacheUtil.Set <string>(key, entity.Id.ToString()); } var companyCode = BaseOrganizationManager.GetCodeByCache(entity.CompanyId.ToString()); if (!string.IsNullOrEmpty(companyCode)) { key = "User:ByCompanyCode:ByCode" + companyCode + ":" + entity.Code; CacheUtil.Set <string>(key, entity.Id.ToString()); } Console.WriteLine(entity.Id + " : " + entity.RealName); } }
/// <summary> /// 增加日志 /// </summary> /// <param name="systemCode">系统编码</param> /// <param name="userEntity"></param> /// <param name="ipAddress"></param> /// <param name="ipAddressName"></param> /// <param name="macAddress"></param> /// <param name="loginStatus"></param> /// <param name="operationType"></param> /// <param name="loginResult"></param> /// <param name="sourceType"></param> /// <param name="targetApplication"></param> /// <param name="targetIp"></param> /// <returns></returns> public static string AddLog(string systemCode, BaseUserEntity userEntity, string ipAddress, string ipAddressName, string macAddress, string loginStatus, int operationType = 1, int loginResult = 1, string sourceType = null, string targetApplication = null, string targetIp = null) { if (!BaseSystemInfo.RecordLogonLog) { return(string.Empty); } if (userEntity == null) { return(null); } var result = string.Empty; var entity = new BaseLogonLogEntity { SystemCode = systemCode, UserId = userEntity.Id, UserName = userEntity.UserName, NickName = userEntity.NickName, RealName = userEntity.RealName, CompanyId = userEntity.CompanyId, CompanyName = userEntity.CompanyName }; if (BaseSystemInfo.OnInternet && userEntity.CompanyId > 0) { entity.CompanyCode = BaseOrganizationManager.GetCodeByCache(userEntity.CompanyId.ToString()); } entity.Province = userEntity.Province; entity.City = userEntity.City; entity.TargetApplication = targetApplication; entity.TargetIp = targetIp; entity.SourceType = sourceType; entity.IpAddress = ipAddress; entity.IpAddressName = ipAddressName; entity.MacAddress = macAddress; entity.LogonStatus = loginStatus; entity.OperationType = operationType; entity.Result = loginResult; entity.LogLevel = LogonStatusToLogLevel(loginStatus); entity.CreateTime = DateTime.Now; var tableName = GetSplitTableName(userEntity); var loginLogManager = new BaseLogonLogManager(tableName); try { // 2015-07-13 把登录日志无法正常写入的,进行日志记录 result = loginLogManager.Add(entity); } catch (Exception ex) { LogUtil.WriteLog("AddLogTask: 异常信息:" + ex.Message + "userName:"******"错误源:" + ex.Source + Environment.NewLine + "堆栈信息:" + ex.StackTrace, "Log"); } return(result); }