/// <summary>
 /// 关闭消息,与定时触发
 /// </summary>
 /// <param name="DaskID"></param>
 /// <param name="strEventID"></param>
 public void MsgClose(string DaskID, string strEventID)
 {
     EngineServicesDAL dal = new EngineServicesDAL();
     if (!string.IsNullOrEmpty(DaskID))
     {
         dal.ClosedDoTaskStatus(DaskID);
     }
     if (!string.IsNullOrEmpty(strEventID))
     {
         dal.DeleteTimingTrigger(strEventID);
     }
 }
        public void MsgListClose(string strSystemCode, List<ReceiveUserForm> List)
        {
            string strMsg = string.Empty;
            if (List != null && List.Count > 0)
            {
                if (!string.IsNullOrEmpty(strSystemCode))
                {
                    EngineServicesDAL dal = new EngineServicesDAL();
                    foreach (ReceiveUserForm user in List)
                    {
                        if (user.FormID != null && user.FormID.Count > 0)
                        {
                            foreach (string strFormID in user.FormID)
                            {
                                try
                                {
                                    TaskCache.TaskCacheReflesh(user.ReceiveUser);
                                    dal.ClosedDoTaskStatus(strSystemCode, strFormID, user.ReceiveUser);
                                }
                                catch (Exception e)
                                {

                                    strMsg = "TaskMsgClose出现异常:SystemCode='" + strSystemCode + "',FormID='" + strFormID + "',ReceiveUser='******',Error='" + e.Message + "'";
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                strMsg = "MsgListClose(批量关闭待办任务) 没有得到关闭列表数据:SystemCode='" + strSystemCode + "'";
            }
            if (!string.IsNullOrEmpty(strMsg))
            {
                Tracer.Debug("MsgListClose" + strMsg);
            }
        }
 public void ModelMsgClose(string strModelCode, string strReceiveUser)
 {
     if (!string.IsNullOrEmpty(strModelCode) && !string.IsNullOrEmpty(strReceiveUser))
     {
         try
         {
             EngineServicesDAL dal = new EngineServicesDAL();
             //刷新缓存用户是否有新的待办
             TaskCache.TaskCacheReflesh(strReceiveUser);
             dal.ClosedDoTaskStatus(strModelCode, strReceiveUser);
         }
         catch (Exception e)
         {
             string cMessage = "Message=[" + e.Message + "]" + "<消息引擎>Source=[" + e.Source + "]<消息引擎>StackTrace=[" + e.StackTrace + "]<消息引擎>TargetSite=[" + e.TargetSite + "]" + "\r\n";
             Tracer.Debug("ModelMsgClose():" + cMessage);
         }
     }
 }
        public void AddDoDask(string companyID, string orderID, string systemCode, string modelCode, string modelName, string strXML, MsgType msgType)
        {
            try
            {
                Tracer.Debug("传入参数:companyID||" + companyID + "||orderID:" + orderID + "||modelCode:" + modelCode + "||strXML:" + strXML);
                EngineServicesDAL dal = new EngineServicesDAL();
                T_WF_MESSAGEBODYDEFINE MsgBodyDefine = dal.GetMessageBodyDefine(systemCode, modelCode, companyID, 0).FirstOrDefault();
                if (MsgBodyDefine == null)
                {
                    Tracer.Debug("EngineServicesBLL.AddDoDask()没有查询到默认消息:modelCode||" + modelCode + "||systemCode" + systemCode + "||companyID" + companyID);
                    return;
                }
                DataTable dtValue = Common.EncrytXmlToDataTable(strXML);
                string Content = MsgBodyDefine.MESSAGEBODY;
                string Url = MsgBodyDefine.MESSAGEURL;
                Tracer.Debug("查询到的URL:" + Url);
                Content = Content.Replace("new:", "");
                Common.ReplaceValue(ref Content, ref Url, dtValue);
                Tracer.Debug("替换后的URL:" + Url);
                //T_WF_DOTASK dask = new T_WF_DOTASK();
                if (MsgBodyDefine.RECEIVETYPE == 1 && MsgBodyDefine.RECEIVERUSERID != null)
                {
                    for (int i = 0; i < MsgBodyDefine.RECEIVERUSERID.Split(',').Length; i++)
                    {

                        if (MsgType.Task == msgType)//代办任务
                        {
                            TaskCache.TaskCacheReflesh(MsgBodyDefine.RECEIVERUSERID.Split(',')[i]);
                            dal.ClosedDoTaskStatus(systemCode, orderID, MsgBodyDefine.RECEIVERUSERID.Split(',')[i]);
                            Tracer.Debug("开始进行保存时的URL:" + Url);
                            dal.SendTriggerTaskMsg(MsgBodyDefine.RECEIVERUSERID.Split(',')[i], systemCode, modelCode, orderID, Content, Url, Common.BOObjectEscapeString(strXML), strXML);
                        }
                        else if (MsgType.Msg == msgType)
                        {
                            dal.SendTriggerMsg(MsgBodyDefine.RECEIVERUSERID.Split(',')[i], systemCode, orderID, Content);
                        }

                    }
                }
                else if (MsgBodyDefine.RECEIVETYPE == 0 && MsgBodyDefine.RECEIVEPOSTID != null)
                {
                    for (int i = 0; i < MsgBodyDefine.RECEIVEPOSTID.Split(',').Length; i++)
                    {

                        PersonnelWS.PersonnelServiceClient HRClient = new PersonnelWS.PersonnelServiceClient();
                        Tracer.Debug("岗位:" + MsgBodyDefine.RECEIVEPOSTID.Split(',')[i]);
                        if (!string.IsNullOrEmpty(MsgBodyDefine.RECEIVEPOSTID.Split(',')[i]))
                        {
                            string[] Employees = HRClient.GetEmployeeIDsByPostID(MsgBodyDefine.RECEIVEPOSTID.Split(',')[i]);
                            Tracer.Debug("岗位人:" + Employees[0]);
                            if (MsgType.Task == msgType)//代办任务
                            {
                                TaskCache.TaskCacheReflesh(Employees[0]);
                                dal.ClosedDoTaskStatus(systemCode, orderID, Employees[0]);
                                Tracer.Debug("开始进行保存时的URL:" + Url);
                                dal.SendTriggerTaskMsg(Employees[0], systemCode, modelCode, orderID, Content, Url, Common.BOObjectEscapeString(strXML), strXML);
                            }
                            else if (MsgType.Msg == msgType)
                            {
                                dal.SendTriggerMsg(Employees[0], systemCode, orderID, Content);
                            }
                        }

                    }
                }

            }
            catch (Exception ex)
            {
                Tracer.Debug("EngineServicesBLL.AddDoDask()" + ex.Message);
            }
        }
        public void ApplicationMsgTriggerNew(List<CustomUserMsg> UserAndForm, string companyID, string SystemCode, string ModelCode, string strXml, MsgType msgType)
        {
            string strUserAndForm = string.Empty;
            string cMessage = string.Empty;
            if (UserAndForm.Count > 0)
            {

                try
                {
                    EngineServicesDAL dal = new EngineServicesDAL();
                    T_WF_MESSAGEBODYDEFINE MsgBodyDefine = dal.GetMessageBodyDefine(SystemCode, ModelCode, companyID, 0).FirstOrDefault();
                    if (MsgBodyDefine != null) //在默认消息中有定义消息
                    {
                        DataTable dtValue = Common.EncrytXmlToDataTable(strXml);
                        string Content = MsgBodyDefine.MESSAGEBODY;
                        string Url = MsgBodyDefine.MESSAGEURL;
                        Content = Content.Replace("new:", "");
                        Common.ReplaceValue(ref Content, ref Url, dtValue);
                        foreach (CustomUserMsg custom in UserAndForm)
                        {
                            strUserAndForm += "FormID:" + custom.FormID + " ReceiveUserID:" + custom.UserID + "\r\n";
                            if (MsgType.Task == msgType)//代办任务
                            {
                                TaskCache.TaskCacheReflesh(custom.UserID);
                                dal.ClosedDoTaskStatus(SystemCode, custom.FormID, custom.UserID);

                                dal.SendTriggerTaskMsg(custom.UserID, SystemCode, ModelCode, custom.FormID, Content, Url, Common.BOObjectEscapeString(strXml), strXml);
                            }
                            else if (MsgType.Msg == msgType)
                            {
                                dal.SendTriggerMsg(custom.UserID, SystemCode, custom.FormID, Content);
                            }
                        }

                    }
                    else
                    {
                        cMessage = "未在消息定义中定义默认数据:ApplicationMsgTriggerNew" + "\r\n" +
                                         "SystemCode:" + SystemCode + "\r\n" +
                                         "ModelCode:" + ModelCode + "\r\n" +
                                         "执行时间:" + DateTime.Now.ToString();
                        Tracer.Debug("ApplicationMsgTriggerNew()" + cMessage);
                    }
                }
                catch (Exception e)
                {
                    cMessage = "ApplicationMsgTriggerNew出现异常" + "\r\n" +
                                     "SystemCode:" + SystemCode + "\r\n" +
                                     "ModelCode:" + ModelCode + "\r\n" +
                                     "业务数据XML:" + strXml + "\r\n" +
                                     "异常信息:" + e.Message + "\r\n" +
                                     "异常来源:" + e.Source;
                    Tracer.Debug("ApplicationMsgTriggerNew()" + cMessage);
                }

            }
            cMessage = "ApplicationMsgTriggerNew被执行调用" + "\r\n" +
                                        "SystemCode:" + SystemCode + "\r\n" +
                                        "ModelCode:" + ModelCode + "\r\n" +
                                        "业务数据XML:" + strXml + "\r\n" +
                                         "UserAndForm Count:" + UserAndForm.Count + "\r\n" +
                                         "UserAndForm:" + strUserAndForm;
            Tracer.Debug("ApplicationMsgTriggerNew" + cMessage);
        }
        //kangxf
        public void TaskMsgClose(string strSystemCode, string strFormID, string strReceiveUser)
        {
            if (!string.IsNullOrEmpty(strSystemCode) && !string.IsNullOrEmpty(strFormID) && !string.IsNullOrEmpty(strReceiveUser))
            {
                try
                {
                    EngineServicesDAL dal = new EngineServicesDAL();
                    if (strReceiveUser.IndexOf(',') != -1)
                    {
                        string[] users = strReceiveUser.Split(',');
                        foreach (string user in users)
                        {
                            //刷新缓存用户是否有新的待办
                            TaskCache.TaskCacheReflesh(strReceiveUser);
                            dal.ClosedDoTaskStatus(strSystemCode, strFormID, user);
                        }
                    }
                    else
                    {
                        //刷新缓存用户是否有新的待办
                        TaskCache.TaskCacheReflesh(strReceiveUser);
                        dal.ClosedDoTaskStatus(strSystemCode, strFormID, strReceiveUser);
                    }
                }
                catch (Exception e)
                {

                    string cMessage = "TaskMsgClose出现异常:SystemCode='" + strSystemCode + "',FormID='" + strFormID + "',ReceiveUser='******',Error='" + e.Message + "'";
                    Tracer.Debug("TaskMsgClose()" + cMessage);
                }
            }
        }
        public List<UserInfo> ReturnUserInfoDask(string companyID, string orderID, string systemCode, string modelCode, string modelName, string strXML, MsgType msgType)
        {
            try
            {
                PersonnelWS.PersonnelServiceClient HRClient = new PersonnelWS.PersonnelServiceClient();
                List<UserInfo> list = new List<UserInfo>();
                EngineServicesDAL dal = new EngineServicesDAL();
                T_WF_MESSAGEBODYDEFINE MsgBodyDefine = dal.GetMessageBodyDefine(systemCode, modelCode, companyID, 0).FirstOrDefault();
                if (MsgBodyDefine == null)
                {
                    Tracer.Debug("EngineServicesBLL.ReturnUserInfoDask()没有查询到默认消息:modelCode||" + modelCode + "||systemCode" + systemCode + "||companyID" + companyID);
                    return null;
                }
                DataTable dtValue = Common.EncrytXmlToDataTable(strXML);
                string Content = MsgBodyDefine.MESSAGEBODY;
                string Url = MsgBodyDefine.MESSAGEURL.Replace("Details", "Edit");//MVC 审核通过之后发送指定人的代办
                Content = Content.Replace("new:", "");
                Common.ReplaceValue(ref Content, ref Url, dtValue);
                Tracer.Debug("替换后的URL:" + Url);
                if (MsgBodyDefine.RECEIVETYPE == 1 && MsgBodyDefine.RECEIVERUSERID != null)
                {
                    for (int i = 0; i < MsgBodyDefine.RECEIVERUSERID.Split(',').Length; i++)
                    {
                        var Users = HRClient.GetFlowUserByUserID(MsgBodyDefine.RECEIVERUSERID.Split(',')[i]);
                        UserInfo info = new UserInfo();
                        info.CompanyID = Users[0].CompayID;
                        info.CompanyName = Users[0].CompayName;
                        info.DepartmentID = Users[0].DepartmentID;
                        info.DepartmentName = Users[0].DepartmentName;
                        info.PostID = Users[0].PostID;
                        info.PostName = Users[0].PostName;
                        info.UserID = Users[0].UserID;
                        info.UserName = Users[0].EmployeeName;
                        list.Add(info);
                        if (MsgType.Task == msgType)//代办任务
                        {
                            TaskCache.TaskCacheReflesh(MsgBodyDefine.RECEIVERUSERID.Split(',')[i]);
                            dal.ClosedDoTaskStatus(systemCode, orderID, MsgBodyDefine.RECEIVERUSERID.Split(',')[i]);
                            Tracer.Debug("开始进行保存时的URL:" + Url);
                            dal.SendTriggerTaskMsg(MsgBodyDefine.RECEIVERUSERID.Split(',')[i], systemCode, modelCode, orderID, Content, Url, Common.BOObjectEscapeString(strXML), strXML);
                        }
                        else if (MsgType.Msg == msgType)
                        {
                            dal.SendTriggerMsg(MsgBodyDefine.RECEIVERUSERID.Split(',')[i], systemCode, orderID, Content);
                        }

                    }
                }
                else if (MsgBodyDefine.RECEIVETYPE == 0 && MsgBodyDefine.RECEIVEPOSTID != null)
                {
                    for (int i = 0; i < MsgBodyDefine.RECEIVEPOSTID.Split(',').Length; i++)
                    {
                        Tracer.Debug("岗位:" + MsgBodyDefine.RECEIVEPOSTID.Split(',')[i]);
                        if (!string.IsNullOrEmpty(MsgBodyDefine.RECEIVEPOSTID.Split(',')[i]))
                        {
                            string[] Employees = HRClient.GetEmployeeIDsByPostID(MsgBodyDefine.RECEIVEPOSTID.Split(',')[i]);
                            var Users = HRClient.GetFlowUserByUserID(Employees[0]);
                            UserInfo info = new UserInfo();
                            info.CompanyID = Users[0].CompayID;
                            info.CompanyName = Users[0].CompayName;
                            info.DepartmentID = Users[0].DepartmentID;
                            info.DepartmentName = Users[0].DepartmentName;
                            info.PostID = Users[0].PostID;
                            info.PostName = Users[0].PostName;
                            info.UserID = Users[0].UserID;
                            info.UserName = Users[0].EmployeeName;
                            list.Add(info);
                            Tracer.Debug("岗位人:" + Employees[0]);
                            if (MsgType.Task == msgType)//代办任务
                            {
                                TaskCache.TaskCacheReflesh(Employees[0]);
                                dal.ClosedDoTaskStatus(systemCode, orderID, Employees[0]);
                                Tracer.Debug("开始进行保存时的URL:" + Url);
                                dal.SendTriggerTaskMsg(Employees[0], systemCode, modelCode, orderID, Content, Url, Common.BOObjectEscapeString(strXML), strXML);
                            }
                            else if (MsgType.Msg == msgType)
                            {
                                dal.SendTriggerMsg(Employees[0], systemCode, orderID, Content);
                            }
                        }

                    }
                }
                return list;
            }
            catch (Exception ex)
            {
                Tracer.Debug("EngineServicesBLL.ReturnUserInfoDask()" + ex.Message);
                return null;
            }
        }