/// <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);
        }
        /// <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);
        }
Пример #3
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);
        }