/// <summary> /// 流程咨讯 /// </summary> /// <param name="UserAndForm"></param> /// <param name="strTitle"></param> /// <param name="strFlowXML"></param> /// <param name="strAppXml"></param> /// <returns></returns> public bool FlowConsultati(OracleConnection con, List<CustomUserMsg> UserAndForm, string strTitle, string strFlowXML, string strAppXml) { string strCompanyID = string.Empty;//公司ID string strSystemCode = string.Empty;//系统代号 string strModelCode = string.Empty;//模块代号 string strFormID = string.Empty;//FORMID string strModelName = string.Empty;//模块名称 if (UserAndForm.Count > 0) { try { EnginFlowDAL dal = new EnginFlowDAL(); /*解析流程和业务数据XML*/ Byte[] b = System.Text.UTF8Encoding.UTF8.GetBytes(strFlowXML); XElement xele = XElement.Load(System.Xml.XmlReader.Create(new MemoryStream(b))); strCompanyID = XMLToAttribute(xele, "COMPANYID"); strSystemCode = string.Empty; strModelCode = XMLToAttribute(xele, "MODELCODE"); strFormID = XMLToAttribute(xele, "FORMID"); strModelName = XMLToAttribute(xele, "ModelName"); if (!string.IsNullOrEmpty(strAppXml)) { Byte[] Bo = System.Text.UTF8Encoding.UTF8.GetBytes(strAppXml); XElement xemeBoObject = XElement.Load(System.Xml.XmlReader.Create(new MemoryStream(Bo))); strSystemCode = (from item in xemeBoObject.Descendants("Name") select item).FirstOrDefault().Value; } /*在T_WF_MESSAGEDEFINE 中查找消息内容*/ string content = dal.GetMessageDefine(con, "FLOWCONSULTATI"); string strAppFieldValue = ConbinString(xele) + BOObjectEscapeString(strAppXml); DataTable dtValue = FieldStringToDataTable(strAppFieldValue, ref strAppFieldValue); /*在消息触发规则定义中查找消息链接*/ DataTable dtFlowTrigger = dal.FlowTriggerTable(con, strSystemCode, strModelCode, string.Empty, strCompanyID); if (dtFlowTrigger != null && dtFlowTrigger.Rows.Count > 0) { string Url = dtFlowTrigger.Rows[0]["applicationurl"].ToString(); ReplaceUrl(ref content, ref Url, dtValue); string strContent = string.Empty; foreach (CustomUserMsg custom in UserAndForm) { if (!string.IsNullOrEmpty(strTitle)) { content = strTitle; } //刷新缓存用户是否有新的待办 //EngineCache.TaskCache.TaskCacheReflesh(custom.UserID); dal.FlowConsultatiMsg(con, custom.UserID, strSystemCode, strModelCode, custom.FormID, content, Url, BOObjectEscapeString(strAppXml), strFlowXML, strAppXml); } return true; } else { //未能在触发规则定义中找到一条数据,无法发送咨讯 string cMessage = "未能在触发规则定义中找到一条数据,无法发送咨讯" + "\r\n" + "SystemCode:" + strSystemCode + "\r\n" + "Content:" + content + "\r\n" + "MODELCODE:" + strModelCode + "\r\n" + "COMPANYID:" + strCompanyID + "\r\n" + "FORMID:" + strFormID + "\r\n"; LogHelper.WriteLog("FlowConsultati()流程咨讯" + cMessage); return false; } } catch (Exception e) { string cMessage = "发送咨讯出现异常" + "\r\n" + "SystemCode:" + strSystemCode + "\r\n" + "MODELCODE:" + strModelCode + "\r\n" + "COMPANYID:" + strCompanyID + "\r\n" + "Error:" + e.Message + "\r\n" + "FORMID:" + strFormID + "\r\n"; LogHelper.WriteLog("FlowConsultati()流程咨讯" + cMessage); return false; } } else { string cMessage = "发送咨讯出现错误(没有指定接收人员)" + "\r\n" + "SystemCode:" + strSystemCode + "\r\n" + "MODELCODE:" + strModelCode + "\r\n" + "COMPANYID:" + strCompanyID + "\r\n" + "FORMID:" + strFormID + "\r\n"; LogHelper.WriteLog("FlowConsultati()流程咨讯" + cMessage); return false; } }
private bool EngineExecute(OracleConnection con, T_WF_DOTASK Entity, string IsTask, ref string ErroMessage) { bool result = false; EnginFlowDAL dal = new EnginFlowDAL(); string strAppFieldValue = string.Empty; LogHelper.WriteLog("开始将数据源字段转换成数据表...."); DataTable sourceTable = FieldStringToDataTable(Entity.APPFIELDVALUE, ref strAppFieldValue);//将业务数据与流程数据转换成DataTable作为替换的源数据 LogHelper.WriteLog("结束将数据源字段转换成数据表"); //通过系统代号,模块代号,企业ID,流程状态查到引擎配置内容 LogHelper.WriteLog("开始通过系统代号,模块代号,企业ID,流程状态查到引擎配置内容...."); DataTable dtFlowTrigger = dal.FlowTriggerTable(con, Entity.SYSTEMCODE, Entity.MODELCODE, Entity.ORDERSTATUS.ToString(), Entity.COMPANYID); LogHelper.WriteLog("结束通过系统代号,模块代号,企业ID,流程状态查到引擎配置内容"); if (dtFlowTrigger == null || dtFlowTrigger.Rows.Count == 0) { dtFlowTrigger = dal.FlowTriggerTable(con, Entity.SYSTEMCODE, Entity.MODELCODE, Entity.ORDERSTATUS.ToString()); } LogHelper.WriteLog("数量:" + dtFlowTrigger.Rows.Count.ToString()); if (dtFlowTrigger != null && dtFlowTrigger.Rows.Count > 0) { #region DataRow[] drs = dtFlowTrigger.Select("ISDEFAULTMSG=1");//发的是默认流程触发条件 if (drs.Count() > 0) { ErroMessage+="开始-发的是默认流程触发条件\r\n"; if (IsTask == "1")//新增待办任务 { ErroMessage += "开始-新增待办任务\r\n"; dal.AddDoTask(con, Entity, drs[0], sourceTable, strAppFieldValue);//新增待办任务 ErroMessage += "结束-新增待办任务\r\n"; } else if (IsTask == "0")//消息 { ErroMessage += "开始-新增消息\r\n"; dal.AddDoTaskMessage(con, Entity, drs[0], sourceTable); ErroMessage += "结束-新增消息\r\n"; } ErroMessage += "结束-发的是默认流程触发条件\r\n"; } DataRow[] NotDefaultMsg = dtFlowTrigger.Select("ISDEFAULTMSG=0");//非默认消息,需要调用的WCF待办任务 if (NotDefaultMsg != null && NotDefaultMsg.Count() > 0) { foreach (DataRow dr1 in NotDefaultMsg) { string strAppMsg = string.Empty; ErroMessage += "开始-调用WCF服务\r\n"; CallWCFService(con, dr1, sourceTable, ref strAppMsg, ref ErroMessage);//调用WCF服务 ErroMessage += "结束-调用WCF服务\r\n"; if (!string.IsNullOrEmpty(strAppMsg)) { try { string IsNewFlow = "1"; string NewFormID = string.Empty; string strFormTypes = string.Empty;//表单状态 DataRow DRNewTrigger = null; if (ApplicationValueToDataTable(con, strAppMsg, string.Concat(Entity.COMPANYID), ref sourceTable, ref IsNewFlow, ref NewFormID, ref strFormTypes, ref DRNewTrigger)) { //通过岗位查找用户,并且取第一个用户为发送消息的对像 PersonnelServiceClient HRClient = new PersonnelServiceClient(); if (!string.IsNullOrEmpty(dr1["OWNERPOSTID"].ToString())) { string[] Employees = HRClient.GetEmployeeIDsByPostID(dr1["OWNERPOSTID"].ToString()); if (Employees != null && Employees.Count() > 0) { dal.AddDoTask(con, Entity, dr1, sourceTable, Employees[0], NewFormID, strAppFieldValue, string.Concat(dr1["MESSAGEBODY"]), strFormTypes);//发送消息 } } else { string cMessage = "引擎调用新流程时没有选定岗位 SystemCode:" + string.Concat(DRNewTrigger["SYSTEMCODE"]) + " MODELCODE:" + string.Concat(DRNewTrigger["MODELCODE"]) + " NewFormID:" + NewFormID; ErroMessage += cMessage; throw new Exception("命名空间:SMT.FlowWFService.EnginFlowBLL类方法:EngineExecute()引擎调用新流程时没有选定岗位"); } } } catch (Exception ex) { LogHelper.WriteLog(ErroMessage); throw new Exception("命名空间:SMT.FlowWFService.EnginFlowBLL类方法:EngineExecute()" + ex.Message); } } } } result = true; #endregion } else { string strMsg = "系统代号" + Entity.SYSTEMCODE + "\r\n" + "模块代号:" + Entity.MODELCODE + "\r\n" + "触发条件:" + Entity.ORDERSTATUS + "公司ID:" + Entity.COMPANYID + "\r\n" + "单据ID:" + Entity.ORDERID; ErroMessage += "该单据所对应的引擎系统设置未找到,请先配置该模块引擎消息(审核通过、审核不通过、审核中):\r\n" + strMsg; LogHelper.WriteLog(ErroMessage); throw new Exception("该单据所对应的引擎系统设置未找到,请先配置该模块引擎消息(审核通过、审核不通过、审核中)" + strMsg); } return result; }
/// <summary> /// 调用WCF返回数据转换成数据源 /// </summary> /// <param name="strAppMsg">返回数据内容</param> /// <param name="sourceTable">原数据源Table</param> /// <param name="IsNewFlow">是否是新流程</param> /// <param name="DRFlowTrigger">新流程对应的流程定义</param> /// <returns></returns> private bool ApplicationValueToDataTable(OracleConnection con, string strAppMsg, string strCompanyID, ref DataTable sourceTable, ref string IsNewFlow, ref string NewFormID, ref string strFormTypes, ref DataRow DRFlowTrigger) { try { EnginFlowDAL dal = new EnginFlowDAL(); if (sourceTable == null) { sourceTable = new DataTable(); sourceTable.Columns.Add("FieldType", typeof(string)); sourceTable.Columns.Add("ColumnName", typeof(string)); sourceTable.Columns.Add("ColumnValue", typeof(string)); } Byte[] b = System.Text.UTF8Encoding.UTF8.GetBytes(strAppMsg); XElement xele = XElement.Load(System.Xml.XmlReader.Create(new MemoryStream(b))); var v = from c in xele.Descendants("Attribute") select c; IsNewFlow = string.Empty; try { //是否是新流程(0:新流程,1:旧流程) IsNewFlow = (from c in xele.Descendants("IsNewFlow") select c).FirstOrDefault().Value; } catch { IsNewFlow = "1"; } try { NewFormID = (from c in xele.Descendants("NewFormID") select c).FirstOrDefault().Value; } catch { } try { strFormTypes = (from c in xele.Descendants("FormTypes") select c).FirstOrDefault().Value; } catch { } if (v.Count() > 0) { string SystemCode = string.Empty; string ModelCode = string.Empty; foreach (var vv in v) { DataRow dr = sourceTable.NewRow(); string Name = vv.Attribute("Name").Value.ToString(); DataRow[] drs = sourceTable.Select("ColumnName='" + Name + "'"); if (drs != null && drs.Length > 0) { foreach (DataRow row in drs) { sourceTable.Rows.Remove(row);//移除相同数据 } } string Value = vv.Attribute("DataValue").Value.ToString(); dr["ColumnName"] = Name; dr["ColumnValue"] = Value; dr["FieldType"] = "sys"; if (IsNewFlow == "0") { switch (Name) { case "SYSTEMCODE": SystemCode = Value; break; case "MODELCODE": ModelCode = Value; break; } } sourceTable.Rows.Add(dr); } //新流程,并且系统代号与模块代号不为空 if (IsNewFlow == "0" && !string.IsNullOrEmpty(SystemCode) && !string.IsNullOrEmpty(ModelCode)) { DataTable table = dal.FlowTriggerTable(con, SystemCode, ModelCode, null, strCompanyID); if (table != null && table.Rows.Count > 0) { DRFlowTrigger = table.Rows[0]; } } return true; } } catch { return false; } return false; }
private bool SendDotask(string submitUserName, string modeName, string msgOpen, T_WF_DOTASK Entity, string IsTask, ref FlowUser sUser, ref string ErroMessage) { bool result = false; dal = new EnginFlowDAL(); strAppFieldValue = string.Empty; //sUser.TrackingMessage+="开始将数据源字段转换成数据表 FORMID="+sUser.FormID+"r\n"; //将业务数据与流程数据转换成DataTable作为替换的源数据 sourceTable = FieldStringToDataTable(Entity.APPFIELDVALUE, ref strAppFieldValue); //sUser.TrackingMessage += "结束将数据源字段转换成数据表 FORMID=" + sUser.FormID + "r\n"; //通过系统代号,模块代号,企业ID,流程状态查到引擎配置内容 //Tracer.Debug("开始通过系统代号,模块代号,企业ID,流程状态查[消息规则]内容 FORMID=" + sUser.FormID + ""); dtFlowTrigger = dal.FlowTriggerTable(Entity.SYSTEMCODE, Entity.MODELCODE, Entity.ORDERSTATUS.ToString(), Entity.COMPANYID); //Tracer.Debug("结束通过系统代号,模块代号,企业ID,流程状态查[消息规则]内容 FORMID=" + sUser.FormID + ""); if (dtFlowTrigger == null || dtFlowTrigger.Rows.Count == 0) { //sUser.ErrorMsg += "没有找到[消息规则]内容 再次通过全局默认消息继续查找 FORMID=" + sUser.FormID + " 异常信息:" + ErroMessage + "\r\n"; //Tracer.Debug("dtFlowTrigger=null或者dtFlowTrigger.Rows.Count == 0 没有找到[消息规则]内容 再次通过全局默认消息继续查找 FORMID=" + sUser.FormID + ""); dtFlowTrigger = dal.FlowTriggerTable(Entity.SYSTEMCODE, Entity.MODELCODE, Entity.ORDERSTATUS.ToString()); } //if (dtFlowTrigger != null && dtFlowTrigger.Rows.Count > 0) //{ //} //else //{ // //string strMsg = "系统代号:" + Entity.SYSTEMCODE + "\r\n" + // // "模块代号:" + Entity.MODELCODE + "\r\n" + // // "触发条件:" + Entity.ORDERSTATUS + "\r\n" + // // "公司 ID:" + Entity.COMPANYID + "\r\n" + // // "单据 ID:" + Entity.ORDERID; // //ErroMessage = "FORMID=" + sUser.FormID + " 发送待办任务失败, 该单据所对应的[消息规则]设置未找到,请先配置公司[" + sUser.CompayName+ "("+sUser.CompayID+")] 下的模块[ " + sUser.ModelName + " ]的 [消息规则](审核通过、审核不通过、审核中):\r\n" + strMsg; // //sUser.ErrorMsg += "发送待办任务失败 FORMID=" + sUser.FormID + " 异常信息:" + ErroMessage + "\r\n"; // //Tracer.Debug(ErroMessage); // //暂是没有默认消息也可以审核通过 // // throw new Exception("该单据所对应的引擎系统设置未找到,请先配置该模块 " + sUser.ModelName + " 引擎消息(审核通过、审核不通过、审核中)"); //} #region 发送待办任务(不管有没有配置消息规则,都发送待办任务) DataRow[] drs = new DataRow[] { }; if (dtFlowTrigger != null && dtFlowTrigger.Rows.Count > 0) { drs = dtFlowTrigger.Select("ISDEFAULTMSG=1");//不管有没有配置 } //edit by ken 2015-7-17 //if (drs.Count() > 0) //{ //sUser.ErrorMsg += "发现默认流程触发[消息规则]内容 FORMID=" + sUser.FormID + " IsTask:" + IsTask.ToString() + "\r\n"; //Tracer.Debug("FORMID=" + sUser.FormID + " 发现默认流程触发消息规则 IsTask=" + IsTask.ToString()); //if (IsTask == "1")//新增待办任务 //{ dal.AddDoTask(Entity, drs, sourceTable, strAppFieldValue, submitUserName, modeName, msgOpen);//新增待办任务 //FlowEngine.TaskCacheReflesh(Entity.RECEIVEUSERID); //} //else if (IsTask == "0")//消息 //{ //dal.AddDoTaskMessage(Entity, drs[0], sourceTable); //} //} //else //{ // sUser.ErrorMsg += "没有发现默认流程触发(审核通过、审核不通过、审核中)[消息规则]内容 FORMID=" + sUser.FormID + " IsTask:" + IsTask.ToString() + "\r\n"; // Tracer.Debug("FORMID=" + sUser.FormID + " 没有发现默认流程触发(审核通过、审核不通过、审核中)消息规则 "); // //throw new Exception("该单据所对应的默认[消息规则]设置未找到,请先配置该模块 " + sUser.ModelName + " 默认消息规则(审核通过、审核不通过、审核中)"); //} //end edit by ken 2015-7-17 DataRow[] NotDefaultMsg = dtFlowTrigger.Select("ISDEFAULTMSG=0");//非默认消息,需要调用的WCF待办任务 if (NotDefaultMsg != null && NotDefaultMsg.Count() > 0) { //AutoCallFlow( dal,Entity,dtFlowTrigger,sourceTable, ref sUser, strAppFieldValue, ref ErroMessage); #region 非默认消息时,自动发起流程 //foreach (DataRow dr1 in NotDefaultMsg) //{ // string strAppMsg = string.Empty; // CallWCFService( dr1, sourceTable, ref sUser, ref strAppMsg, ref ErroMessage);//调用WCF服务 // if (!string.IsNullOrEmpty(strAppMsg)) // { // try // { // string IsNewFlow = "1"; // string NewFormID = string.Empty; // string strFormTypes = string.Empty;//表单状态 // DataRow DRNewTrigger = null; // if (ApplicationValueToDataTable( strAppMsg, string.Concat(Entity.COMPANYID), ref sourceTable, ref IsNewFlow, ref NewFormID, ref strFormTypes, ref DRNewTrigger)) // { // //通过岗位查找用户,并且取第一个用户为发送消息的对像 // PersonnelServiceClient HRClient = new PersonnelServiceClient(); // if (!string.IsNullOrEmpty(dr1["OWNERPOSTID"].ToString())) // { // string[] Employees = HRClient.GetEmployeeIDsByPostID(dr1["OWNERPOSTID"].ToString()); // if (Employees != null && Employees.Count() > 0) // { // dal.AddDoTask( Entity, dr1, sourceTable, Employees[0], NewFormID, strAppFieldValue, string.Concat(dr1["MESSAGEBODY"]), strFormTypes);//发送消息 // } // } // else // { // string cMessage = "引擎调用新流程时没有选定岗位 SystemCode:" + string.Concat(DRNewTrigger["SYSTEMCODE"]) + " MODELCODE:" + string.Concat(DRNewTrigger["MODELCODE"]) + " NewFormID:" + NewFormID; // ErroMessage = cMessage; // throw new Exception("命名空间:SMT.FlowWFService.EnginFlowBLL类方法:EngineExecute()引擎调用新流程时没有选定岗位"); // } // } // } // catch (Exception ex) // { // throw new Exception("命名空间:SMT.FlowWFService.EnginFlowBLL类方法:EngineExecute() FORMID=" + sUser.FormID + "" + ex.Message); // } // } //} #endregion } result = true; #endregion return result; }