Exemplo n.º 1
0
        //BE同步至RTX
        public void AddDeptToRTX(DataRow currentOrg, DataRow parentOrg, DataRow[] children)
        {
            string logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";

            if (currentOrg == null)
            {
                return;
            }

            absoluteFullDpetNameList.Clear();
            GetAbsoluteFullDpetName(currentOrg);
            var absoluteFullDpetName = string.Join("\\", absoluteFullDpetNameList);
            var currentOrgName       = currentOrg["Name"] == null ? "" : currentOrg["Name"].ToString();

            if (!deptManager.IsDeptExist(absoluteFullDpetName + "\\" + currentOrgName))
            {
                if (parentOrg == null)
                {
                    try
                    {
                        deptManager.AddDept(currentOrgName, "");
                    }
                    catch (Exception exp)
                    {
                        logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                        logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "同步" + currentOrgName + "部门信息时失败。"
                                               , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                        SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);
                        return;
                    }
                }
                else
                {
                    try
                    {
                        deptManager.AddDept(currentOrgName, absoluteFullDpetName);
                    }
                    catch (Exception exp)
                    {
                        logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                        logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "同步" + currentOrgName + "部门信息时失败。"
                                               , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                        SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);
                        return;
                    }
                }
            }
            if (children != null && children.Count() > 0)
            {
                foreach (DataRow child in children)
                {
                    var Id       = child["ID"].ToString();
                    var grandsen = orgDt.Select(" ParentID='" + Id + "'");
                    AddDeptToRTX(child, currentOrg, grandsen);
                }
            }
        }
Exemplo n.º 2
0
        public void StartSynchUserInfo()
        {
            string logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";

            userManager = RootObj.UserManager;
            if (userManager == null)
            {
                return;
            }
            deptManager = RootObj.DeptManager;
            if (deptManager == null)
            {
                return;
            }
            var userDt = baseSqlHelper.ExecuteDataTable(" select * from S_A_User ");
            //  var userList = baseEntites.S_A_User.ToList();
            //获取人员和部门的关系信息
            string    sql             = @" select UserID,OrgID,Name as DeptName,ParentID from S_A__OrgUser
left join S_A_Org on S_A__OrgUser.OrgID = S_A_Org.ID ";
            DataTable userOrgInfoDt   = baseSqlHelper.ExecuteDataTable(sql);
            var       userOrgInfoRows = userOrgInfoDt.Rows;
            var       userRows        = userDt.Rows;

            foreach (DataRow userItem in userRows)
            {
                var systemName = userItem["Code"] == null ? "" : userItem["Code"].ToString();
                systemName = systemName.TrimStart(' ').TrimEnd(' ');
                var     isDeleted    = userItem["IsDeleted"] == null ? "" : userItem["IsDeleted"].ToString();
                var     deptName     = userItem["DeptName"] == null ? "" : userItem["DeptName"].ToString();
                var     orgID        = userItem["DeptID"] == null ? "" : userItem["DeptID"].ToString();
                DataRow orgInfo      = null;
                var     orgInfo_Temp = orgDt.Select(" ID='" + orgID + "'");
                if (orgInfo_Temp != null && orgInfo_Temp.Count() > 0)
                {
                    orgInfo = orgInfo_Temp[0];
                }
                absoluteFullDpetNameList.Clear();
                if (orgInfo != null)
                {
                    GetAbsoluteFullDpetName(orgInfo);
                    var absoluteFullDpetName = string.Join("\\", absoluteFullDpetNameList);
                    deptName = absoluteFullDpetName + "\\" + deptName;
                }
                if (isDeleted == "1")
                {
                    //删除用户信息
                    if (userManager.IsUserExist(systemName))
                    {
                        try
                        {
                            userManager.DeleteUser(systemName);
                        }
                        catch (Exception exp)
                        {
                            logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                            logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "删除用户" + systemName + "失败"
                                                   , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                            SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);

                            continue;
                        }
                    }
                }
                else
                {
                    if (!userManager.IsUserExist(systemName))
                    {
                        try
                        {
                            userManager.AddUser(systemName, 0);
                        }
                        catch (Exception exp)
                        {
                            logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                            logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "添加用户" + systemName + "失败"
                                                   , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                            SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);

                            continue;
                        }
                        if (!string.IsNullOrEmpty(deptName) && deptManager.IsDeptExist(deptName))
                        {
                            try
                            {
                                deptManager.AddUserToDept(systemName, "", deptName, false);
                            }
                            catch (Exception exp)
                            {
                                logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";

                                logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "添加用户部门之间的关联关系失败,用户(" + systemName + "),部门(" + deptName + ")"
                                                       , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                                SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);

                                continue;
                            }
                        }
                    }
                    else
                    {
                        //设置用户部门信息
                        string      UserDeptInfo = deptManager.GetUserDepts(systemName);
                        XmlDocument xmlDoc       = new XmlDocument();
                        xmlDoc.LoadXml(BeforeLoadXML(UserDeptInfo));
                        XmlElement  xmlEle   = xmlDoc.DocumentElement;
                        XmlNodeList nodelist = xmlEle.SelectNodes("//Department");
                        if (nodelist.Count > 0)
                        {
                            //删除RTX中人员的部门信息
                            foreach (XmlNode node in nodelist)
                            {
                                string name = ((XmlElement)node).GetAttribute("Name");
                                try
                                {
                                    deptManager.DelUserFromDept(systemName, name);
                                }
                                catch (Exception exp)
                                {
                                    logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                                    logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "删除用户部门之间的关联关系失败,用户(" + systemName + "),部门(" + name + ")"
                                                           , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                                    SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);

                                    continue;
                                }
                            }
                        }
                        var userId = userItem["ID"];
                        var userOrgInfoRowsOfSingleUser = userOrgInfoDt.Select(" UserID='" + userId + "'");
                        foreach (DataRow row in userOrgInfoRowsOfSingleUser)
                        {
                            deptName = row["DeptName"] == null ? "" : row["DeptName"].ToString();
                            absoluteFullDpetNameList.Clear();
                            if (orgInfo != null)
                            {
                                GetAbsoluteFullDpetName(row);
                                var absoluteFullDpetName = string.Join("\\", absoluteFullDpetNameList);
                                if (!string.IsNullOrEmpty(absoluteFullDpetName))
                                {
                                    deptName = absoluteFullDpetName + "\\" + deptName;
                                }
                            }
                            if (!string.IsNullOrEmpty(deptName) && deptManager.IsDeptExist(deptName))
                            {
                                try
                                {
                                    deptManager.AddUserToDept(systemName, "", deptName, false);
                                }
                                catch (Exception exp)
                                {
                                    logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                                    logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "添加用户部门之间的关联关系失败,用户(" + systemName + "),部门(" + deptName + ")"
                                                           , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                                    SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);
                                    continue;
                                }
                            }
                        }
                    }
                    //设置用户的基本信息(用户姓名,用户性别,用户手机,用户电子邮件,用户电话,用户认证类型)
                    string Name        = userItem["Name"] == null ? "" : userItem["Name"].ToString();
                    string Sex         = userItem["Sex"] == null ? "" : userItem["Sex"].ToString();
                    string MobilePhone = userItem["MobilePhone"] == null ? "" : userItem["MobilePhone"].ToString();
                    string Email       = userItem["Email"] == null ? "" : userItem["Email"].ToString();
                    string Phone       = userItem["Phone"] == null ? "" : userItem["Phone"].ToString();
                    try
                    {
                        userManager.SetUserBasicInfo(systemName, Name, GetSex(Sex), MobilePhone, Email, Phone, 0);
                    }
                    catch (Exception exp)
                    {
                        logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                        logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "设置用户基本信息失败,用户(" + systemName + ")"
                                               , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                        SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);
                        continue;
                    }
                    //设置用户的详细信息(用户生日,用户血型,用户星座,用户毕业院校,用户主页,用户传真,用户地址,用户邮编,用户所在国家, 用户所在省份, 用户所在城市,用户所在街道,用户职务,用户权值 (用于排序) )
                    string strSortIndex = userItem["SortIndex"] == null || userItem["SortIndex"].ToString() == "" ? "0" : userItem["SortIndex"].ToString();
                    int    sortIndex    = Convert.ToInt32(strSortIndex);
                    try
                    {
                        userManager.SetUserDetailInfo(systemName, -1, -1, -1, "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", "RTX_NULL", sortIndex);
                    }
                    catch (Exception exp)
                    {
                        logSql = @" insert into S_D_ModifyLog (ID,ConnName,TableName,ModifyMode,EntityKey,CurrentValue,OriginalValue
                               ,ModifyUserID,ModifyUserName,ModifyTime,ClientIP,UserHostAddress) 
                               Values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')";
                        logSql = string.Format(logSql, FormulaHelper.CreateGuid(), "Base", "", "Added", "设置用户详细信息失败,用户(" + systemName + ")"
                                               , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message, "", "", DateTime.Now, "", "");
                        SQLHelper.CreateSqlHelper(ConnEnum.Base).ExecuteNonQuery(logSql);
                        continue;
                    }
                }
            }
        }