/// <summary> /// 非默认消息时,自动发起流程 /// </summary> private void AutoCallFlow( EnginFlowDAL dal, T_WF_DOTASK Entity, DataTable dtFlowTrigger, DataTable sourceTable, ref FlowUser sUser,string strAppFieldValue, ref string ErroMessage) { DataRow[] NotDefaultMsg = dtFlowTrigger.Select("ISDEFAULTMSG=0");//非默认消息,需要调用的WCF待办任务 if (NotDefaultMsg != null && NotDefaultMsg.Count() > 0) { #region 非默认消息时,自动发起流程 foreach (DataRow dr1 in NotDefaultMsg) { string strAppMsg = string.Empty; CallWCFService( dr1, sourceTable, ref sUser, ref strAppMsg, ref ErroMessage);//调用WCF服务 if (!string.IsNullOrEmpty(strAppMsg)) { #region 执行自动发起流程结果返回不为空 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())) { if (DRNewTrigger != null) { Tracer.Debug("自动发起流程 消息规则设置中 选定岗位=" + dr1["OWNERPOSTID"].ToString() + " ;消息=" + string.Concat(dr1["MESSAGEBODY"]) + ":MODELCODE=" + string.Concat(DRNewTrigger["MODELCODE"]) + ";AutoCallFlow() FORMID=" + sUser.FormID); } else { Tracer.Debug("DRNewTrigger=null 自动发起流程的第三方消息规则中没有设置没有消息规则,当前的模块消息规则设置中 选定岗位=" + dr1["OWNERPOSTID"].ToString() + " ;消息=" + string.Concat(dr1["MESSAGEBODY"]) + ":MODELCODE=null;AutoCallFlow() FORMID=" + sUser.FormID); } List<string> Employees = new List<string>();// HRClient.GetEmployeeIDsByPostID(dr1["OWNERPOSTID"].ToString()); using (EmployeeBLL bll = new EmployeeBLL()) { var q = bll.GetEmployeeIDsByPostID(dr1["OWNERPOSTID"].ToString()); Employees= q.Count() > 0 ? q.ToList() : null; } if (Employees != null && Employees.Count() > 0) { Entity.SYSTEMCODE = dr1["SYSTEMCODE"].ToString();//解决傅意成遇到的问题(发起员工入职手续的待办,数据库中数据存在问题,系统代号是错误的RM代号,应是HR代号) dal.AddDoTask( Entity, dr1, sourceTable, Employees[0], NewFormID, strAppFieldValue, string.Concat(dr1["MESSAGEBODY"]), strFormTypes);//发送消息 //FlowEngine.TaskCacheReflesh(Employees[0]); } } else { string cMessage = ""; if (DRNewTrigger != null) { cMessage = "SystemCode:" + string.Concat(DRNewTrigger["SYSTEMCODE"]) + " MODELCODE:" + string.Concat(DRNewTrigger["MODELCODE"]) + " ;消息=" + string.Concat(dr1["MESSAGEBODY"]) + " NewFormID:" + NewFormID; } else { cMessage = "DRNewTrigger=null 消息=" + string.Concat(dr1["MESSAGEBODY"]) + " NewFormID:" + NewFormID; } //string cMessage = "SystemCode:" + string.Concat(DRNewTrigger["SYSTEMCODE"]) + " MODELCODE:" + string.Concat(DRNewTrigger["MODELCODE"]) + " ;消息=" + string.Concat(dr1["MESSAGEBODY"]) + " NewFormID:" + NewFormID; ErroMessage = cMessage; if (DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_oa_businesstrip" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_oa_businessreport" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_salaryrecordbatch" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_attendancesolutionasign" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_attendancesolution" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_employeesalaryrecord" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_employeeentry" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_leftoffice" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_oa_travelreimbursement" || DRNewTrigger["MODELCODE"].ToString().ToLower() == "t_hr_leftofficeconfirm" ) {//不需要接收岗位的: //出差申请 T_OA_BUSINESSTRIP //出差报告 T_OA_BUSINESSREPORT //月薪批量审核 T_HR_SALARYRECORDBATCH //考勤方案分配 T_HR_ATTENDANCESOLUTIONASIGN //考勤方案定义 T_HR_ATTENDANCESOLUTION //薪资记录 T_HR_EMPLOYEESALARYRECORD //员工入职 T_HR_EMPLOYEEENTRY //员工离职 T_HR_LEFTOFFICE //离职确认 T_HR_LEFTOFFICECONFIRM //出差报销 T_OA_TRAVELREIMBURSEMENT Tracer.Debug("自动发起流程 消息规则中非默认的设置中 不需要 选定岗位: AutoCallFlow() FORMID=" + sUser.FormID + " " + cMessage); } else { Tracer.Debug("自动发起流程(失败) 消息规则中非默认的设置中没有选定岗位:AutoCallFlow() FORMID=" + sUser.FormID + " " + cMessage); throw new Exception("自动发起流程(失败) 消息规则中非默认的设置中没有选定岗位 \r\n FORMID=" + sUser.FormID); } } } } catch (Exception ex) { Tracer.Debug("自动发起流程(失败):消息规则中非默认的设置中检查选定岗位出错 消息=" + string.Concat(dr1["MESSAGEBODY"]) + " AutoCallFlow() FORMID=" + sUser.FormID + " 异常信息:\r\n" + ex.Message); throw new Exception("自动发起流程(失败):消息规则中非默认的设置中检查选定岗位出错 \r\n FORMID=" + sUser.FormID); } #endregion } else { Tracer.Debug("自动发起流程成功,但返回的结果为空 消息规则设置中 ;选定岗位=" + dr1["OWNERPOSTID"].ToString() + " ;消息=" + string.Concat(dr1["MESSAGEBODY"]) + ";MODELCODE=" + string.Concat(dr1["MODELCODE"]) + ":AutoCallFlow() FORMID=" + sUser.FormID); } } #endregion } }
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; }
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; }