예제 #1
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;
                    }
                }
            }
        }
예제 #2
0
        public void StartSendNotify()
        {
            userManager = RootObj.UserManager;
            //UserService userService = new UserService();
            var    userService = FormulaHelper.GetService <IUserService>();
            string msgSQL      = @" select * from S_E_RTXSynchNoticeAndTask where State='Wait'
                               union select * from {0}.dbo.S_E_RTXSynchNoticeAndTask where State='Wait'";

            msgSQL = string.Format(msgSQL, baseSqlHelper.DbName);
            DataTable msgDt   = workFlowHelper.ExecuteDataTable(msgSQL);
            var       msgRows = msgDt.Rows;
            //将本次同步的消息置为"Processing"
            var Ids = string.Empty;

            foreach (DataRow msgRow in msgRows)
            {
                Ids += msgRow["ID"].ToString() + ",";
            }
            if (!string.IsNullOrEmpty(Ids))
            {
                Ids = Ids.TrimEnd(',');
            }
            string updateSQL = @" update S_E_RTXSynchNoticeAndTask set State = 'Processing' where ID in ('" + Ids.Replace(",", "','") + "')";

            workFlowHelper.ExecuteNonQuery(updateSQL);
            baseSqlHelper.ExecuteNonQuery(updateSQL);

            //循环将BE用户信息同步至RTX
            foreach (DataRow msgRow in msgRows)
            {
                //主键ID
                var id = msgRow["ID"].ToString();
                //消息ID
                var taskOrMsgID = msgRow["TaskExecIDOrMsgID"].ToString();

                //标题
                var title = msgRow["Title"] == null ? "" : msgRow["Title"].ToString();
                //内容
                var content = msgRow["Content"] == null ? title : msgRow["Content"].ToString();
                //LinkURL
                var linkURL = msgRow["LinkURL"] == null ? "" : msgRow["LinkURL"].ToString();
                //OwnerUserID
                var userID = msgRow["OwnerUserID"].ToString();
                //系统名称
                UserInfo userInfo   = userService.GetUserInfoByID(userID);
                var      systemName = userInfo.Code;
                systemName = systemName.TrimEnd(' ').TrimStart(' ');

                if (!userManager.IsUserExist(systemName))   //判断用户是否存在于RTX
                {
                    //用户不存在记录异常信息
                    updateSQL = @" update S_E_RTXSynchNoticeAndTask set State = 'Fail' where ID='" + id + "'  ";
                    workFlowHelper.ExecuteNonQuery(updateSQL);
                    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(), "WorkFlow", "", "Added", "给用户" + systemName + "发送提醒失败(提醒ID:" + id + ")"
                                           , "失败时间:" + DateTime.Now, "失败详细信息:用户" + systemName + "不存在", "", "", DateTime.Now, "", "");
                    baseSqlHelper.ExecuteNonQuery(logSQL);
                    continue;
                }
                //创建日期
                var      strCreateDate = msgRow["CreateDate"].ToString();
                DateTime createdate    = Convert.ToDateTime(strCreateDate);
                //流程ID
                var insFlowID = msgRow["InsFlowID"] == null ? "" : msgRow["InsFlowID"].ToString();
                //FormID
                var formID = msgRow["FormID"] == null ? "" : msgRow["FormID"].ToString();
                //数据类型
                var dataType = msgRow["DataType"].ToString();

                if (dataType == "TASK") //任务
                {
                    //如果提醒信息未任务,则添加判断任务是否已经执行过的逻辑。
                    string    taskSql = @" select ExecTime from S_WF_InsTaskExec where ID = '" + taskOrMsgID + "' and ExecTime is null";
                    DataTable taskDt  = workFlowHelper.ExecuteDataTable(taskSql);
                    if (taskDt == null || taskDt.Rows.Count == 0)
                    {
                        updateSQL = @" update S_E_RTXSynchNoticeAndTask set State = 'Fail',ErrorMsg='任务已经被执行过了' where ID='" + id + "'  ";
                        workFlowHelper.ExecuteNonQuery(updateSQL);
                        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(), "WorkFlow", "", "Added", "给用户" + systemName + "发送任务(ID:" + id + ")失败"
                                               , "失败时间:" + DateTime.Now, "失败详细信息:任务已经被执行过了。", "", "", DateTime.Now, "", "");
                        baseSqlHelper.ExecuteNonQuery(logSQL);
                        continue;
                    }

                    if (linkURL.IndexOf("?") >= 0)
                    {
                        linkURL += "&ID=" + formID + "&TaskExecID=" + taskOrMsgID + "&TaskStatus=Processing";
                    }
                    else
                    {
                        linkURL += "?ID=" + formID + "&TaskExecID=" + taskOrMsgID + "&TaskStatus=Processing";
                    }
                }

                //添加WebAddress
                linkURL = webAddress + linkURL;
                //增加模拟登录
                if (!string.IsNullOrEmpty(linkURL))
                {
                    if (linkURL.IndexOf("?") >= 0)
                    {
                        linkURL += "&SystemName=" + systemName;
                    }
                    else
                    {
                        linkURL += "?SystemName=" + systemName;
                    }
                }
                //发送者
                var sendUserIDs     = msgRow["SendUserIDs"] == null ? "" : msgRow["SendUserIDs"].ToString();
                var senderUserNames = msgRow["SendUserNames"] == null ? "" : msgRow["SendUserNames"].ToString();

                //处理标题和内容
                title   = title.Replace("[", "");
                title   = title.Replace("]", "");
                content = content.Replace("[", "");
                content = content.Replace("]", "");
                if (title.Length > 14)
                {
                    title = title.Substring(0, 13) + "......";
                }
                if (content.Length > 34)
                {
                    content = content.Substring(0, 33) + "......";
                }

                //消息主体
                //string txtMsgContent = " 标  题:" + title + "\r\n概  要:" + content + "\r\n发送者:" + senderUserNames
                //       + "\r\n\r\n[查看详细|" + linkURL + "] ";
                string txtMsgContent = " 标  题:" + title + "\r\n概  要:" + content + "\r\n发送者:" + senderUserNames
                                       + "\r\n\r\n ";
                int servertime = Convert.ToInt32(strdelayTime);
                servertime = servertime * 1000;

                try
                {
                    if (dataType == "MSG")
                    {
                        RootObj.SendNotify(systemName, "消息提醒", servertime, txtMsgContent);
                    }
                    else
                    {
                        RootObj.SendNotify(systemName, "任务提醒", servertime, txtMsgContent);
                    }
                }
                catch (Exception exp)
                {
                    updateSQL = @" update S_E_RTXSynchNoticeAndTask set State = 'Fail' where ID='" + id + "'  ";
                    workFlowHelper.ExecuteNonQuery(updateSQL);
                    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(), "WorkFlow", "", "Added", "给用户" + systemName + "发送提醒失败(提醒ID(" + id + "))"
                                           , "失败时间:" + DateTime.Now, "失败详细信息:" + exp.Message.ToString(), "", "", DateTime.Now, "", "");
                    baseSqlHelper.ExecuteNonQuery(logSQL);
                    continue;
                }
                updateSQL = @" update S_E_RTXSynchNoticeAndTask set State = 'Finish',ExecTime='" + DateTime.Now + "' where ID='" + id + "'  ";
                workFlowHelper.ExecuteNonQuery(updateSQL);
            }
        }