Ejemplo n.º 1
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dbHelper">数据库连接</param>
        /// <param name="userInfo">用户信息</param>
        /// <param name="userEntity">用户实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string AddUser(IDbHelper dbHelper, BaseUserInfo userInfo, BaseUserEntity userEntity, out string statusCode, out string statusMessage)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            BaseSystemInfo.IsAuthorized(userInfo);
            #endif

            string          returnValue = string.Empty;
            BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
            // 若是系统需要用加密的密码,这里需要加密密码。
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                userEntity.UserPassword = userManager.EncryptUserPassword(userEntity.UserPassword);
                // 安全通讯密码、交易密码也生成好
                userEntity.CommunicationPassword = userManager.EncryptUserPassword(userEntity.CommunicationPassword);
            }
            returnValue   = userManager.Add(userEntity, out statusCode);
            statusMessage = userManager.GetStateMessage(statusCode);
            // 自己不用给自己发提示信息,这个提示信息是为了提高工作效率的,还是需要审核通过的,否则垃圾信息太多了
            if (userEntity.Enabled == 0 && statusCode.Equals(StatusCode.OKAdd.ToString()))
            {
                // 不是系统管理员添加
                if (!userInfo.IsAdministrator)
                {
                    // 给超级管理员群组发信息
                    BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo);
                    string[]        roleIds     = roleManager.GetIds(new KeyValuePair <string, object>(BaseRoleEntity.FieldCode, "Administrators"));
                    string[]        userIds     = userManager.GetIds(new KeyValuePair <string, object>(BaseUserEntity.FieldCode, "Administrator"));
                    // 发送请求审核的信息
                    BaseMessageEntity messageEntity = new BaseMessageEntity();
                    messageEntity.FunctionCode = MessageFunction.WaitForAudit.ToString();

                    // Pcsky 2012.05.04 显示申请的用户名
                    messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.UserName + AppMessage.UserService_Check;
                    //messageEntity.Contents = userInfo.RealName + "(" + userInfo.IPAddress + ")" + AppMessage.UserService_Application + userEntity.RealName + AppMessage.UserService_Check;

                    BaseMessageManager messageManager = new BaseMessageManager(dbHelper, userInfo);
                    messageManager.BatchSend(userIds, null, roleIds, messageEntity, false);
                }
            }
            return(returnValue);
        }
        /// <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>
        /// 增加用户账号
        /// </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);
        }