Exemple #1
0
        /// <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>
        /// 导入员工
        /// </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);
        }
Exemple #3
0
        /// <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);
        }