/// <summary> /// 更新访问数据 /// </summary> /// <param name="userLogonEntity"></param> /// <param name="createOpenId"></param> /// <returns></returns> public string UpdateVisitTime(BaseUserLogonEntity userLogonEntity, bool createOpenId = true) { var openId = string.IsNullOrEmpty(userLogonEntity?.OpenId)? Guid.NewGuid().ToString("N") : userLogonEntity?.OpenId; //Troy.Cui 2020-02-29 强制每次都自动生成,但对于可并发用户,OpenId过期了才更新一下OpenId //Troy.Cui 并发用户需要检测下OpenId过期时间 2020-06-17 if (createOpenId && userLogonEntity.ConcurrentUser == 1 && userLogonEntity.OpenIdTimeoutTime.HasValue && !string.IsNullOrEmpty(userLogonEntity.OpenId)) { //var timeSpan = DateTime.Now - userLogonEntity.OpenIdTimeoutTime.Value; var timeSpan = userLogonEntity.OpenIdTimeoutTime.Value - DateTime.Now; if ((timeSpan.TotalSeconds) < 0) { openId = userLogonEntity.OpenId; } } // Troy.Cui 非并发用户强制每次生成 2020-06-17 if (createOpenId && userLogonEntity.ConcurrentUser == 0) { openId = Guid.NewGuid().ToString("N"); } // 抛出一个线程 UpdateVisitTimeTask(userLogonEntity, openId, createOpenId); // new Thread(UpdateVisitTimeTask).Start(new Tuple<BaseUserLogonEntity, bool, string>(userLogonEntity, result)); return(openId); }
/// <summary> /// 保存实体修改记录 /// </summary> /// <param name="entityNew">修改后的实体对象</param> /// <param name="entityOld">修改前的实体对象</param> /// <param name="tableName">表名称</param> public void SaveEntityChangeLog(BaseUserLogonEntity entityNew, BaseUserLogonEntity entityOld, string tableName = null) { if (string.IsNullOrEmpty(tableName)) { //统一放在一个公共表 Troy.Cui 2016-08-17 tableName = BaseChangeLogEntity.CurrentTableName; } var manager = new BaseChangeLogManager(UserInfo, tableName); foreach (var property in typeof(BaseUserLogonEntity).GetProperties()) { var oldValue = Convert.ToString(property.GetValue(entityOld, null)); var newValue = Convert.ToString(property.GetValue(entityNew, null)); var fieldDescription = property.GetCustomAttributes(typeof(FieldDescription), false).FirstOrDefault() as FieldDescription; //不记录创建人、修改人、没有修改的记录 if (!fieldDescription.NeedLog || oldValue == newValue) { continue; } var entity = new BaseChangeLogEntity { TableName = CurrentTableName, TableDescription = FieldExtensions.ToDescription(typeof(BaseUserLogonEntity), "CurrentTableName"), ColumnName = property.Name, ColumnDescription = fieldDescription.Text, NewValue = newValue, OldValue = oldValue, RecordKey = entityOld.Id.ToString() }; manager.Add(entity, true, false); } }
/// <summary> /// 添加, 这里可以人工干预,提高程序的性能 /// </summary> /// <param name="entity">实体</param> /// <param name="identity">自增量方式,表主键是否采用自增的策略</param> /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param> /// <returns>主键</returns> public string Add(BaseUserLogonEntity entity, bool identity = true, bool returnId = true) { Identity = identity; ReturnId = returnId; entity.Id = AddEntity(entity).ToInt(); return(entity.Id.ToString()); }
/// <summary> /// 设置缓存 /// 20151007 吉日嘎拉,需要在一个连接上进行大量的操作 /// 20160128 吉日嘎拉,一些空调间的判断。 /// </summary> /// <param name="entity">用户实体</param> public static void SetCache(BaseUserLogonEntity entity) { var key = string.Empty; if (entity != null && entity.UserId > 0) { key = "UserLogon:" + entity.UserId; CacheUtil.Set(key, entity); } }
/// <summary> /// 获取缓存 /// </summary> /// <param name="key">缓存主键</param> /// <returns>用户信息</returns> public static BaseUserLogonEntity GetCacheByKey(string key) { BaseUserLogonEntity result = null; if (!string.IsNullOrWhiteSpace(key)) { result = CacheUtil.Get <BaseUserLogonEntity>(key); } return(result); }
/// <summary> /// 从缓存中获取实体 /// </summary> /// <param name="id"></param> /// <returns></returns> public static BaseUserLogonEntity GetEntityByCache(string id) { BaseUserLogonEntity result = null; if (!string.IsNullOrEmpty(id)) { var key = "UserLogon:" + id; result = CacheUtil.Cache(key, () => GetCacheByKey(key), true); } return(result); }
/// <summary> /// 重新设置缓存(重新强制设置缓存)可以提供外部调用的 /// 20151007 吉日嘎拉,需要在一个连接上进行大量的操作 /// </summary> /// <param name="userId">主键</param> /// <returns>用户信息</returns> public static BaseUserLogonEntity SetCache(string userId) { BaseUserLogonEntity result = null; var manager = new BaseUserLogonManager(); result = manager.GetEntityByUserId(userId); if (result != null) { SetCache(result); } return(result); }
/// <summary> /// 添加或更新(主键是否为0) /// </summary> /// <param name="entity">实体</param> /// <param name="identity">自增量方式,表主键是否采用自增的策略</param> /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param> /// <returns>主键</returns> public string AddOrUpdate(BaseUserLogonEntity entity, bool identity = true, bool returnId = true) { Identity = identity; ReturnId = returnId; if (entity.Id == 0) { entity.Id = AddEntity(entity).ToInt(); return(entity.Id.ToString()); } else { return(UpdateEntity(entity) > 0 ? entity.Id.ToString() : string.Empty); } }
/// <summary> /// 更新实体 /// </summary> /// <param name="taskId">任务标识</param> /// <param name="userInfo">用户</param> /// <param name="entity">实体</param> /// <returns>影响行数</returns> public int Update(string taskId, BaseUserInfo userInfo, BaseUserLogonEntity entity) { var result = 0; var parameter = ServiceInfo.Create(taskId, userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { // 调用方法,并且返回运行结果 var userLogonManager = new BaseUserLogonManager(); result = userLogonManager.Update(entity, true); }); return(result); }
/// <summary> /// 添加用户 /// </summary> /// <param name="entity">用户实体</param> /// <param name="userLogonEntity"></param> /// <returns>主键</returns> public string AddUser(BaseUserEntity entity, BaseUserLogonEntity userLogonEntity = null) { var result = string.Empty; BeforeAdd(entity); if (StatusCode == Status.OkAdd.ToString()) { //添加用户 result = AddEntity(entity); // 用户登录表里,插入一条记录 if (userLogonEntity == null) { userLogonEntity = new BaseUserLogonEntity(); } userLogonEntity.UserId = result.ToInt(); //userLogonEntity.CompanyId = entity.CompanyId; //把一些默认值读取到,系统的默认值,这样增加用户时可以把系统的默认值带入 userLogonEntity.ConcurrentUser = BaseSystemInfo.CheckOnline ? 0 : 1; userLogonEntity.CheckIpAddress = BaseSystemInfo.CheckIpAddress ? 1 : 0; //此处设置密码强度级别 userLogonEntity.PasswordStrength = SecretUtil.GetUserPassWordRate(userLogonEntity.UserPassword); //密码盐 userLogonEntity.Salt = RandomUtil.GetString(20); // 若是系统需要用加密的密码,这里需要加密密码。 if (BaseSystemInfo.ServerEncryptPassword) { userLogonEntity.UserPassword = EncryptUserPassword(userLogonEntity.UserPassword, userLogonEntity.Salt); // 安全通讯密码、交易密码也生成好 // userLogonEntity.UserPassword = this.EncryptUserPassword(entity.CommunicationPassword); } //// 2016.05.21 吉日嘎拉 完善创建信息 //userLogonEntity.CreateTime = DateTime.Now; //userLogonEntity.UpdateTime = DateTime.Now; //if (UserInfo != null) //{ // userLogonEntity.CreateUserId = UserInfo.UserId; // userLogonEntity.CreateBy = UserInfo.RealName; //} new BaseUserLogonManager(DbHelper, UserInfo).Add(userLogonEntity); AfterAdd(entity); } return(result); }
/// <summary> /// 添加用户 /// </summary> /// <param name="userInfo">用户信息</param> /// <param name="userEntity">用户实体</param> /// <param name="userLogonEntity">用户登录实体</param> /// <param name="userContactEntity"></param> /// <param name="status">状态</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string CreateUser(BaseUserInfo userInfo, BaseUserEntity userEntity, BaseUserLogonEntity userLogonEntity, BaseUserContactEntity userContactEntity, out Status status, out string statusMessage) { var result = string.Empty; var returnCode = Status.Ok; var returnMessage = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { result = CreateUser(dbHelper, userInfo, userEntity, userLogonEntity, userContactEntity, out returnCode, out returnMessage); }); status = returnCode; statusMessage = returnMessage; return(result); }
/// <summary> /// 获取实体 /// </summary> /// <param name="taskId">任务标识</param> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>实体</returns> public BaseUserLogonEntity GetEntity(string taskId, BaseUserInfo userInfo, string id) { BaseUserLogonEntity result = null; var parameter = ServiceInfo.Create(taskId, userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); // 判断是否已经登录的用户? if (userManager.UserIsLogon(userInfo)) { var userLogonManager = new BaseUserLogonManager(); result = userLogonManager.GetEntity(id); } }); return(result); }
/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> /// <param name="logHistory">记录历史</param> public int Update(BaseUserLogonEntity entity, bool logHistory) { var result = 0; if (logHistory) { // 获取原始实体信息 var entityOld = GetEntity(entity.Id); //2016-11-23 欧腾飞加入判断 原始实体信息如果为null 则不去保存修改记录(原始方法 实体可能为null如果去保存修改记录则会报错) if (entityOld != null) { // 保存修改记录 SaveEntityChangeLog(entity, entityOld); } } // 更新数据 result = UpdateEntity(entity); // 重新缓存 return(result); }
/// <summary> /// 检查用户的 IPAddress 绑定是否正常 /// /// 防止重复多读数据? /// 是否判断正确? /// 可以按每个用户缓存? /// 若没有就自动化增加? /// IP 限制完善? /// IP 限制缓存预热? /// </summary> /// <param name="userId">用户主键</param> /// <param name="userLogonEntity">用户登录实体</param> /// <param name="ipAddress">ip地址</param> /// <param name="autoAdd">没有在列表的IP是否自动增加</param> /// <returns>正确</returns> public static bool CheckIpAddressByCache(string userId, BaseUserLogonEntity userLogonEntity, string ipAddress, bool autoAdd = false) { // 默认是不成功的,防止出错误 var result = false; // 检查参数的有效性 if (!ValidateUtil.IsInt(userId)) { return(result); } if (string.IsNullOrEmpty(ipAddress)) { return(result); } int?checkIpAddress = null; if (userLogonEntity != null) { checkIpAddress = userLogonEntity.CheckIpAddress; } // 若用户是不限制登录的、那就可以返回真的 if (!checkIpAddress.HasValue || checkIpAddress.Value == 0) { return(true); } // 提高效率,全小写转换 ipAddress = ipAddress.ToLower(); // 这里是处理,多个IP的问题 var ip = ipAddress.Split(';'); var key = "IP:" + userId; //TODO result = true; return(result); }
/// <summary> /// 离职处理 /// </summary> /// <param name="userEntity"></param> /// <param name="userLogonEntity"></param> /// <param name="comment"></param> /// <returns>影响行数</returns> public int Leave(BaseUserEntity userEntity, BaseUserLogonEntity userLogonEntity, string comment) { var result = 0; if (userEntity != null) { // 更新用户实体 UpdateEntity(userEntity); } // 更新登录信息 if (userLogonEntity != null) { var userLogonManager = new BaseUserLogonManager(UserInfo); userLogonManager.UpdateEntity(userLogonEntity); } // 2016-03-17 吉日嘎拉 停止吉信的号码 if (userEntity != null && !string.IsNullOrEmpty(userEntity.NickName)) { //AfterLeaveStopIm(userEntity); } // 2016-03-17 吉日嘎拉 停止吉信的号码 if (userEntity != null && userEntity.Id > 0) { BaseUserContactEntity userContactEntity = null; // 2015-12-08 吉日嘎拉 提高效率、从缓存获取数据 userContactEntity = BaseUserContactManager.GetEntityByCache(userEntity.Id); if (userContactEntity != null && !string.IsNullOrEmpty(userContactEntity.CompanyEmail)) { ChangeUserMailStatus(userContactEntity.CompanyEmail, true); } } return(result); }
/// <summary> /// 设置实体 /// </summary> /// <param name="sqlBuilder">Sql语句生成器</param> /// <param name="entity">实体</param> private void SetEntity(SqlBuilder sqlBuilder, BaseUserLogonEntity entity) { SetEntityExtend(sqlBuilder, entity); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUserId, entity.UserId); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUserPassword, entity.UserPassword); sqlBuilder.SetValue(BaseUserLogonEntity.FieldOpenId, entity.OpenId); sqlBuilder.SetValue(BaseUserLogonEntity.FieldAllowStartTime, entity.AllowStartTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldAllowEndTime, entity.AllowEndTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldLockStartTime, entity.LockStartTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldLockEndTime, entity.LockEndTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldFirstVisitTime, entity.FirstVisitTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldPreviousVisitTime, entity.PreviousVisitTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldLastVisitTime, entity.LastVisitTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldChangePasswordTime, entity.ChangePasswordTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldLogonCount, entity.LogonCount); sqlBuilder.SetValue(BaseUserLogonEntity.FieldConcurrentUser, entity.ConcurrentUser); sqlBuilder.SetValue(BaseUserLogonEntity.FieldShowCount, entity.ShowCount); sqlBuilder.SetValue(BaseUserLogonEntity.FieldPasswordErrorCount, entity.PasswordErrorCount); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUserOnline, entity.UserOnline); sqlBuilder.SetValue(BaseUserLogonEntity.FieldCheckIpAddress, entity.CheckIpAddress); sqlBuilder.SetValue(BaseUserLogonEntity.FieldVerificationCode, entity.VerificationCode); sqlBuilder.SetValue(BaseUserLogonEntity.FieldIpAddress, entity.IpAddress); sqlBuilder.SetValue(BaseUserLogonEntity.FieldMacAddress, entity.MacAddress); sqlBuilder.SetValue(BaseUserLogonEntity.FieldQuestion, entity.Question); sqlBuilder.SetValue(BaseUserLogonEntity.FieldAnswerQuestion, entity.AnswerQuestion); sqlBuilder.SetValue(BaseUserLogonEntity.FieldSalt, entity.Salt); sqlBuilder.SetValue(BaseUserLogonEntity.FieldOpenIdTimeoutTime, entity.OpenIdTimeoutTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldSystemCode, entity.SystemCode); sqlBuilder.SetValue(BaseUserLogonEntity.FieldIpAddressName, entity.IpAddressName); sqlBuilder.SetValue(BaseUserLogonEntity.FieldPasswordStrength, entity.PasswordStrength); sqlBuilder.SetValue(BaseUserLogonEntity.FieldComputerName, entity.ComputerName); sqlBuilder.SetValue(BaseUserLogonEntity.FieldNeedModifyPassword, entity.NeedModifyPassword); sqlBuilder.SetValue(BaseUserLogonEntity.FieldSortCode, entity.SortCode); sqlBuilder.SetValue(BaseUserLogonEntity.FieldDeleted, entity.Deleted); sqlBuilder.SetValue(BaseUserLogonEntity.FieldEnabled, entity.Enabled); }
/// <summary> /// 更新实体 /// </summary> /// <param name="entity">实体</param> public int UpdateEntity(BaseUserLogonEntity entity) { var sqlBuilder = new SqlBuilder(DbHelper); sqlBuilder.BeginUpdate(CurrentTableName); SetEntity(sqlBuilder, entity); if (UserInfo != null) { sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateUserId, UserInfo.UserId); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateUserName, UserInfo.UserName); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateBy, UserInfo.RealName); } sqlBuilder.SetDbNow(BaseUserLogonEntity.FieldUpdateTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateIp, Utils.GetIp()); sqlBuilder.SetWhere(PrimaryKey, entity.Id); //return sqlBuilder.EndUpdate(); var result = sqlBuilder.EndUpdate(); if (result > 0) { RemoveCache(entity.Id); } return(result); }
// public async Task /// <summary> /// 更新访问数据 /// </summary> /// <param name="userLogonEntity"></param> /// <param name="openId"></param> /// <param name="createOpenId"></param> public void UpdateVisitTimeTask(BaseUserLogonEntity userLogonEntity, string openId, bool createOpenId = true) { var errorMark = 0; var sql = string.Empty; //默认给OpenId 8个小时有效期,每次更新在线状态的时候,再刷新一下OpenId的有效期,Troy.Cui 2020-02-29 DateTime?openIdTimeout = DateTime.Now.AddHours(8); try { using (var dbHelper = DbHelperFactory.Create(BaseSystemInfo.UserCenterDbType, BaseSystemInfo.UserCenterDbConnection)) { // 是否更新访问日期信息 List <IDbDataParameter> dbParameters = null; // 若有一周没登录了,需要重新进行手机验证 var mobileNeedValiated = false; if (userLogonEntity.PreviousVisitTime.HasValue || userLogonEntity.FirstVisitTime.HasValue) { var ts = new TimeSpan(); if (userLogonEntity.LastVisitTime.HasValue) { ts = DateTime.Now.Subtract((DateTime)userLogonEntity.LastVisitTime); mobileNeedValiated = (ts.TotalDays > 7); } else if (userLogonEntity.FirstVisitTime.HasValue) { ts = DateTime.Now.Subtract((DateTime)userLogonEntity.FirstVisitTime); mobileNeedValiated = (ts.TotalDays > 7); } if (mobileNeedValiated) { sql = "UPDATE " + BaseUserContactEntity.CurrentTableName + " SET " + BaseUserContactEntity.FieldMobileValidated + " = 0 " + " WHERE " + BaseUserContactEntity.FieldUserId + " = " + DbHelper.GetParameter(BaseUserContactEntity.FieldUserId) + " AND " + BaseUserContactEntity.FieldMobileValidated + " = " + DbHelper.GetParameter(BaseUserContactEntity.FieldMobileValidated); dbParameters = new List <IDbDataParameter> { DbHelper.MakeParameter(BaseUserContactEntity.FieldUserId, userLogonEntity.UserId), DbHelper.MakeParameter(BaseUserContactEntity.FieldMobileValidated, 1) }; errorMark = 10; dbHelper.ExecuteNonQuery(sql, dbParameters.ToArray()); } } if (BaseSystemInfo.UpdateVisit) { // 第一次登录时间 if (userLogonEntity.FirstVisitTime == null) { sql = "UPDATE " + CurrentTableName + " SET " + BaseUserLogonEntity.FieldPasswordErrorCount + " = 0 " + ", " + BaseUserLogonEntity.FieldUserOnline + " = 1 " + ", " + BaseUserLogonEntity.FieldFirstVisitTime + " = " + dbHelper.GetDbNow() + ", " + BaseUserLogonEntity.FieldLogonCount + " = 1 " + ", " + BaseUserLogonEntity.FieldSystemCode + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldSystemCode) + ", " + BaseUserLogonEntity.FieldIpAddress + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldIpAddress) + ", " + BaseUserLogonEntity.FieldIpAddressName + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldIpAddressName) + ", " + BaseUserLogonEntity.FieldMacAddress + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldMacAddress) + ", " + BaseUserLogonEntity.FieldComputerName + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldComputerName); dbParameters = new List <IDbDataParameter> { dbHelper.MakeParameter(BaseUserLogonEntity.FieldSystemCode, userLogonEntity.SystemCode), dbHelper.MakeParameter(BaseUserLogonEntity.FieldIpAddress, userLogonEntity.IpAddress), dbHelper.MakeParameter(BaseUserLogonEntity.FieldIpAddressName, userLogonEntity.IpAddressName), dbHelper.MakeParameter(BaseUserLogonEntity.FieldMacAddress, userLogonEntity.MacAddress), dbHelper.MakeParameter(BaseUserLogonEntity.FieldComputerName, userLogonEntity.ComputerName) }; if (createOpenId) { sql += ", " + BaseUserLogonEntity.FieldOpenId + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldOpenId); sql += ", " + BaseUserLogonEntity.FieldOpenIdTimeoutTime + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldOpenIdTimeoutTime); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldOpenId, openId)); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldOpenIdTimeoutTime, openIdTimeout)); } sql += " WHERE " + BaseUserLogonEntity.FieldUserId + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldUserId) + " AND " + BaseUserLogonEntity.FieldFirstVisitTime + " IS NULL"; dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldUserId, userLogonEntity.UserId)); errorMark = 20; dbHelper.ExecuteNonQuery(sql, dbParameters.ToArray()); } else { // 最后一次登录时间 sql = "UPDATE " + CurrentTableName + " SET " + BaseUserLogonEntity.FieldPasswordErrorCount + " = 0 " + ", " + BaseUserLogonEntity.FieldPreviousVisitTime + " = " + BaseUserLogonEntity.FieldLastVisitTime + ", " + BaseUserLogonEntity.FieldUserOnline + " = 1 " + ", " + BaseUserLogonEntity.FieldLastVisitTime + " = " + dbHelper.GetDbNow() + ", " + BaseUserLogonEntity.FieldLogonCount + " = " + BaseUserLogonEntity.FieldLogonCount + " + 1 " + ", " + BaseUserLogonEntity.FieldSystemCode + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldSystemCode) + ", " + BaseUserLogonEntity.FieldIpAddress + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldIpAddress) + ", " + BaseUserLogonEntity.FieldIpAddressName + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldIpAddressName) + ", " + BaseUserLogonEntity.FieldMacAddress + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldMacAddress) + ", " + BaseUserLogonEntity.FieldComputerName + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldComputerName); dbParameters = new List <IDbDataParameter> { dbHelper.MakeParameter(BaseUserLogonEntity.FieldSystemCode, userLogonEntity.SystemCode), dbHelper.MakeParameter(BaseUserLogonEntity.FieldIpAddress, userLogonEntity.IpAddress), dbHelper.MakeParameter(BaseUserLogonEntity.FieldIpAddressName, userLogonEntity.IpAddressName), dbHelper.MakeParameter(BaseUserLogonEntity.FieldMacAddress, userLogonEntity.MacAddress), dbHelper.MakeParameter(BaseUserLogonEntity.FieldComputerName, userLogonEntity.ComputerName) }; if (createOpenId) { sql += ", " + BaseUserLogonEntity.FieldOpenId + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldOpenId); sql += ", " + BaseUserLogonEntity.FieldOpenIdTimeoutTime + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldOpenIdTimeoutTime); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldOpenId, openId)); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldOpenIdTimeoutTime, openIdTimeout)); } sql += " WHERE " + BaseUserLogonEntity.FieldUserId + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldUserId); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldUserId, userLogonEntity.UserId)); errorMark = 30; dbHelper.ExecuteNonQuery(sql, dbParameters.ToArray()); } } else { sql = "UPDATE " + CurrentTableName + " SET " + BaseUserLogonEntity.FieldPasswordErrorCount + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldPasswordErrorCount) + ", " + BaseUserLogonEntity.FieldSystemCode + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldSystemCode); dbParameters = new List <IDbDataParameter> { dbHelper.MakeParameter(BaseUserLogonEntity.FieldPasswordErrorCount, 0), dbHelper.MakeParameter(BaseUserLogonEntity.FieldSystemCode, userLogonEntity.SystemCode) }; if (createOpenId) { sql += ", " + BaseUserLogonEntity.FieldOpenId + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldOpenId); sql += ", " + BaseUserLogonEntity.FieldOpenIdTimeoutTime + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldOpenIdTimeoutTime); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldOpenId, openId)); dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldOpenIdTimeoutTime, openIdTimeout)); } sql += " WHERE " + BaseUserLogonEntity.FieldUserId + " = " + dbHelper.GetParameter(BaseUserLogonEntity.FieldUserId); // sql += " AND " + BaseUserEntity.FieldOpenId + " IS NULL "; dbParameters.Add(dbHelper.MakeParameter(BaseUserLogonEntity.FieldUserId, userLogonEntity.UserId)); errorMark = 40; dbHelper.ExecuteNonQuery(sql, dbParameters.ToArray()); } } } catch (Exception ex) { var writeMessage = "BaseUserLogonManager.UpdateVisitTimeTask:发生时间:" + DateTime.Now + Environment.NewLine + "errorMark = " + errorMark + Environment.NewLine + "UserInfo:" + UserInfo.Serialize() + Environment.NewLine + "Message:" + ex.Message + Environment.NewLine + "Source:" + ex.Source + Environment.NewLine + "StackTrace:" + ex.StackTrace + Environment.NewLine + "TargetSite:" + ex.TargetSite + Environment.NewLine; LogUtil.WriteLog(writeMessage, "Exception"); } }
/// <summary> /// 更新 /// </summary> /// <param name="entity">实体</param> public int Update(BaseUserLogonEntity entity) { return(UpdateEntity(entity)); }
/// <summary> /// 添加实体 /// </summary> /// <param name="entity">实体</param> public string AddEntity(BaseUserLogonEntity entity) { var key = string.Empty; if (entity.SortCode == 0) { var managerSequence = new BaseSequenceManager(DbHelper, Identity); if (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2) { key = managerSequence.Increment($"SC_{CurrentTableName}_SEQ"); } else { key = managerSequence.Increment(CurrentTableName); } entity.SortCode = key.ToInt(); } var sqlBuilder = new SqlBuilder(DbHelper, Identity, ReturnId); sqlBuilder.BeginInsert(CurrentTableName, PrimaryKey); if (!Identity) { // 这里已经是指定了主键了,所以不需要返回主键了 sqlBuilder.ReturnId = false; sqlBuilder.SetValue(PrimaryKey, entity.Id); } else { if (!ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(PrimaryKey, $"{CurrentTableName}_SEQ.NEXTVAL"); } if (DbHelper.CurrentDbType == CurrentDbType.Db2) { sqlBuilder.SetFormula(PrimaryKey, $"NEXT VALUE FOR {CurrentTableName}_SEQ"); } } else { if (Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2)) { var managerSequence = new BaseSequenceManager(DbHelper); entity.Id = managerSequence.Increment($"{CurrentTableName}_SEQ").ToInt(); sqlBuilder.SetValue(PrimaryKey, entity.Id); } } } SetEntity(sqlBuilder, entity); if (UserInfo != null) { sqlBuilder.SetValue(BaseUserLogonEntity.FieldCreateUserId, UserInfo.UserId); sqlBuilder.SetValue(BaseUserLogonEntity.FieldCreateUserName, UserInfo.UserName); sqlBuilder.SetValue(BaseUserLogonEntity.FieldCreateBy, UserInfo.RealName); } else { sqlBuilder.SetValue(BaseUserLogonEntity.FieldCreateBy, entity.CreateBy); sqlBuilder.SetValue(BaseUserLogonEntity.FieldCreateUserName, entity.CreateUserName); } sqlBuilder.SetDbNow(BaseUserLogonEntity.FieldCreateTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldCreateIp, Utils.GetIp()); if (UserInfo != null) { sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateUserId, UserInfo.UserId); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateUserName, UserInfo.UserName); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateBy, UserInfo.RealName); } sqlBuilder.SetDbNow(BaseUserLogonEntity.FieldUpdateTime); sqlBuilder.SetValue(BaseUserLogonEntity.FieldUpdateIp, Utils.GetIp()); if (Identity && (DbHelper.CurrentDbType == CurrentDbType.SqlServer || DbHelper.CurrentDbType == CurrentDbType.Access)) { key = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } if (Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.Db2)) { key = entity.Id.ToString(); } if (!string.IsNullOrWhiteSpace(key)) { RemoveCache(); } return(key); }
// 这个是声明扩展方法 partial void SetEntityExtend(SqlBuilder sqlBuilder, BaseUserLogonEntity entity);
/// <summary> /// 导入员工 /// </summary> /// <param name="dataReader"></param> /// <param name="staffManager"></param> /// <param name="userManager"></param> /// <param name="userLogonManager"></param> /// <returns></returns> //public int ImportStaff(IDataReader dataReader, BaseStaffManager staffManager, BaseUserExpressManager sTaffExpressManager, BaseUserManager userManager, BaseUserLogonManager userLogonManager) public int ImportStaff(IDataReader dataReader, BaseStaffManager staffManager, BaseUserManager userManager, BaseUserLogonManager userLogonManager) { var result = 0; /* * BaseStaffEntity staffEntity = staffManager.GetEntity(dataReader["Id"].ToString()); * if (staffEntity == null) * { * staffEntity = new BaseStaffEntity(); * } * staffEntity.Id = int.Parse(dataReader["Id"].ToString()); * staffEntity.Code = dataReader["EMPLOYEE_CODE"].ToString(); * staffEntity.RealName = dataReader["EMPLOYEE_NAME"].ToString(); * staffEntity.Telephone = dataReader["PHONE"].ToString(); * staffEntity.HomeAddress = dataReader["ADDRESS"].ToString(); * staffEntity.IDCard = dataReader["ID_CARD"].ToString(); * * // staffEntity.CompanyId = dataReader["OWNER_SITE"].ToString(); * staffEntity.CompanyName = dataReader["OWNER_SITE"].ToString(); * // staffEntity.DepartmentId = dataReader["DEPT_NAME"].ToString(); * staffEntity.DepartmentName = dataReader["DEPT_NAME"].ToString(); * // staffEntity.WorkgroupId = dataReader["GROUP_NAME"].ToString(); * staffEntity.WorkgroupName = dataReader["GROUP_NAME"].ToString(); * * System.Console.WriteLine("ImportK8Staff:" + staffEntity.Id + ":" + staffEntity.RealName); * // 02:可以把读取到的数据能写入到用户中心的。 * result = staffManager.UpdateEntity(staffEntity); * if (result == 0) * { * staffManager.AddEntity(staffEntity); * } */ /* * BaseUserExpressEntity sTAFF_EXPRESSEntity = sTAFF_EXPRESSManager.GetEntity(dataReader["Id"].ToString()); * if (sTAFF_EXPRESSEntity == null) * { * sTAFF_EXPRESSEntity = new BaseUserExpressEntity(); * } * sTAFF_EXPRESSEntity.Id = int.Parse(dataReader["Id"].ToString()); * sTAFF_EXPRESSEntity.OWNER_RANGE = dataReader["OWNER_RANGE"].ToString(); * Decimal tRANSFER_ADD_FEE = 0; * if (!string.IsNullOrEmpty(dataReader["TRANSFER_ADD_FEE"].ToString()) && ValidateUtil.IsDouble(dataReader["TRANSFER_ADD_FEE"].ToString())) * { * tRANSFER_ADD_FEE = Decimal.Parse(dataReader["TRANSFER_ADD_FEE"].ToString()); * } * sTAFF_EXPRESSEntity.TRANSFER_ADD_FEE = tRANSFER_ADD_FEE; * Decimal dISPATCH_ADD_FEE = 0; * if (!string.IsNullOrEmpty(dataReader["DISPATCH__ADD_FEE"].ToString()) && ValidateUtil.IsDouble(dataReader["DISPATCH__ADD_FEE"].ToString())) * { * dISPATCH_ADD_FEE = Decimal.Parse(dataReader["DISPATCH__ADD_FEE"].ToString()); * } * sTAFF_EXPRESSEntity.DISPATCH_ADD_FEE = dISPATCH_ADD_FEE; * * System.Console.WriteLine("ImportK8Staffexpress:" + staffEntity.Id + ":" + staffEntity.RealName); * // 02:可以把读取到的数据能写入到用户中心的。 * result = sTAFF_EXPRESSManager.Update(sTAFF_EXPRESSEntity); * if (result == 0) * { * sTAFF_EXPRESSManager.Add(sTAFF_EXPRESSEntity); * } */ var userEntity = new BaseUserEntity { Id = dataReader["ID"].ToString().ToInt(), UserFrom = "PDA", Code = dataReader["EMPLOYEE_CODE"].ToString(), UserName = dataReader["EMPLOYEE_NAME"].ToString(), RealName = dataReader["REAL_NAME"].ToString(), Description = dataReader["PHONE"].ToString(), CompanyName = dataReader["OWNER_SITE"].ToString() }; if (userEntity.CompanyId > 0) { if (BaseOrganizationManager.GetEntityByNameByCache(userEntity.CompanyName) == null) { Console.WriteLine("无CompanyId " + userEntity.Id + ":" + userEntity.UserName + ":" + userEntity.RealName); return(0); } } userEntity.DepartmentName = dataReader["DEPT_NAME"].ToString(); userEntity.WorkgroupName = dataReader["GROUP_NAME"].ToString(); userEntity.HomeAddress = dataReader["ADDRESS"].ToString(); userEntity.IdCard = dataReader["ID_CARD"].ToString(); if (!string.IsNullOrEmpty(dataReader["cardnum"].ToString())) { userEntity.IdCard = dataReader["cardnum"].ToString(); } userEntity.Signature = dataReader["EMPLOYEE_TYPE"].ToString(); userEntity.SortCode = int.Parse(dataReader["ID"].ToString()); if (userEntity.UpdateTime == null) { userEntity.UpdateTime = DateTime.Parse(dataReader["UPDATETIME"].ToString()); } else { if (userEntity.UpdateTime < DateTime.Parse(dataReader["UPDATETIME"].ToString())) { userEntity.UpdateTime = DateTime.Parse(dataReader["UPDATETIME"].ToString()); } } // 修改日期需要同步 // result = userManager.UpdateEntity(userEntity); if (result == 0) { userManager.AddEntity(userEntity); var userContactEntity = new BaseUserContactEntity { UserId = dataReader["ID"].ToString().ToInt(), Telephone = dataReader["PHONE"].ToString() }; new BaseUserContactManager().AddEntity(userContactEntity); var userLogonEntity = new BaseUserLogonEntity { UserId = dataReader["ID"].ToString().ToInt(), UserPassword = dataReader["BAR_PASSWORD"].ToString() }; userLogonManager.AddEntity(userLogonEntity); } // 处理角色 /* * string roleName = dataReader["EMPLOYEE_TYPE"].ToString(); * // 看是否在这个角色里,若没有增加上去。 * userManager.AddToRole("PDA", userEntity.Id, roleName); * * // 添加用户密码表 * BaseUserLogonEntity userLogonEntity = userLogonManager.GetEntity(userEntity.Id); * if (userLogonEntity == null) * { * userLogonEntity = new BaseUserLogonEntity(); * userLogonEntity.Id = userEntity.Id; * userLogonEntity.UserPassword = dataReader["BAR_PASSWORD"].ToString(); * //userLogonEntity.Salt = dataReader["SALT"].ToString(); * //if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) * //{ * // userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); * //} * userLogonManager.AddEntity(userLogonEntity); * } * else * { * userLogonEntity.Id = userEntity.Id; * userLogonEntity.UserPassword = dataReader["BAR_PASSWORD"].ToString(); * //userLogonEntity.Salt = dataReader["SALT"].ToString(); * //if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) * //{ * // userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); * //} * result = userLogonManager.UpdateEntity(userLogonEntity); * } */ return(result); }
/// <summary> /// 设置密码 /// </summary> /// <param name="userId">被设置的用户主键</param> /// <param name="newPassword">新密码(原始,未加密)</param> /// <param name="unlock">解除锁定</param> /// <param name="autoAdd">数据缺少自动补充登录信息</param> /// <param name="changeLog">记录更改</param> /// <returns>影响行数</returns> public virtual int SetPassword(int userId, string newPassword, bool?unlock = null, bool?autoAdd = null, bool changeLog = true) { var result = 0; // 密码强度检查 /* * if (BaseSystemInfo.CheckPasswordStrength) * { * if (password.Length == 0) * { * this.StatusCode = StatusCode.PasswordCanNotBeNull.ToString(); * return result; * } * } */ var encryptPassword = newPassword; var salt = string.Empty; // 加密密码 if (BaseSystemInfo.ServerEncryptPassword) { salt = RandomUtil.GetString(20); encryptPassword = EncryptUserPassword(newPassword, salt); } // 设置密码字段 var parameters = new List <KeyValuePair <string, object> > { new KeyValuePair <string, object>(BaseUserLogonEntity.FieldUserPassword, encryptPassword), // 2016-05-20 吉日嘎拉 把修改的痕迹保留起来 new KeyValuePair <string, object>(BaseUserLogonEntity.FieldUpdateTime, DateTime.Now) }; if (UserInfo != null) { parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldUpdateUserId, UserInfo.UserId)); parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldUpdateBy, UserInfo.RealName)); } //需要重新登录才可以,防止正在被人黑中,阻止已经在线上的人 parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldOpenId, Guid.NewGuid().ToString("N"))); if (BaseSystemInfo.ServerEncryptPassword) { parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldSalt, salt)); } parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldChangePasswordTime, DateTime.Now)); if (unlock.HasValue && unlock.Value == true) { parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldLockStartTime, null)); parameters.Add(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldLockEndTime, null)); } var userLogonManager = new BaseUserLogonManager(DbHelper, UserInfo); result = userLogonManager.SetProperty(new KeyValuePair <string, object>(BaseUserLogonEntity.FieldUserId, userId), parameters); if (result == 0 && autoAdd.HasValue && autoAdd.Value == true) { var userLogonEntity = new BaseUserLogonEntity { UserId = userId, ChangePasswordTime = DateTime.Now, UserPassword = encryptPassword, Salt = salt, Enabled = 1, CreateTime = DateTime.Now, UpdateTime = DateTime.Now }; if (UserInfo != null) { userLogonEntity.CreateUserId = UserInfo.UserId; userLogonEntity.CreateBy = UserInfo.RealName; } userLogonManager.AddEntity(userLogonEntity); result = 1; } // 2015-12-09 吉日嘎拉 增加日志功能、谁什么时候设置了谁的密码? if (changeLog) { var record = new BaseChangeLogEntity { TableName = BaseUserLogonEntity.CurrentTableName, TableDescription = FieldExtensions.ToDescription(typeof(BaseUserLogonEntity), "CurrentTableName"), ColumnName = BaseUserLogonEntity.FieldUserPassword, ColumnDescription = "用户密码", RecordKey = userId.ToString(), NewValue = "设置密码" }; var changeLogManager = new BaseChangeLogManager(UserInfo); changeLogManager.Add(record, true, false); } if (result == 1) { StatusCode = Status.SetPasswordOk.ToString(); // 调用扩展 if (BaseSystemInfo.OnInternet && BaseSystemInfo.ServerEncryptPassword) { // AfterSetPassword(userId, salt, password); } } else { // 数据可能被删除 StatusCode = Status.ErrorDeleted.ToString(); } return(result); }
/// <summary> /// 导入用户 /// </summary> /// <param name="dataReader"></param> /// <param name="organizationManager"></param> /// <param name="userLogonManager"></param> /// <param name="userContactManager"></param> /// <returns></returns> public int ImportUser(IDataReader dataReader, BaseOrganizationManager organizationManager, BaseUserLogonManager userLogonManager, BaseUserContactManager userContactManager) { var result = 0; var userEntity = GetEntity(dataReader["ID"].ToString()); if (userEntity == null) { userEntity = new BaseUserEntity { Id = dataReader["ID"].ToString().ToInt() }; } userEntity.Id = dataReader["ID"].ToString().ToInt(); userEntity.UserFrom = "K8"; userEntity.UserName = dataReader["USER_NAME"].ToString(); userEntity.IdCard = dataReader["ID_Card"].ToString(); userEntity.Code = dataReader["EMPLOYEE_CODE"].ToString(); userEntity.RealName = dataReader["REAL_NAME"].ToString(); if (string.IsNullOrWhiteSpace(userEntity.RealName)) { userEntity.RealName = dataReader["EMPLOYEE_NAME"].ToString(); } userEntity.NickName = dataReader["ONLY_USER_NAME"].ToString(); userEntity.CompanyName = dataReader["OWNER_SITE"].ToString(); userEntity.Description = dataReader["REMARK"].ToString(); // 把被删除的数据恢复过来 userEntity.Deleted = 0; if (userEntity.CompanyId > 0) { if (string.IsNullOrEmpty(organizationManager.GetProperty(new KeyValuePair <string, object>(BaseOrganizationEntity.FieldName, userEntity.CompanyName), BaseOrganizationEntity.FieldId))) { Console.WriteLine("无CompanyId " + userEntity.Id + ":" + userEntity.UserName + ":" + userEntity.RealName); return(0); } } // 不是内部组织机构的才进行调整 if (userEntity.DepartmentId > 0) { userEntity.DepartmentName = dataReader["DEPT_NAME"].ToString(); } if (!string.IsNullOrEmpty(dataReader["IM_NAME"].ToString())) { // userEntity.QQ = dataReader["IM_NAME"].ToString(); } userEntity.Enabled = int.Parse(dataReader["BL_LOCK_FLAG"].ToString()); Console.WriteLine("ImportK8User:"******":" + userEntity.RealName); // 02:可以把读取到的数据能写入到用户中心的。 result = UpdateEntity(userEntity); if (result == 0) { AddEntity(userEntity); } // 添加用户密码表 var userLogonEntity = userLogonManager.GetEntityByUserId(userEntity.Id); if (userLogonEntity == null) { userLogonEntity = new BaseUserLogonEntity { UserId = userEntity.Id, // 邦定mac地址 CheckIpAddress = 1, UserPassword = dataReader["USER_PASSWD"].ToString(), Salt = dataReader["SALT"].ToString() }; // 是否检查机器码 MAC地址 var checkIpAddress = 1; int.TryParse(dataReader["BL_CHECK_COMPUTER"].ToString(), out checkIpAddress); userLogonEntity.CheckIpAddress = checkIpAddress; if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) { userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); } userLogonManager.AddEntity(userLogonEntity); } else { userLogonEntity.UserId = userEntity.Id; userLogonEntity.UserPassword = dataReader["USER_PASSWD"].ToString(); userLogonEntity.Salt = dataReader["SALT"].ToString(); if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString())) { userLogonEntity.ChangePasswordTime = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString()); } result = userLogonManager.UpdateEntity(userLogonEntity); } // 用户的联系方式 var userContactEntity = userContactManager.GetEntityByUserId(userEntity.Id.ToString()); if (userContactEntity == null) { userContactEntity = new BaseUserContactEntity { UserId = userEntity.Id, Qq = dataReader["QQ"].ToString(), Mobile = dataReader["Mobile"].ToString(), Email = dataReader["Email"].ToString() }; userContactManager.AddEntity(userContactEntity); } else { if (!string.IsNullOrEmpty(dataReader["QQ"].ToString())) { userContactEntity.Qq = dataReader["QQ"].ToString(); } if (!string.IsNullOrEmpty(dataReader["Mobile"].ToString())) { userContactEntity.Mobile = dataReader["Mobile"].ToString(); } if (!string.IsNullOrEmpty(dataReader["Email"].ToString())) { userContactEntity.Email = dataReader["Email"].ToString(); } userContactManager.AddOrUpdate(userContactEntity); } return(result); }
/// <summary> /// 转换为UserInfo用户信息 /// </summary> /// <param name="userEntity"></param> /// <param name="userLogonEntity"></param> /// <param name="validateUserOnly"></param> /// <returns></returns> public BaseUserInfo ConvertToUserInfo(BaseUserEntity userEntity, BaseUserLogonEntity userLogonEntity = null, bool validateUserOnly = false) { var userInfo = new BaseUserInfo(); return(ConvertToUserInfo(userInfo, userEntity, userLogonEntity, validateUserOnly)); }
/// <summary> /// 转换为UserInfo用户信息 /// </summary> /// <param name="userInfo"></param> /// <param name="userEntity"></param> /// <param name="userLogonEntity"></param> /// <param name="validateUserOnly"></param> /// <returns></returns> public BaseUserInfo ConvertToUserInfo(BaseUserInfo userInfo, BaseUserEntity userEntity, BaseUserLogonEntity userLogonEntity = null, bool validateUserOnly = false) { if (userEntity == null) { return(null); } userInfo.Id = userEntity.Id.ToString(); userInfo.UserId = userEntity.Id; userInfo.IsAdministrator = userEntity.IsAdministrator == 1; userInfo.Code = userEntity.Code; userInfo.UserName = userEntity.UserName; userInfo.RealName = userEntity.RealName; userInfo.NickName = userEntity.NickName; if (userLogonEntity != null) { userInfo.OpenId = userLogonEntity.OpenId; } userInfo.CompanyId = userEntity.CompanyId.ToString(); userInfo.CompanyName = userEntity.CompanyName; userInfo.CompanyCode = BaseOrganizationManager.GetEntityByCache(userEntity.CompanyId.ToString())?.Code; //Troy.Cui 2018.08.04 增加Sub的转换 userInfo.SubCompanyId = userEntity.SubCompanyId.ToString(); userInfo.SubCompanyName = userEntity.SubCompanyName; userInfo.SubCompanyCode = BaseOrganizationManager.GetEntityByCache(userEntity.SubCompanyId.ToString())?.Code; userInfo.DepartmentId = userEntity.DepartmentId.ToString(); userInfo.DepartmentName = userEntity.DepartmentName; userInfo.DepartmentCode = BaseOrganizationManager.GetEntityByCache(userEntity.DepartmentId.ToString())?.Code; userInfo.SubDepartmentId = userEntity.SubDepartmentId.ToString(); userInfo.SubDepartmentName = userEntity.SubDepartmentName; userInfo.SubDepartmentCode = BaseOrganizationManager.GetEntityByCache(userEntity.SubDepartmentId.ToString())?.Code; userInfo.WorkgroupId = userEntity.WorkgroupId.ToString(); userInfo.WorkgroupName = userEntity.WorkgroupName; //2016-11-23 欧腾飞加入 companyCode 和数字签名 userInfo.Signature = userEntity.Signature; BaseOrganizationEntity organizationEntity = null; if (!string.IsNullOrEmpty(userInfo.CompanyId)) { try { organizationEntity = BaseOrganizationManager.GetEntityByCache(userInfo.CompanyId.ToString()); } catch (Exception ex) { var writeMessage = "BaseOrganizationManager.GetEntityByCache:发生时间:" + DateTime.Now + Environment.NewLine + "CompanyId 无法缓存获取:" + userInfo.CompanyId + Environment.NewLine + "Message:" + ex.Message + Environment.NewLine + "Source:" + ex.Source + Environment.NewLine + "StackTrace:" + ex.StackTrace + Environment.NewLine + "TargetSite:" + ex.TargetSite + Environment.NewLine; LogUtil.WriteLog(writeMessage, "Exception"); } if (organizationEntity == null) { var organizationManager = new BaseOrganizationManager(); organizationEntity = organizationManager.GetEntity(userInfo.CompanyId); // 2015-12-06 吉日嘎拉 进行记录日志功能改进 if (organizationEntity == null) { var writeMessage = "BaseOrganizationManager.GetEntity:发生时间:" + DateTime.Now + Environment.NewLine + "CompanyId 无法缓存获取:" + userInfo.CompanyId + Environment.NewLine + "BaseUserInfo:" + userInfo.Serialize(); LogUtil.WriteLog(writeMessage, "Log"); } } if (organizationEntity != null) { userInfo.CompanyCode = organizationEntity.Code; } } ////部门数据需要从部门表里读取 //if (!validateUserOnly && !string.IsNullOrEmpty(userInfo.DepartmentId)) //{ // organizationEntity = BaseOrganizationManager.GetEntityByCache(userInfo.DepartmentId); //} //else //{ // if (organizationManager == null) // { // organizationManager = new Business.BaseOrganizationManager(); // } // organizationEntity = organizationManager.GetEntity(userInfo.DepartmentId); //} //if (organizationEntity != null) //{ // userInfo.DepartmentCode = organizationEntity.Code; //} return(userInfo); }
/// <summary> /// 添加用户 /// </summary> /// <param name="dbHelper">数据库连接</param> /// <param name="userInfo">用户信息</param> /// <param name="entity">用户实体</param> /// <param name="userLogonEntity">用户登录实体</param> /// <param name="userContactEntity">用户联系方式</param> /// <param name="status">状态</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string CreateUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity entity, BaseUserLogonEntity userLogonEntity, BaseUserContactEntity userContactEntity, out Status status, out string statusMessage) { var result = string.Empty; // 加强安全验证防止未授权匿名调用 #if (!DEBUG) BaseSystemInfo.IsAuthorized(userInfo); #endif var userManager = new BaseUserManager(dbHelper, userInfo); result = userManager.AddUser(entity, userLogonEntity); status = userManager.Status; statusMessage = userManager.GetStateMessage(); // 20140219 JiRiGaLa 添加成功的用户才增加联系方式 if (!string.IsNullOrEmpty(result) && status == Status.OkAdd && userContactEntity != null) { // 添加联系方式 userContactEntity.UserId = int.Parse(result); var userContactManager = new BaseUserContactManager(dbHelper, userInfo); userContactEntity.CompanyId = entity.CompanyId; userContactManager.Add(userContactEntity); } // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了 if (entity.Enabled == 0 && status == Status.OkAdd) { // 不是系统管理员添加 if (!BaseUserManager.IsAdministrator(userInfo.Id)) { // 给超级管理员群组发信息 var roleManager = new BaseRoleManager(dbHelper, userInfo); var roleIds = roleManager.GetIds(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, "Administrators")); var userIds = userManager.GetIds(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, "Administrator")); // 发送请求审核的信息 //var messageEntity = new BaseMessageEntity //{ // FunctionCode = MessageFunction.WaitForAudit.ToString(), // // Pcsky 2012.05.04 显示申请的用户名 // Contents = userInfo.RealName + "(" + userInfo.IpAddress + ")" + AppMessage.UserServiceApplication + entity.UserName + AppMessage.UserServiceCheck //}; //messageEntity.Contents = result.RealName + "(" + result.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check; //var messageManager = new BaseMessageManager(dbHelper, userInfo); //messageManager.BatchSend(userIds, null, roleIds, messageEntity, false); } } return(result); }
/// <summary> /// 更新用户 /// </summary> /// <param name="userInfo">用户信息</param> /// <param name="entity">用户实体</param> /// <param name="userLogonEntity">用户登录实体</param> /// <param name="userContactEntity">用户联系方式实体</param> /// <param name="status">状态</param> /// <param name="statusMessage">状态信息</param> /// <returns>影响行数</returns> public int UpdateUser(BaseUserInfo userInfo, BaseUserEntity entity, BaseUserLogonEntity userLogonEntity, BaseUserContactEntity userContactEntity, out Status status, out string statusMessage) { var result = 0; var returnCode = Status.Ok; var returnMessage = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); // 调用方法,并且返回运行结果,判断重复 // result = userManager.Update(entity, out StatusCode); // 不判断重复直接更新 if (entity != null) { // 2015-12-09 吉日嘎拉 确认更新日志功能 result = userManager.Update(entity); // 若是超级管理员,就是名字编号重复了,也应该能修改数据比较好,否则有些事情无法办理下去了,由于历史原因导致数据重复的什么的,也需要能修改才可以。 if (BaseUserManager.IsAdministrator(userInfo.Id)) { if (userManager.StatusCode == Status.ErrorUserExist.ToString() || userManager.StatusCode == Status.ErrorCodeExist.ToString()) { result = userManager.UpdateEntity(entity); } } } //用户登录 Troy.Cui 2018-10-06增加 if (userLogonEntity != null) { var userLogonManager = new BaseUserLogonManager(dbHelper, userInfo); userLogonManager.Update(userLogonEntity, true); } if (userContactEntity != null) { var userContactManager = new BaseUserContactManager(dbHelper, userInfo); userContactManager.SetEntity(userContactEntity); } if (result == 1) { userManager.Status = Status.OkUpdate; userManager.StatusCode = Status.OkUpdate.ToString(); returnCode = userManager.Status; } userManager.StatusMessage = userManager.GetStateMessage(returnCode); // 更新员工信息 if (entity != null) { if (entity.IsStaff == 0) { //BaseStaffManager staffManager = new BaseStaffManager(dbHelper, result); //string staffId = staffManager.GetIdByUserId(entity.Id); //if (!string.IsNullOrEmpty(staffId)) //{ // BaseStaffEntity staffEntity = staffManager.GetEntity(staffId); // staffEntity.Code = entity.Code; // staffEntity.Birthday = entity.Birthday; // staffEntity.Gender = entity.Gender; // staffEntity.UserName = entity.UserName; // staffEntity.RealName = entity.RealName; // staffEntity.QQ = entity.QQ; // staffEntity.Mobile = entity.Mobile; // staffEntity.Telephone = entity.Telephone; // staffEntity.Email = entity.Email; // staffEntity.CompanyId = entity.CompanyId; // staffEntity.SubCompanyId = entity.SubCompanyId; // staffEntity.DepartmentId = entity.DepartmentId; // staffEntity.WorkgroupId = entity.WorkgroupId; // staffManager.Update(staffEntity); //} } } returnCode = userManager.Status; returnMessage = userManager.StatusMessage; }); status = returnCode; statusMessage = returnMessage; return(result); }
/// <summary> /// 检查用户的登录许可信息 /// </summary> /// <param name="userEntity">用户实体</param> /// <param name="userLogonEntity">用户登录实体</param> /// <returns>用户登录信息</returns> public static UserLogonResult CheckUser(BaseUserEntity userEntity, BaseUserLogonEntity userLogonEntity) { var result = new UserLogonResult(); //int errorMark = 0; // 05. 是否允许登录,是否离职是否正确 if (!string.IsNullOrEmpty(userEntity.AuditStatus) && userEntity.AuditStatus.EndsWith(AuditStatus.WaitForAudit.ToString())) { result.Status = Status.WaitForAudit; result.StatusCode = AuditStatus.WaitForAudit.ToString(); result.StatusMessage = AuditStatus.WaitForAudit.ToDescription(); //errorMark = 1; return(result); } // 用户是否有效的 if (userEntity.Enabled == 0) { result.Status = Status.LogonDeny; result.StatusCode = Status.LogonDeny.ToString(); result.StatusMessage = Status.LogonDeny.ToDescription(); //errorMark = 2; return(result); } // 用户是否有效的 if (userEntity.Enabled == -1) { result.Status = Status.UserNotActive; result.StatusCode = Status.UserNotActive.ToString(); result.StatusMessage = Status.UserNotActive.ToDescription(); //errorMark = 3; return(result); } // 01: 系统是否采用了在线用户的限制, 这里是登录到哪个表里去? //errorMark = 6; // 2015-12-08 吉日嘎拉 if (userLogonEntity == null) { result.Status = Status.MissingData; result.StatusCode = Status.MissingData.ToString(); result.StatusMessage = Status.MissingData.ToDescription(); return(result); } // 06. 允许登录时间是否有限制 // 2015-05-28 jirigala 子系统的用户是否有效的 //errorMark = 7; if (userLogonEntity.Enabled == 0) { //errorMark = 8; result.Status = Status.LogonDeny; result.StatusCode = Status.LogonDeny.ToString(); result.StatusMessage = Status.LogonDeny.ToDescription(); return(result); } //errorMark = 11; if (userLogonEntity.AllowEndTime != null) { //errorMark = 12; //userLogonEntity.AllowEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userLogonEntity.AllowEndTime.Value.Hour, userLogonEntity.AllowEndTime.Value.Minute, userLogonEntity.AllowEndTime.Value.Second); } //errorMark = 13; if (userLogonEntity.AllowStartTime != null) { //errorMark = 14; //userLogonEntity.AllowStartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, userLogonEntity.AllowStartTime.Value.Hour, userLogonEntity.AllowStartTime.Value.Minute, userLogonEntity.AllowStartTime.Value.Second); //errorMark = 15; if (DateTime.Now < userLogonEntity.AllowStartTime) { result.Status = Status.ServiceNotStart; result.StatusCode = Status.ServiceNotStart.ToString(); result.StatusMessage = Status.ServiceNotStart.ToDescription(); //errorMark = 17; return(result); } } //errorMark = 18; if (userLogonEntity.AllowEndTime != null) { //errorMark = 19; if (DateTime.Now > userLogonEntity.AllowEndTime) { result.Status = Status.ServiceExpired; result.StatusCode = Status.ServiceExpired.ToString(); result.StatusMessage = Status.ServiceExpired.ToDescription(); //errorMark = 20; return(result); } } // 07. 锁定日期是否有限制 //errorMark = 21; if (userLogonEntity.LockStartTime != null) { //errorMark = 22; if (DateTime.Now > userLogonEntity.LockStartTime) { //errorMark = 23; if (userLogonEntity.LockEndTime == null || DateTime.Now < userLogonEntity.LockEndTime) { result.Status = Status.UserLocked; result.StatusCode = Status.UserLocked.ToString(); result.StatusMessage = Status.UserLocked.ToDescription(); //errorMark = 24; return(result); } } } //errorMark = 25; if (userLogonEntity.LockEndTime != null) { //errorMark = 26; if (DateTime.Now < userLogonEntity.LockEndTime) { //errorMark = 27; result.Status = Status.UserLocked; result.StatusCode = Status.UserLocked.ToString(); result.StatusMessage = Status.UserLocked.ToDescription(); //errorMark = 28; return(result); } } result.Status = Status.Ok; result.StatusCode = Status.Ok.ToString(); result.StatusMessage = Status.Ok.ToDescription(); return(result); }