public int ImportStaff(System.Data.IDataReader dataReader, BaseStaffManager staffManager, BaseUserExpressManager sTAFF_EXPRESSManager, BaseUserManager userManager, BaseUserLogOnManager userLogOnManager)
        {
            int result = 0;

            /*
             * BaseStaffEntity staffEntity = staffManager.GetObject(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.UpdateObject(staffEntity);
             * if (result == 0)
             * {
             *  staffManager.AddObject(staffEntity);
             * }
             */

            /*
             * BaseUserExpressEntity sTAFF_EXPRESSEntity = sTAFF_EXPRESSManager.GetObject(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);
             * }
             */

            BaseUserEntity userEntity = new BaseUserEntity();

            userEntity.Id = dataReader["ID"].ToString();

            userEntity.UserFrom    = "PDA";
            userEntity.Code        = dataReader["EMPLOYEE_CODE"].ToString();
            userEntity.UserName    = dataReader["EMPLOYEE_NAME"].ToString();
            userEntity.RealName    = dataReader["REAL_NAME"].ToString();
            userEntity.Description = dataReader["PHONE"].ToString();
            userEntity.CompanyName = dataReader["OWNER_SITE"].ToString();
            if (string.IsNullOrEmpty(userEntity.CompanyId))
            {
                userEntity.CompanyId = BaseOrganizeManager.GetObjectByNameByCache(userEntity.CompanyName).Id.ToString();
                if (string.IsNullOrEmpty(userEntity.CompanyId))
                {
                    System.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.ModifiedOn.HasValue)
            {
                userEntity.ModifiedOn = DateTime.Parse(dataReader["UPDATETIME"].ToString());
            }
            else
            {
                if (userEntity.ModifiedOn.Value < DateTime.Parse(dataReader["UPDATETIME"].ToString()))
                {
                    userEntity.ModifiedOn = DateTime.Parse(dataReader["UPDATETIME"].ToString());
                }
            }
            // 修改日期需要同步
            // result = userManager.UpdateObject(userEntity);
            if (result == 0)
            {
                userManager.AddObject(userEntity);

                BaseUserContactEntity userContactEntity = new BaseUserContactEntity();
                userContactEntity.Id        = dataReader["ID"].ToString();
                userContactEntity.Telephone = dataReader["PHONE"].ToString();
                new BaseUserContactManager().AddObject(userContactEntity);

                BaseUserLogOnEntity userLogOnEntity = new BaseUserLogOnEntity();
                userLogOnEntity.Id           = dataReader["ID"].ToString();
                userLogOnEntity.UserPassword = dataReader["BAR_PASSWORD"].ToString();
                userLogOnManager.AddObject(userLogOnEntity);
            }

            // 处理角色

            /*
             * string roleName = dataReader["EMPLOYEE_TYPE"].ToString();
             * // 看是否在这个角色里,若没有增加上去。
             * userManager.AddToRole("PDA", userEntity.Id, roleName);
             *
             * // 添加用户密码表
             * BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(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.ChangePasswordDate = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString());
             *  //}
             *  userLogOnManager.AddObject(userLogOnEntity);
             * }
             * else
             * {
             *  userLogOnEntity.Id = userEntity.Id;
             *  userLogOnEntity.UserPassword = dataReader["BAR_PASSWORD"].ToString();
             *  //userLogOnEntity.Salt = dataReader["SALT"].ToString();
             *  //if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString()))
             *  //{
             *  //    userLogOnEntity.ChangePasswordDate = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString());
             *  //}
             *  result = userLogOnManager.UpdateObject(userLogOnEntity);
             * }
             */

            return(result);
        }
        /// <summary>
        /// 增加用户账号
        /// 传入dbhelper 方法调用使用事务 避免部分同步成功
        /// </summary>
        /// <param name="userEntity"></param>
        /// <param name="userContact"></param>
        /// <param name="userCenterDbHelper"></param>
        /// <param name="k8DbHelper"></param>
        /// <returns></returns>
        public bool AddUser(BaseUserEntity userEntity, BaseUserContactEntity userContact, IDbHelper userCenterDbHelper, IDbHelper k8DbHelper)
        {
            //1、先往中天里添加账号
            BaseUserManager userManager = new BaseUserManager(userCenterDbHelper);

            userEntity.UserFrom     = "Security";
            userEntity.CreateBy     = Utilities.UserInfo.RealName;
            userEntity.CreateUserId = Utilities.UserInfo.Id;
            bool identity = false;

            if (string.IsNullOrEmpty(userEntity.Id))
            {
                identity = true;
            }
            userEntity.Id = userManager.Add(userEntity, identity, true);
            //添加用户密码表
            BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(userCenterDbHelper);
            BaseUserLogOnEntity  userLogOnEntity  = userLogOnManager.GetObject(userEntity.Id);

            userLogOnEntity    = new BaseUserLogOnEntity();
            userLogOnEntity.Id = userEntity.Id;
            //是否验证邦定mac地址,默认绑定
            userLogOnEntity.CheckIPAddress = 1;
            //产生盐
            var salt = BaseRandom.GetRandomString(20);

            userLogOnEntity.Salt         = salt;
            userLogOnEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword, salt);
            //是否检查机器码MAC地址
            userLogOnManager.AddObject(userLogOnEntity);
            //添加用户的联系方式
            BaseUserContactManager userContactManager = new BaseUserContactManager(userCenterDbHelper);

            userContact.MobileValiated = 1;
            userContactManager.AddObject(userContact);

            //2、再往K8里加用户
            TAB_USERManager tabUserManager = new TAB_USERManager(k8DbHelper);
            TAB_USEREntity  tabUserEntity  = new TAB_USEREntity();

            tabUserEntity.OWNER_SITE        = userEntity.CompanyName;
            tabUserEntity.DEPT_NAME         = userEntity.DepartmentName;
            tabUserEntity.USER_NAME         = userEntity.UserName.ToLower();
            tabUserEntity.EMPLOYEE_CODE     = userEntity.Code;
            tabUserEntity.EMPLOYEE_NAME     = userEntity.RealName;
            tabUserEntity.REAL_NAME         = userEntity.RealName;
            tabUserEntity.ONLY_USER_NAME    = userEntity.NickName.ToLower();
            tabUserEntity.ID_CARD           = userEntity.IDCard;
            tabUserEntity.MOBILE            = userContact.Mobile;
            tabUserEntity.CREATE_SITE       = Utilities.UserInfo.CompanyName;
            tabUserEntity.CREATE_USER       = Utilities.UserInfo.RealName;
            tabUserEntity.CREATE_DATE       = DateTime.Now;
            tabUserEntity.BL_LOCK_FLAG      = 1;
            tabUserEntity.BL_TYPE           = 0;
            tabUserEntity.BL_CHECK_COMPUTER = 1;
            tabUserEntity.BL_CHECK_NAME     = 1;
            tabUserEntity.ID        = decimal.Parse(userEntity.Id);
            tabUserEntity.USER_DATE = DateTime.Now.AddYears(3);
            tabUserManager.Add(tabUserEntity, false, true);
            //更新密码和盐
            var sql = string.Format(" UPDATE TAB_USER SET USER_PASSWORD=NULL,USER_PASSWD='{0}',SALT ='{1}',  CHANGEPASSWORDDATE=to_date('{2}','yyyy-mm-dd-hh24:mi:ss')  WHERE ID = '{3}'",
                                    userEntity.UserPassword, salt, DateTime.Now, tabUserEntity.ID);

            tabUserManager.ExecuteNonQuery(sql);

            //3、新增账号的时候默认增加新员工的权限为网点员工
            var roleMenus = GetMenusByUserCode(k8DbHelper, "网点员工", "", "上海");
            TAB_USERPOPEDOMManager userMenuManager = new TAB_USERPOPEDOMManager(k8DbHelper);

            foreach (var roleMenu in roleMenus)
            {
                TAB_USERPOPEDOMEntity userPOPEDOM = new TAB_USERPOPEDOMEntity();
                userPOPEDOM.BL_INSERT  = roleMenu.BL_INSERT;
                userPOPEDOM.BL_UPDATE  = roleMenu.BL_UPDATE;
                userPOPEDOM.BL_DELETE  = roleMenu.BL_DELETE;
                userPOPEDOM.USER_NAME  = tabUserEntity.USER_NAME;
                userPOPEDOM.OWNER_SITE = tabUserEntity.OWNER_SITE;
                userPOPEDOM.MENU_GUID  = roleMenu.MENU_GUID;
                userMenuManager.Add(userPOPEDOM);
            }
            return(true);
        }
        /// <summary>
        /// 更新K8员工后,同步到中天baseuser表
        /// 传入dbhelper 方法调用使用事务 避免部分同步成功
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="userCenterDbHelper"></param>
        public void AfterUpdateEmployee(TAB_EMPLOYEEEntity entity, IDbHelper userCenterDbHelper)
        {
            int            count      = 0;
            BaseUserEntity userEntity = new BaseUserEntity();

            userEntity.Id           = entity.ID.ToString();
            userEntity.UserFrom     = "PDA";
            userEntity.UserPassword = entity.BAR_PASSWORD;
            userEntity.Code         = entity.EMPLOYEE_CODE;
            userEntity.UserName     = entity.EMPLOYEE_NAME;
            userEntity.RealName     = entity.EMPLOYEE_NAME;
            userEntity.Description  = entity.PHONE;
            userEntity.CompanyName  = entity.OWNER_SITE;
            // 1、更新baseuser中的所属网点
            if (string.IsNullOrEmpty(userEntity.CompanyId))
            {
                BaseOrganizeEntity organizeEntity = new BaseOrganizeManager(userCenterDbHelper).GetObjectByName(userEntity.CompanyName);
                if (organizeEntity != null)
                {
                    userEntity.CompanyId = organizeEntity.Id.ToString();
                }
            }
            userEntity.DepartmentName = entity.DEPT_NAME;
            userEntity.WorkgroupName  = entity.GROUP_NAME;
            userEntity.HomeAddress    = entity.ADDRESS;
            userEntity.IDCard         = entity.ID_CARD;

            // 2、员工操作类型,按签名处理
            userEntity.Signature  = entity.EMPLOYEE_TYPE;
            userEntity.SortCode   = int.Parse(entity.ID.ToString());
            userEntity.ModifiedOn = entity.UPDATETIME;
            BaseUserManager userManager = new BaseUserManager(userCenterDbHelper, Utilities.UserInfo);

            // if (!userManager.Exists(userEntity.Id))
            count = userManager.UpdateObject(userEntity);
            if (count == 0)
            {
                userManager.AddObject(userEntity);
            }
            // 3、如果有电话,同步到baseusercontact中
            BaseUserContactEntity userContactEntity = new BaseUserContactEntity();

            userContactEntity.Id        = entity.ID.ToString();
            userContactEntity.Telephone = entity.PHONE;
            BaseUserContactManager userContactManager = new DotNet.Business.BaseUserContactManager(userCenterDbHelper, Utilities.UserInfo);

            count = userContactManager.UpdateObject(userContactEntity);
            if (count == 0)
            {
                userContactManager.AddObject(userContactEntity);
            }
            // 4、新增员工时,同步baseuser员工的密码
            BaseUserLogOnEntity userLogOnEntity = new BaseUserLogOnEntity();

            userLogOnEntity.Id           = entity.ID.ToString();
            userLogOnEntity.UserPassword = entity.BAR_PASSWORD;
            BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(userCenterDbHelper, Utilities.UserInfo);

            count = userLogOnManager.UpdateObject(userLogOnEntity);
            if (count == 0)
            {
                userLogOnManager.AddObject(userLogOnEntity);
            }
            // 5、中转附加费和派件附加费,再确认
            BaseUserExpressManager userExpressManager = new BaseUserExpressManager(userCenterDbHelper, Utilities.UserInfo);
            BaseUserExpressEntity  userExpressEntity  = new BaseUserExpressEntity();

            userExpressEntity.Id = entity.ID;
            userExpressEntity.DISPATCH_ADD_FEE = entity.DISPATCH__ADD_FEE;
            userExpressEntity.TRANSFER_ADD_FEE = entity.TRANSFER_ADD_FEE;
            userExpressEntity.OWNER_RANGE      = entity.OWNER_RANGE;
            count = userExpressManager.UpdateObject(userExpressEntity);
            if (count == 0)
            {
                userExpressManager.Add(userExpressEntity, false);
            }
        }
Example #4
0
        /// <summary>
        /// 设置密码
        /// </summary>
        /// <param name="userId">被设置的用户主键</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="unlock">解除锁定</param>
        /// <param name="autoAdd">数据缺少自动补充登录信息</param>
        /// <returns>影响行数</returns>
        public virtual int SetPassword(string userId, string newPassword, bool?unlock = null, bool?autoAdd = null, bool modifyRecord = true)
        {
            int result = 0;

            // 密码强度检查

            /*
             * if (BaseSystemInfo.CheckPasswordStrength)
             * {
             *  if (password.Length == 0)
             *  {
             *      this.StatusCode = StatusCode.PasswordCanNotBeNull.ToString();
             *      return result;
             *  }
             * }
             */
            string encryptPassword = newPassword;
            string salt            = string.Empty;

            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                salt            = BaseRandom.GetRandomString(20);
                encryptPassword = this.EncryptUserPassword(newPassword, salt);
            }
            // 设置密码字段
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldUserPassword, encryptPassword));
            // 需要重新登录才可以,防止正在被人黑中,阻止已经在线上的人
            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.FieldChangePasswordDate, DateTime.Now));
            if (unlock.HasValue && unlock.Value == true)
            {
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldEnabled, 1));
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldLockStartDate, null));
                parameters.Add(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldLockEndDate, null));
            }
            BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager(this.DbHelper, this.UserInfo);

            result = userLogOnManager.SetProperty(new KeyValuePair <string, object>(BaseUserLogOnEntity.FieldId, userId), parameters);
            if (result == 0 && autoAdd.HasValue && autoAdd.Value == true)
            {
                BaseUserLogOnEntity userLogOnEntity = new BaseUserLogOnEntity();
                userLogOnEntity.Id = userId;
                userLogOnEntity.ChangePasswordDate = DateTime.Now;
                userLogOnEntity.UserPassword       = encryptPassword;
                userLogOnEntity.Salt    = salt;
                userLogOnEntity.Enabled = 1;
                userLogOnManager.AddObject(userLogOnEntity);
                result = 1;
            }

            // 2015-12-09 吉日嘎拉 增加日志功能、谁什么时候设置了谁的密码?
            if (modifyRecord)
            {
                var record = new BaseModifyRecordEntity();
                record.TableCode         = BaseUserLogOnEntity.TableName.ToUpper();
                record.TableDescription  = "用户登录信息表";
                record.ColumnCode        = BaseUserLogOnEntity.FieldUserPassword;
                record.ColumnDescription = "用户密码";
                record.RecordKey         = userId;
                record.NewValue          = "设置密码";
                // record.OldValue = "";
                if (this.UserInfo != null)
                {
                    record.IPAddress    = this.UserInfo.IPAddress;
                    record.CreateUserId = this.UserInfo.Id;
                    record.CreateOn     = DateTime.Now;
                }
                BaseModifyRecordManager modifyRecordManager = new Business.BaseModifyRecordManager(this.UserInfo, BaseUserEntity.TableName + "_Log");
                modifyRecordManager.Add(record, true, false);
            }

            if (result == 1)
            {
                this.StatusCode = Status.SetPasswordOK.ToString();
                // 调用扩展
                if (BaseSystemInfo.OnInternet && BaseSystemInfo.ServerEncryptPassword)
                {
                    // AfterSetPassword(userId, salt, password);
                }
            }
            else
            {
                // 数据可能被删除
                this.StatusCode = Status.ErrorDeleted.ToString();
            }

            return(result);
        }
        /// <summary>
        /// 增加用户账号
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool AddUser(TAB_USEREntity user)
        {
            //1、先往中天里添加账号
            BaseUserEntity       userEntity       = new BaseUserEntity();
            BaseUserManager      userManager      = new BaseUserManager();
            BaseUserLogOnManager userLogOnManager = new BaseUserLogOnManager();

            userEntity.UserFrom    = "K8";
            userEntity.UserName    = user.USER_NAME;
            userEntity.Code        = user.EMPLOYEE_CODE;
            userEntity.RealName    = user.REAL_NAME;
            userEntity.CompanyName = user.OWNER_SITE;
            var organize = new BaseOrganizeManager().GetObjectByName(user.OWNER_SITE);

            if (organize != null)
            {
                userEntity.CompanyId = organize.Id.ToString();
            }
            userEntity.Description       = user.REMARK;
            userEntity.DeletionStateCode = 0;
            userEntity.DepartmentName    = user.DEPT_NAME;
            userEntity.Enabled           = int.Parse(user.BL_LOCK_FLAG.ToString());
            bool identity = false;

            if (!string.IsNullOrEmpty(userEntity.Id))
            {
                identity = true;
            }
            userEntity.Id = userManager.Add(userEntity, identity, true);

            //添加用户密码表
            BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id);

            userLogOnEntity    = new BaseUserLogOnEntity();
            userLogOnEntity.Id = userEntity.Id;
            //邦定mac地址
            userLogOnEntity.CheckIPAddress = 1;
            var salt = BaseRandom.GetRandomString(20);

            userLogOnEntity.Salt         = salt;
            userLogOnEntity.UserPassword = userManager.EncryptUserPassword(user.USER_PASSWD, salt);

            //是否检查机器码 MAC地址
            int checkIPAddress = 1;

            int.TryParse(user.BL_CHECK_COMPUTER.ToString(), out checkIPAddress);
            userLogOnEntity.CheckIPAddress = checkIPAddress;
            userLogOnManager.AddObject(userLogOnEntity);

            //用户的联系方式
            BaseUserContactManager userContactManager = new BaseUserContactManager();
            BaseUserContactEntity  userContactEntity  = new BaseUserContactEntity();

            userContactEntity.Id = userEntity.Id;
            if (!string.IsNullOrEmpty(user.MOBILE))
            {
                userContactEntity.Mobile = user.MOBILE;
            }
            userContactManager.AddObject(userContactEntity);

            //2、再往K8里加用户
            TAB_USERManager        tabUserManager  = new TAB_USERManager();
            TAB_USERPOPEDOMManager userMenuManager = new TAB_USERPOPEDOMManager();

            user.CREATE_SITE = Utilities.UserInfo.CompanyName;
            user.CREATE_USER = Utilities.UserInfo.RealName;
            user.CREATE_DATE = DateTime.Now;
            user.USER_NAME   = user.USER_NAME.Trim();
            user.ID          = decimal.Parse(userEntity.Id);
            tabUserManager.Add(user, false, true);
            var sql = string.Format(" UPDATE TAB_USER SET USER_PASSWORD=NULL,USER_PASSWD='{0}',SALT ='{1}',  CHANGEPASSWORDDATE=to_date('{2}','yyyy-mm-dd-hh24:mi:ss')  WHERE ID = '{3}'",
                                    userEntity.UserPassword, salt, DateTime.Now, user.ID);

            tabUserManager.ExecuteNonQuery(sql);

            //3、新增账号的时候默认增加新员工的权限为网点员工
            var roleMenus = GetMenusByUserCode("网点员工", "", "上海");

            foreach (var roleMenu in roleMenus)
            {
                TAB_USERPOPEDOMEntity userPOPEDOM = new TAB_USERPOPEDOMEntity();
                userPOPEDOM.BL_INSERT  = roleMenu.BL_INSERT;
                userPOPEDOM.BL_UPDATE  = roleMenu.BL_UPDATE;
                userPOPEDOM.BL_DELETE  = roleMenu.BL_DELETE;
                userPOPEDOM.USER_NAME  = user.USER_NAME;
                userPOPEDOM.OWNER_SITE = user.OWNER_SITE;
                userPOPEDOM.MENU_GUID  = roleMenu.MENU_GUID;
                userMenuManager.Add(userPOPEDOM);
            }
            return(true);
        }
Example #6
0
        public int ImportUser(System.Data.IDataReader dataReader, BaseOrganizeManager organizeManager, BaseUserLogOnManager userLogOnManager, BaseUserContactManager userContactManager)
        {
            int            result     = 0;
            BaseUserEntity userEntity = this.GetObject(dataReader["ID"].ToString());

            if (userEntity == null)
            {
                userEntity    = new BaseUserEntity();
                userEntity.Id = dataReader["ID"].ToString();
            }
            userEntity.Id       = dataReader["ID"].ToString();
            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.DeletionStateCode = 0;
            if (string.IsNullOrEmpty(userEntity.CompanyId))
            {
                userEntity.CompanyId = organizeManager.GetProperty(new KeyValuePair <string, object>(BaseOrganizeEntity.FieldFullName, userEntity.CompanyName), BaseOrganizeEntity.FieldId);
                if (string.IsNullOrEmpty(userEntity.CompanyId))
                {
                    System.Console.WriteLine("无CompanyId " + userEntity.Id + ":" + userEntity.UserName + ":" + userEntity.RealName);
                    return(0);
                }
            }
            // 不是内部组织机构的才进行调整
            if (string.IsNullOrEmpty(userEntity.DepartmentId))
            {
                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());
            System.Console.WriteLine("ImportK8User:"******":" + userEntity.RealName);
            // 02:可以把读取到的数据能写入到用户中心的。
            result = this.UpdateObject(userEntity);
            if (result == 0)
            {
                this.AddObject(userEntity);
            }
            // 添加用户密码表
            BaseUserLogOnEntity userLogOnEntity = userLogOnManager.GetObject(userEntity.Id);

            if (userLogOnEntity == null)
            {
                userLogOnEntity    = new BaseUserLogOnEntity();
                userLogOnEntity.Id = userEntity.Id;
                // 邦定mac地址
                userLogOnEntity.CheckIPAddress = 1;
                userLogOnEntity.UserPassword   = dataReader["USER_PASSWD"].ToString();
                userLogOnEntity.Salt           = dataReader["SALT"].ToString();
                // 是否检查机器码 MAC地址
                int checkIPAddress = 1;
                int.TryParse(dataReader["BL_CHECK_COMPUTER"].ToString(), out checkIPAddress);
                userLogOnEntity.CheckIPAddress = checkIPAddress;
                if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString()))
                {
                    userLogOnEntity.ChangePasswordDate = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString());
                }
                userLogOnManager.AddObject(userLogOnEntity);
            }
            else
            {
                userLogOnEntity.Id           = userEntity.Id;
                userLogOnEntity.UserPassword = dataReader["USER_PASSWD"].ToString();
                userLogOnEntity.Salt         = dataReader["SALT"].ToString();
                if (!string.IsNullOrEmpty(dataReader["CHANGEPASSWORDDATE"].ToString()))
                {
                    userLogOnEntity.ChangePasswordDate = DateTime.Parse(dataReader["CHANGEPASSWORDDATE"].ToString());
                }
                result = userLogOnManager.UpdateObject(userLogOnEntity);
            }
            // 用户的联系方式
            BaseUserContactEntity userContactEntity = userContactManager.GetObject(userEntity.Id);

            if (userContactEntity == null)
            {
                userContactEntity        = new BaseUserContactEntity();
                userContactEntity.Id     = userEntity.Id;
                userContactEntity.QQ     = dataReader["QQ"].ToString();
                userContactEntity.Mobile = dataReader["Mobile"].ToString();
                userContactEntity.Email  = dataReader["Email"].ToString();
                userContactManager.AddObject(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.UpdateObject(userContactEntity);
            }
            return(result);
        }