/// <summary> /// 自选流程(对数据库操作、对服务操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <param name="fd"></param> /// <returns></returns> public DataResult ApprovalFreeFlow(OracleConnection con, SubmitData ApprovalData, DataResult APPDataResult, List<FLOW_FLOWRECORDDETAIL_T> fd) { // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); UserInfo AppUser = new UserInfo(); //下一审核人 UserInfo AgentAppUser = new UserInfo(); //代理下一审核人 try { APPDataResult.RunTime += "---GetAppInfoStart:" + DateTime.Now.ToString(); List<FLOW_FLOWRECORDDETAIL_T> tmp = fd.Where(c => (c.EDITUSERID == ApprovalData.ApprovalUser.UserID || c.AGENTUSERID == ApprovalData.ApprovalUser.UserID) && c.FLAG == "0").ToList(); APPDataResult.RunTime += "---GetAppInfoEnd:" + DateTime.Now.ToString(); if (tmp == null) { APPDataResult.FlowResult = FlowResult.FAIL; APPDataResult.Err = "没有找到待审核信息"; // DataResult.UserInfo = null; return APPDataResult; } entity = tmp[0]; entity.EDITDATE = DateTime.Now; //审批时间 if (entity.AGENTUSERID == ApprovalData.ApprovalUser.UserID) { entity.AGENTEDITDATE = entity.EDITDATE; //代理审批时审批时间与代理审批时间到致 } //entity.EditUserID = AppUserId; entity.CONTENT = ApprovalData.ApprovalContent; entity.CHECKSTATE = ((int)ApprovalData.ApprovalResult).ToString(); workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); LogHelper.WriteLog("ApprovalFreeFlow从持久化库在恢复创建工作流实例ID=" + tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID); instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID);// workflowRuntime.GetWorkflow(new Guid(tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID)); //不同意状态处理 if (ApprovalData.ApprovalResult == ApprovalResult.NoPass) { instance.Terminate("0"); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "3"; //设为终审不通过 entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = ApprovalData.ApprovalUser.UserID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = ApprovalData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowRecord(con, entity, ApprovalData.NextStateCode, ApprovalData.NextApprovalUser.UserID); FLOW_FLOWRECORDMASTER_TDAL.Update(con, entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 APPDataResult.CheckState = "3";// APPDataResult.FlowResult = FlowResult.END; // DataResult.UserInfo = null; // return DataResult; } else { //下一审核人赋值 AppUser = ApprovalData.NextApprovalUser; AgentAppUser = GetAgentUserInfo(ApprovalData.ModelCode, AppUser.UserID); //查询是否启用了代理人(对服务操作) FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = ApprovalData.XML; workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) {//完成工作流实例 instance = null; }; ApprovalData.NextStateCode = ApprovalData.NextStateCode == "EndFlow" ? "EndFlow" : "Approval"; APPDataResult.RunTime += "---DoFlowStart:" + DateTime.Now.ToString(); APPDataResult = DoFlowRecord(con, workflowRuntime, instance, entity, ApprovalData.NextStateCode, AppUser, AgentAppUser, ApprovalData.SubmitFlag, ApprovalData.FlowType); //处理流程数据 APPDataResult.AgentUserInfo = AgentAppUser; APPDataResult.RunTime += "---DoFlowEnd:" + DateTime.Now.ToString(); if (ApprovalData.NextStateCode == "EndFlow") { workflowRuntime.GetService<FlowEvent>().OnDoFlow(instance.InstanceId, FlowData); //激发流程引擎执行到一下流程 System.Threading.Thread.Sleep(1000); } } return APPDataResult; } catch (Exception e) { throw new Exception(e.Message); } finally { AppUser = null; AgentAppUser = null; entity = null; instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
//下一审核人提交审核时调用方法 /// <summary> /// 下一审核人提交审核时调用方法 /// </summary> /// <param name="submitData"></param> /// <param name="dataResult"></param> /// <param name="listDetail"></param> /// <returns></returns> public DataResult ApprovalFlow2(OracleConnection con, SubmitData submitData, DataResult dataResult, List<FLOW_FLOWRECORDDETAIL_T> listDetail, ref string msg) { ///针对会签,该次审核成功后是否跳转至下一状态 bool isGotoNextState = true; // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); try { #region Entity赋值 List<FLOW_FLOWRECORDDETAIL_T> tmpEntity = listDetail.Where(c => (c.EDITUSERID == submitData.ApprovalUser.UserID || c.AGENTUSERID == submitData.ApprovalUser.UserID) && c.FLAG == "0").ToList(); if (tmpEntity == null) { dataResult.FlowResult = FlowResult.FAIL; dataResult.Err = "没有找到待审核信息"; return dataResult; } entity = tmpEntity[0]; entity.EDITDATE = DateTime.Now; //审批时间 if (entity.AGENTUSERID == submitData.ApprovalUser.UserID) { entity.AGENTEDITDATE = entity.EDITDATE; //代理审批时审批时间与代理审批时间到致 } entity.CONTENT = submitData.ApprovalContent; entity.CHECKSTATE = ((int)submitData.ApprovalResult).ToString(); #endregion //workflowRuntime.StartRuntime(); msg += "SMTWorkFlowManage.CreateWorkFlowRuntime(true)" + DateTime.Now.ToString() + "\r\n"; workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); try { instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID);// workflowRuntime.GetWorkflow(new Guid(tmp[0].FLOW_FLOWRECORDMASTER_T.INSTANCEID)); LogHelper.WriteLog("FormID=" + submitData.FormID + ";ApprovalFlow2(try)从持久化库[ 完成 ]恢复创建工作流实例ID=" + entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID); } catch (Exception exGetWorkflowInstance) { #region 重新创建新流程,将新流程设置为当前状态。 try { string exc = "FormID=" + submitData.FormID + ";从持久化恢复工作流失败 SMTWorkFlowManage.GetWorkflowInstance(" + workflowRuntime.Name + ", " + entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID + ");原因如下:\r\n" + exGetWorkflowInstance.ToString() + ";\r\n下面重新创建新流程,并将新流程设置为当前状态;\r\nGetFlowByModelName:submitData.ApprovalUser.DepartmentID=" + submitData.ApprovalUser.DepartmentID + ";OrgType='" + ((int)submitData.FlowType).ToString() + "'"; LogHelper.WriteLog(exc); List<FLOW_MODELFLOWRELATION_T> MODELFLOWRELATION = GetFlowByModelName(con, entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID, entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID, submitData.ModelCode, ((int)submitData.FlowType).ToString()); FLOW_MODELFLOWRELATION_T flowRelation = MODELFLOWRELATION[0]; FLOW_FLOWDEFINE_T flowDefine = flowRelation.FLOW_FLOWDEFINE_T; instance = SMTWorkFlowManage.CreateWorkflowInstance(workflowRuntime, flowDefine.XOML, flowDefine.RULES); LogHelper.WriteLog("FormID=" + submitData.FormID + ";ApprovalFlow2(catch)完成重新创建工作流实例ID=" + instance.InstanceId); StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); workflowinstance.SetState(entity.STATECODE); System.Threading.Thread.Sleep(1000); instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, instance.InstanceId.ToString()); LogHelper.WriteLog("FormID=" + submitData.FormID + ";ApprovalFlow2(catch)从持久化库再恢复刚才创建工作流实例ID=" + instance.InstanceId); entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID = instance.InstanceId.ToString(); //FLOW_FLOWRECORDDETAIL_TDAL.UpdateMasterINSTANCEID(entity.FLOW_FLOWRECORDMASTER_T); FLOW_FLOWRECORDMASTER_TDAL.UpdateMasterINSTANCEID(con, entity.FLOW_FLOWRECORDMASTER_T); } catch (Exception exNewInstance) { LogHelper.WriteLog("重新创建新流程,将新流程设置为当前状态失败:FormID=" + submitData.FormID + "FlowBll2->ApprovalFlow2" + exNewInstance.Message); //Tracer.Debug("exNewInstance: -" + submitData.FormID + "--submitDataXML:" + submitData.XML + "-" + exNewInstance.InnerException + exNewInstance.Message); throw exGetWorkflowInstance; } #endregion } msg += "SMTWorkFlowManage.CreateWorkFlowRuntime(true)完成" + DateTime.Now.ToString() + "\r\n"; #region 当前状态会签状态处理 bool currentIsCountersign = false; string currentCountersignType = "0"; Utility.IsCountersign(entity.FLOW_FLOWRECORDMASTER_T.ACTIVEROLE, entity.STATECODE, ref currentIsCountersign, ref currentCountersignType); if (currentIsCountersign) { msg += "状态会签状态处理" + DateTime.Now.ToString() + "\r\n"; if (currentCountersignType == "1")//一人通过即所有通过,可以跳转至下一状态 { isGotoNextState = true; } else { ///该审核是会签的最后的审核人 if (entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T.Count == 1) { isGotoNextState = true; } else { isGotoNextState = false; } } msg += "状态会签状态处理完成" + DateTime.Now.ToString() + "\r\n"; } #endregion //不同意状态处理 if (submitData.ApprovalResult == ApprovalResult.NoPass) { msg += "不同意状态处理" + DateTime.Now.ToString() + "\r\n"; #region instance.Terminate("0"); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "3"; //设为终审不通过 entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = submitData.ApprovalUser.UserID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = submitData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowRecord(con, entity, submitData.NextStateCode, submitData.NextApprovalUser.UserID); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); dataResult.CheckState = "3";// dataResult.FlowResult = FlowResult.END; if (currentIsCountersign) { #region 当前是会签状态,删除未审核记录 entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T .Where(detail => detail.FLOWRECORDDETAILID != entity.FLOWRECORDDETAILID && detail.STATECODE == entity.STATECODE && detail.FLAG == "0") .ToList().ForEach(item => { item.FLAG = "1"; item.CHECKSTATE = "8"; UpdateFlowRecord2(con, item); }); #endregion } #endregion msg += "不同意状态处理完成" + DateTime.Now.ToString() + "\r\n"; } else { if (!isGotoNextState) { msg += "isGotoNextState" + DateTime.Now.ToString() + "\r\n"; #region UpdateFlowRecord2(con, entity); dataResult.AppState = entity.STATECODE; dataResult.FlowResult = FlowResult.SUCCESS; dataResult.CheckState = "1"; #endregion msg += "isGotoNextState完成" + DateTime.Now.ToString() + "\r\n"; } else { msg += "获取下一状态数据" + DateTime.Now.ToString() + "\r\n"; #region 获取下一状态数据 List<string> User = new List<string>(); User.Add(entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID); User.Add(submitData.ApprovalUser.UserID); List<string> tmpPostID = new List<string>(); tmpPostID.Add(entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID); tmpPostID.Add(entity.EDITPOSTID); GetUserByInstance2(entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID, workflowRuntime, instance, entity.FLOW_FLOWRECORDMASTER_T.ACTIVEROLE, submitData.XML, entity.STATECODE, User, tmpPostID, submitData.FlowType, ref dataResult); if (dataResult.FlowResult == FlowResult.FAIL) { return dataResult; } submitData.NextStateCode = dataResult.AppState; if (dataResult.IsCountersign) { #region if (dataResult.FlowResult == FlowResult.Countersign) { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.DictCounterUser = dataResult.DictCounterUser; } } #endregion } else { #region if (dataResult.FlowResult == FlowResult.MULTIUSER) { if (submitData.NextApprovalUser == null || (Utility.GetString(submitData.NextApprovalUser.UserID) == "" || Utility.GetString(submitData.NextApprovalUser.UserName) == "")) { return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.NextApprovalUser = dataResult.UserInfo[0]; } } #endregion } #endregion msg += "获取下一状态数据完成" + DateTime.Now.ToString() + "\r\n"; msg += "单会签情况" + DateTime.Now.ToString() + "\r\n"; #region 对于单会签情况,需要将其他审核人的审核设为会签通过状态 if (currentIsCountersign && currentCountersignType == "1") { entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T .Where(detail => detail.FLOWRECORDDETAILID != entity.FLOWRECORDDETAILID && detail.STATECODE == entity.STATECODE && detail.FLAG == "0") .ToList().ForEach(item => { item.FLAG = "1"; item.CHECKSTATE = "7"; UpdateFlowRecord2(con, item); }); } #endregion msg += "单会签情况完成" + DateTime.Now.ToString() + "\r\n"; #region FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = submitData.XML; workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { instance = null; }; msg += "处理kpi" + DateTime.Now.ToString() + "\r\n"; #region 处理kpi时间 string KPITime = ""; //PerformanceServiceWS.PerformanceServiceClient psc = new PerformanceServiceWS.PerformanceServiceClient(); string pscResult = entity.FLOW_FLOWRECORDMASTER_T.KPITIMEXML; //psc.Close(); if (!string.IsNullOrEmpty(pscResult)) { XElement xe = XElement.Parse(pscResult); Func<XElement, bool> f = (x) => { XAttribute xid = x.Attribute("id"); XAttribute xvalue = x.Attribute("value"); if (xid == null || xvalue == null) return false; else { if (xid.Value == dataResult.AppState) return true; else return false; } }; XElement FlowNode = xe.Elements("FlowNode").FirstOrDefault(f); if (FlowNode != null) { KPITime = FlowNode.Attribute("value").Value; } } dataResult.KPITime = KPITime; #endregion msg += "处理kpi完成" + DateTime.Now.ToString() + "\r\n"; if (!dataResult.IsCountersign) { msg += "非会签" + DateTime.Now.ToString() + "\r\n"; #region 非会签 UserInfo AppUser = submitData.NextApprovalUser; dataResult.UserInfo.Clear(); dataResult.UserInfo.Add(AppUser); UserInfo AgentAppUser = GetAgentUserInfo(submitData.ModelCode, AppUser.UserID);//查询是否启用了代理人 dataResult = DoFlowRecord2(con, workflowRuntime, instance, entity, submitData.NextStateCode, AppUser, AgentAppUser, submitData.SubmitFlag, submitData.FlowType); //处理流程数据 dataResult.AgentUserInfo = AgentAppUser; dataResult.IsCountersign = false; #endregion msg += "非会签完成" + DateTime.Now.ToString() + "\r\n"; } else { #region 会签 dataResult.DictCounterUser = submitData.DictCounterUser; Dictionary<UserInfo, UserInfo> dictAgentUserInfo = GetAgentUserInfo2(submitData.ModelCode, submitData.DictCounterUser); dataResult = DoFlowRecord_Approval(con, workflowRuntime, instance, entity, submitData.NextStateCode, submitData.DictCounterUser, dictAgentUserInfo, submitData.SubmitFlag, submitData.FlowType); //处理流程数据 dataResult.DictAgentUserInfo = dictAgentUserInfo; dataResult.IsCountersign = true; #endregion } msg += "激发流程引擎执行到一下流程" + DateTime.Now.ToString() + "\r\n"; #region 激发流程引擎执行到一下流程 if (dataResult.AppState == null || dataResult.AppState == "") workflowRuntime.GetService<FlowEvent>().OnDoFlow(instance.InstanceId, FlowData); //激发流程引擎执行到一下流程 else { string ss = ""; int n = 0; StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); workflowinstance.SetState(dataResult.AppState); //流程跳转到指定节点 //while (true) //{ // ss += (n++).ToString()+"|" + workflowinstance.CurrentStateName; // string stateName = workflowinstance.CurrentStateName; // if (stateName != null && stateName.ToUpper().IndexOf("START") == -1) // { // break; // } //} } #endregion msg += "激发流程引擎执行到一下流程完成" + DateTime.Now.ToString() + "\r\n"; //dataResult.CanSendMessage = true; msg += "System.Threading.Thread.Sleep(1000)" + DateTime.Now.ToString() + "\r\n"; System.Threading.Thread.Sleep(1000); if (submitData.FlowType == FlowType.Task) dataResult.SubModelCode = Utility.GetSubModelCode(entity.FLOW_FLOWRECORDMASTER_T.ACTIVEROLE, dataResult.AppState); //返回下一子模块代码 msg += "System.Threading.Thread.Sleep(1000)完成" + DateTime.Now.ToString() + "\r\n"; #endregion } } dataResult.CurrentIsCountersign = currentIsCountersign; dataResult.IsGotoNextState = isGotoNextState; return dataResult; } catch (Exception e) { throw new Exception(e.Message); } finally { entity = null; instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
/// <summary> /// 自选流程审批(对服务操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <returns></returns> public DataResult AddFreeFlow(OracleConnection con, SubmitData ApprovalData, DataResult APPDataResult) { // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = new FLOW_FLOWRECORDMASTER_T(); UserInfo AppUser = new UserInfo(); //下一审核人 UserInfo AgentAppUser = new UserInfo(); //代理下一审核人 try { entity.FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT = ApprovalData.XML; entity.FLOW_FLOWRECORDMASTER_T.FORMID = ApprovalData.FormID; entity.FLOW_FLOWRECORDMASTER_T.MODELCODE = ApprovalData.ModelCode; // entity.FLOWRECORDDETAILID = FlowGUID; entity.CREATECOMPANYID = ApprovalData.ApprovalUser.CompanyID; entity.CREATEDEPARTMENTID = ApprovalData.ApprovalUser.DepartmentID; entity.CREATEPOSTID = ApprovalData.ApprovalUser.PostID; entity.CREATEUSERID = ApprovalData.ApprovalUser.UserID; entity.CREATEUSERNAME = ApprovalData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.FLOWTYPE = ((int)ApprovalData.FlowType).ToString(); entity.FLOW_FLOWRECORDMASTER_T.FLOWSELECTTYPE = ((int)ApprovalData.FlowSelectType).ToString(); entity.FLOW_FLOWRECORDMASTER_T.FLOWCODE = "FreeFlow"; workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); instance = SMTWorkFlowManage.CreateWorkflowInstance(workflowRuntime, "FreeFlow.xml");//自选流程使用 LogHelper.WriteLog("自选流程使用 AddFreeFlow(try)创建工作流实例ID=" + instance.InstanceId); entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID = instance.InstanceId.ToString(); //下一审核人赋值 AppUser = ApprovalData.NextApprovalUser; APPDataResult.RunTime += "---DoFlowStart:" + DateTime.Now.ToString(); ApprovalData.NextStateCode = "Approval"; AgentAppUser = GetAgentUserInfo(ApprovalData.ModelCode, AppUser.UserID); //查询是否启用了代理人(对服务操作) APPDataResult = DoFlowRecord(con, workflowRuntime, instance, entity, ApprovalData.NextStateCode, AppUser, AgentAppUser, ApprovalData.SubmitFlag, ApprovalData.FlowType); //处理流程数据 APPDataResult.AgentUserInfo = AgentAppUser; APPDataResult.RunTime += "---DoFlowEnd:" + DateTime.Now.ToString(); return APPDataResult; } catch (Exception e) { throw new Exception(e.Message); } finally { AppUser = null; AgentAppUser = null; entity = null; instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
public DataResult SubimtFlow(SubmitData submitData) { #region //submitData = new SubmitData(); //StringBuilder sb2 = new StringBuilder(); //sb2.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); //sb2.AppendLine("<System>"); //sb2.AppendLine(" <Name>OA</Name>"); //sb2.AppendLine(" <Version>1.0</Version>"); //sb2.AppendLine(" <System>"); //sb2.AppendLine(" <Function Description=\"事项审批\" Address=\"SmtOAPersonOffice.svc\" FuncName=\"CallApplicationService\" Binding=\"customBinding\" SplitChar=\"Г\">"); //sb2.AppendLine(" <ParaStr>"); //sb2.AppendLine(" <Para TableName=\"T_OA_APPROVALINFO\" Name=\"APPROVALID\" Description=\"报批件ID\" Value=\"\"></Para>"); //sb2.AppendLine(" </ParaStr>"); //sb2.AppendLine(" </Function>"); //sb2.AppendLine(" </System>"); //sb2.AppendLine(" <MsgOpen>"); //sb2.AppendLine(" <AssemblyName>SMT.SaaS.OA.UI</AssemblyName>"); //sb2.AppendLine(" <PublicClass>SMT.SaaS.OA.UI.Utility</PublicClass>"); //sb2.AppendLine(" <ProcessName>CreateFormFromEngine</ProcessName>"); //sb2.AppendLine(" <PageParameter>SMT.SaaS.OA.UI.UserControls.ApprovalForm_aud</PageParameter>"); //sb2.AppendLine(" <ApplicationOrder>{APPROVALID}</ApplicationOrder>"); //sb2.AppendLine(" <FormTypes>Audit</FormTypes>"); //sb2.AppendLine(" </MsgOpen>"); //sb2.AppendLine(" <Object Name=\"T_OA_APPROVALINFO\" Description=\"事项审批\" Key=\"APPROVALID\" id=\"ea454559-3810-4fa2-8500-b20c480dd4bd\">"); //sb2.AppendLine(" <Attribute Name=\"CURRENTEMPLOYEENAME\" LableResourceID=\"CURRENTEMPLOYEENAME\" Description=\"提交者\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"APPROVALID\" LableResourceID=\"APPROVALID\" Description=\"报批件ID\" DataType=\"string\" DataValue=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"APPROVALCODE\" LableResourceID=\"CODINGMATTERS\" Description=\"事项编码\" DataType=\"string\" DataValue=\"BPJ201205050001\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"APPROVALTITLE\" LableResourceID=\"TITLEMATTERS\" Description=\"事项标题\" DataType=\"string\" DataValue=\"旧流程数据到新流程数据过度测试\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"TEL\" LableResourceID=\"TEL\" Description=\"电话\" DataType=\"string\" DataValue=\"88997744\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"ISCHARGE\" LableResourceID=\"ISCHARGE\" Description=\"是否有费用\" DataType=\"string\" DataValue=\"1\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CHARGEMONEY\" LableResourceID=\"Fees\" Description=\"费用\" DataType=\"decimal\" DataValue=\"500\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CHECKSTATE\" LableResourceID=\"CHECKSTATE\" Description=\"审批状态\" DataType=\"string\" DataValue=\"0\" DataText=\"审核中\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"OWNERID\" LableResourceID=\"OWNERID\" Description=\"所属员工\" DataType=\"string\" DataValue=\"1bc4b78a-d178-4499-b948-16e18a9d73d3\" DataText=\"人事001-人事经理-人力资源部-模拟测试公司\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"OWNERNAME\" LableResourceID=\"OWNERNAME\" Description=\"当事人\" DataType=\"string\" DataValue=\"人事001\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"OWNERCOMPANYID\" LableResourceID=\"OWNERCOMPANYID\" Description=\"所属公司\" DataType=\"string\" DataValue=\"491d6eac-3bae-47ca-8998-89d39fc6faea\" DataText=\"模拟测试公司\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"OWNERDEPARTMENTID\" LableResourceID=\"OWNERDEPARTMENTID\" Description=\"所属部门\" DataType=\"string\" DataValue=\"4b146209-9442-489a-b19d-b70bd6a720d6\" DataText=\"人力资源部\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"OWNERPOSTID\" LableResourceID=\"OWNERPOSTID\" Description=\"所属岗位\" DataType=\"string\" DataValue=\"6d438cb1-92a8-4a07-a2ab-49926c68d1cd\" DataText=\"人事经理\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CREATEUSERID\" LableResourceID=\"CREATEUSERID\" Description=\"创建人\" DataType=\"string\" DataValue=\"1bc4b78a-d178-4499-b948-16e18a9d73d3\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CREATEUSERNAME\" LableResourceID=\"CREATEUSERNAME\" Description=\"创建人\" DataType=\"string\" DataValue=\"人事001\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CREATECOMPANYID\" LableResourceID=\"CREATECOMPANYID\" Description=\"创建公司\" DataType=\"string\" DataValue=\"491d6eac-3bae-47ca-8998-89d39fc6faea\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CREATEDEPARTMENTID\" LableResourceID=\"CREATEDEPARTMENTID\" Description=\"创建人部门\" DataType=\"string\" DataValue=\"4b146209-9442-489a-b19d-b70bd6a720d6\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CREATEPOSTID\" LableResourceID=\"CREATEPOSTID\" Description=\"创建人岗位\" DataType=\"string\" DataValue=\"6d438cb1-92a8-4a07-a2ab-49926c68d1cd\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CREATEDATE\" LableResourceID=\"CREATEDATE\" Description=\"创建日期\" DataType=\"DateTime\" DataValue=\"2012/5/5 15:42:27\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"UPDATEUSERID\" LableResourceID=\"UPDATEUSERID\" Description=\"修改人\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"UPDATEUSERNAME\" LableResourceID=\"UPDATEUSERNAME\" Description=\"修改人名\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"UPDATEDATE\" LableResourceID=\"UPDATEDATE\" Description=\"修改时间\" DataType=\"DateTime\" DataValue=\"\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"CONTENT\" LableResourceID=\"CONTENT\" Description=\"内容\" DataType=\"RTF\" DataValue=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" DataText=\"ea454559-3810-4fa2-8500-b20c480dd4bd\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"AttachMent\" LableResourceID=\"AttachMent\" Description=\"附件\" DataType=\"attachmentlist\" DataValue=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" DataText=\"ea454559-3810-4fa2-8500-b20c480dd4bd\" />"); //sb2.AppendLine(" <Attribute Name=\"POSTLEVEL\" LableResourceID=\"POSTLEVEL\" Description=\"岗位级别\" DataType=\"string\" DataValue=\"15\" DataText=\"15\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"TYPEAPPROVAL\" LableResourceID=\"TYPEAPPROVAL\" Description=\"事项类型\" DataType=\"string\" DataValue=\"5\" DataText=\"公司制度修改\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"TYPEAPPROVALONE\" LableResourceID=\"TYPEAPPROVALONE\" Description=\"上级事项审批类型\" DataType=\"string\" DataValue=\"0\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"TYPEAPPROVALTWO\" LableResourceID=\"TYPEAPPROVALTWO\" Description=\"上上级事项审批类型\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" <Attribute Name=\"TYPEAPPROVALTHREE\" LableResourceID=\"TYPEAPPROVALTHREE\" Description=\"上上上级事项审批类型\" DataType=\"string\" DataValue=\"\" DataText=\"\"></Attribute>"); //sb2.AppendLine(" </Object>"); //sb2.AppendLine("</System>"); //submitData.FlowSelectType = FlowSelectType.FixedFlow; //submitData.FormID = "ea454559-3810-4fa2-8500-b20c480dd4bd"; //submitData.ModelCode = "T_OA_APPROVALINFO"; //submitData.ApprovalUser = new UserInfo(); //submitData.ApprovalUser.CompanyID = "491d6eac-3bae-47ca-8998-89d39fc6faea"; //submitData.ApprovalUser.DepartmentID = "4b146209-9442-489a-b19d-b70bd6a720d6"; //submitData.ApprovalUser.PostID = "6d438cb1-92a8-4a07-a2ab-49926c68d1cd"; //submitData.ApprovalUser.UserID = "1bc4b78a-d178-4499-b948-16e18a9d73d3"; //submitData.ApprovalUser.UserName = "******"; //submitData.NextStateCode = ""; //submitData.NextApprovalUser = new UserInfo(); //submitData.NextApprovalUser.CompanyID = ""; //submitData.NextApprovalUser.DepartmentID = ""; //submitData.NextApprovalUser.PostID = ""; //submitData.NextApprovalUser.UserID = ""; //submitData.NextApprovalUser.UserName = ""; //submitData.SubmitFlag = SubmitFlag.New; //submitData.XML = sb2.ToString(); //submitData.FlowType = FlowType.Approval; //submitData.ApprovalResult = ApprovalResult.Pass; //submitData.ApprovalContent = "提交"; #endregion //调试外网 st = new 调试外网(); //return st.SubimtFlow(submitData); StringBuilder sb = new StringBuilder(); sb.AppendLine("submitData.FlowSelectType =\"" + submitData.FlowSelectType + "\";"); sb.AppendLine("submitData.FormID = \"" + submitData.FormID + "\";"); sb.AppendLine("submitData.ModelCode = \"" + submitData.ModelCode + "\";"); sb.AppendLine("submitData.ApprovalUser.CompanyID = \"" + submitData.ApprovalUser.CompanyID + "\";"); sb.AppendLine("submitData.ApprovalUser.DepartmentID = \"" + submitData.ApprovalUser.DepartmentID + "\";"); sb.AppendLine("submitData.ApprovalUser.PostID = \"" + submitData.ApprovalUser.PostID + "\";"); sb.AppendLine("submitData.ApprovalUser.UserID = \"" + submitData.ApprovalUser.UserID + "\";"); sb.AppendLine("submitData.ApprovalUser.UserName = \"" + submitData.ApprovalUser.UserName + "\";"); sb.AppendLine("submitData.NextStateCode = \"" + (submitData.NextStateCode != null ? submitData.NextStateCode : "空") + "\";"); sb.AppendLine("submitData.NextApprovalUser = \"" + submitData.NextApprovalUser + "\";"); sb.AppendLine("submitData.NextApprovalUser.CompanyID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.CompanyID : "空") + "\";"); sb.AppendLine("submitData.NextApprovalUser.DepartmentID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.DepartmentID : "空") + "\";"); sb.AppendLine("submitData.NextApprovalUser.PostID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.PostID : "空") + "\";"); sb.AppendLine("submitData.NextApprovalUser.UserID = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.UserID : "空") + "\";"); sb.AppendLine("submitData.NextApprovalUser.UserName = \"" + (submitData.NextApprovalUser != null ? submitData.NextApprovalUser.UserName : "******") + "\";"); sb.AppendLine("submitData.SubmitFlag = \"" + submitData.SubmitFlag + "\";"); // sb.AppendLine("submitData.XML = \"" + submitData.XML + "\";"); sb.AppendLine("submitData.FlowType = \"" + submitData.FlowType.ToString() + "\";"); sb.AppendLine("submitData.ApprovalResult = \"" + submitData.ApprovalResult.ToString() + "\";"); sb.AppendLine("submitData.ApprovalContent = \"" + submitData.ApprovalContent + "\";"); LogHelper.WriteLog("提交审核的信息:\r\n" + sb.ToString() + "\r\n"); LogHelper.WriteLog("流程引擎的XML数据", "SubimtFlow入口处:" + submitData.ApprovalContent + " FormID=" + submitData.FormID + ";ModelCode=" + submitData.ModelCode + " \r\n submitData.XML:\r\n" + submitData.XML); LogHelper.WriteLog("***********************************************开始" + DateTime.Now.ToString() + "***********************************************"); string msg = ""; // MsOracle.BeginTransaction(con); DateTime dtStart = DateTime.Now; DateTime dtEngineStart = DateTime.Now; DateTime dtEnd = DateTime.Now; DateTime dtCheckData = DateTime.Now; //using (TransactionScope ts = new TransactionScope()) //设置2分钟超时时间 using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(DateTime.Now.AddMinutes(2).Ticks))) { OracleConnection con = ADOHelper.GetOracleConnection(); #region 事务处理 //System.Threading.Thread.Sleep(60000); DataResult dataResult = new DataResult(); FlowBLL2 Flowbill = new FlowBLL2(); string AppCompanyID = ""; //申请公司 string MessageUserID = ""; //申请人ID string MessageUserName = ""; //申请人名 dataResult.FlowResult = FlowResult.SUCCESS; try { #region 检查流程数据是否规范 if (!FlowBLL2.CheckFlowData(submitData, ref dataResult)) { dataResult.FlowResult = FlowResult.FAIL; { //ts.Complete(); return dataResult; } } #endregion submitData.ApprovalResult = submitData.SubmitFlag == SubmitFlag.New ? ApprovalResult.Pass : submitData.ApprovalResult; submitData.FlowSelectType = submitData.FlowSelectType == null ? FlowSelectType.FixedFlow : submitData.FlowSelectType; #region #region 检查是否已提交流程(对数据库操作) msg += "检查是否已提交流程" + DateTime.Now.ToString() + "\r\n"; LogHelper.WriteLog("检查是否已提交流程FormID = " + submitData.FormID); OracleConnection ocon = ADOHelper.GetOracleConnection(); CheckResult CheckFlowResult = Flowbill.CheckFlow2(ocon, submitData, dataResult);//对数据库操作 msg += "检查是否已提交流程完成" + DateTime.Now.ToString() + "\r\n"; LogHelper.WriteLog("检查是否已提交流程完成FormID =" + submitData.FormID); dtCheckData = DateTime.Now; dataResult = CheckFlowResult.APPDataResult; if (CheckFlowResult.Flag == 0)//已审批:1,未审批:0 { //ts.Complete(); //return dataResult; } if (ocon.State == ConnectionState.Open) { ocon.Close(); } #endregion dataResult.AppState = submitData.NextStateCode; //提交新流程 if (submitData.SubmitFlag == SubmitFlag.New) { #region 新增 AppCompanyID = submitData.ApprovalUser.CompanyID; if (submitData.FlowSelectType == FlowSelectType.FreeFlow) //自选流程 dataResult = Flowbill.AddFreeFlow(con, submitData, dataResult);//对数据库操作 else { //固定流程 msg += "固定流程" + DateTime.Now.ToString() + "\r\n"; LogHelper.WriteLog("固定流程.Flowbill.AddFlow2"); dataResult = Flowbill.AddFlow2(con, submitData, dataResult, ref msg);//对数据库操作 msg += "固定流程完成" + DateTime.Now.ToString() + "\r\n"; } #endregion } else if (submitData.SubmitFlag == SubmitFlag.Cancel) { #region 撤单 if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT)) { submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT; } submitData.ApprovalContent = ""; dataResult = Flowbill.CancelFlow(submitData, dataResult, CheckFlowResult.fd); dataResult.SubmitFlag = submitData.SubmitFlag; #endregion } //审批流程 else { msg += "审核" + DateTime.Now.ToString() + "\r\n"; #region 审核 if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT)) { submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT; } //引擎消息数据 AppCompanyID = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID; MessageUserID = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERID; MessageUserName = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME; submitData.ApprovalUser.CompanyID = CheckFlowResult.fd[0].EDITCOMPANYID; submitData.ApprovalUser.DepartmentID = CheckFlowResult.fd[0].EDITDEPARTMENTID; submitData.ApprovalUser.PostID = CheckFlowResult.fd[0].EDITPOSTID; submitData.FlowSelectType = (FlowSelectType)Convert.ToInt32(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.FLOWSELECTTYPE); if (submitData.FlowSelectType == FlowSelectType.FreeFlow) dataResult = Flowbill.ApprovalFreeFlow(con, submitData, dataResult, CheckFlowResult.fd);//对数据库操作、对服务操作 else dataResult = Flowbill.ApprovalFlow2(con, submitData, dataResult, CheckFlowResult.fd, ref msg); #endregion msg += "审核完成" + DateTime.Now.ToString() + "\r\n"; } #endregion ModelInfo modelinfo = FlowBLL2.GetSysCodeByModelCode(con, submitData.ModelCode);//对数据库操作 if (dataResult.FlowResult == FlowResult.MULTIUSER) {//如果检出有多个审核人时,返回界面让用户选择一个人进行审核 string users = "检出有多个审核人\r\n"; foreach (var u in dataResult.UserInfo) { users += "CompanyID =" + u.CompanyID + "\r\n"; users += "DepartmentID = " + u.DepartmentID + "\r\n"; users += "PostID = " + u.PostID + "\r\n"; users += "serID = " + u.UserID + "\r\n"; users += "UserName = "******"\r\n"; users += "------------------------------------\r\n"; } LogHelper.WriteLog(users + "检出有多个审核人,返回界面让用户选择一个人进行审核 FormID =" + submitData.FormID); return dataResult; } //return dataResult;//测试检查流程用的,不能提交事务 LogHelper.WriteLog("模块名称:submitData.ModelCode=" + submitData.ModelCode + ";modelinfo.ModelName=" + modelinfo.ModelName); //ts.Complete(); //提交事务 if (string.IsNullOrEmpty(strIsFlowEngine) || strIsFlowEngine.ToLower() == "true") { msg += "发送审批消息(调用引擎服务)" + DateTime.Now.ToString() + "\r\n"; #region 发送审批消息(调用引擎服务) LogHelper.WriteLog("开始(调用引擎服务):SubmitEngineService"); SubmitEngineService(con, submitData, dataResult, modelinfo, CheckFlowResult, Flowbill, AppCompanyID, MessageUserID, MessageUserName, ref msg); LogHelper.WriteLog("结束(调用引擎服务):SubmitEngineService"); #endregion msg += "发送审批消息(调用引擎服务)完成" + DateTime.Now.ToString() + "\r\n"; } dtEnd = DateTime.Now; dataResult.SubmitFlag = submitData.SubmitFlag; msg += "开始时间" + dtStart.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n"; msg += "结束时间" + dtEnd.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n"; msg += "完成时间" + DateDiff(dtEnd, dtStart); ts.Complete();//提交事务 MsOracle.Close(con);//关闭数据库 LogHelper.WriteLog("执行流程成功:FormID=" + submitData.FormID); //LogHelper.WriteLog(msg); return dataResult; } catch (Exception ex) { ts.Dispose(); if (con.State == System.Data.ConnectionState.Open) { con.Close(); con.Dispose(); } dataResult.RunTime += "---FlowEnd:" + DateTime.Now.ToString(); dataResult.FlowResult = FlowResult.FAIL; // Flowbill = null; dataResult.Err = ex.Message; // Tracer.Debug("FlowService: -" + submitData.FormID + "--submitDataXML:" + submitData.XML + "-" + ex.InnerException + ex.Message); LogHelper.WriteLog("执行流程失败:FormID=" + submitData.FormID + " 异常信息:" + ex.Message); return dataResult; } finally { if (Flowbill.workflowRuntime != null && Flowbill.workflowRuntime.IsStarted) { Flowbill.workflowRuntime.Dispose(); } if (con.State == System.Data.ConnectionState.Open) { con.Close(); con.Dispose(); } dataResult = null; // Tracer.Debug("-------Trace--FormID:" + submitData.FormID + "DateTime: Start:" + dtStart.ToString() + " EngineStart:" + dtEngineStart.ToString() + " End:" + dtEnd.ToString() + "\n"); } #endregion } }
public void GetUserByFlow2(string companyID,string Xoml, string Rules, string Layout, string xml, string UserID, string PostID, FlowType FlowType, ref DataResult DataResult) { WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; string strCurrState = "StartFlow"; string strNextState = "StartFlow"; bool IsCountersign = false; string CountersignType = "0"; //Role_UserType RuleName; List<UserInfo> AppUserInfo = null; Dictionary<Role_UserType, List<UserInfo>> DictCounterUser = null; try { WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); bool iscurruser = true; int testflag = 0; while (iscurruser) { testflag++; if (testflag > 10) { throw new Exception("循环超过10次"); } #region strCurrState = strNextState; strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml); if (strNextState == "EndFlow") { strNextState = strCurrState; iscurruser = false; } else { List<Role_UserType> listRole = Utility.GetRlueName2(Layout, strNextState, ref IsCountersign, ref CountersignType); if (listRole.Count == 0) { DataResult.Err = "没有找到对应角色"; DataResult.FlowResult = FlowResult.FAIL; return; } if (!IsCountersign) { #region bool isHigher = false; //根据角色找人 AppUserInfo = GetUserByStateCode(listRole[0].RoleName, UserID, PostID,ref isHigher); #region beyond if (!isHigher) { if (listRole[0].IsOtherCompany != null&&listRole[0].IsOtherCompany.Value == true) { //过滤人 AppUserInfo = AppUserInfo.Where(user => user.CompanyID == listRole[0].OtherCompanyID).ToList(); } else { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList(); } } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } if (AppUserInfo.Where(c => c.UserID == UserID).Count() == 0) iscurruser = false; #endregion } else { #region DictCounterUser = new Dictionary<Role_UserType, List<UserInfo>>(); if (CountersignType == "0") { #region for (int i = 0; i < listRole.Count; i++) { bool isHigher = false; var listuserinfo = GetUserByStateCode(listRole[i].RoleName, UserID, PostID,ref isHigher); if (!isHigher) { if (listRole[i].IsOtherCompany != null&&listRole[i].IsOtherCompany.Value == true) { listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList(); } else { listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList(); } } if (listuserinfo == null || listuserinfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } DictCounterUser.Add(listRole[i], listuserinfo); } iscurruser = false; #endregion } else { #region iscurruser = false; bool bFlag = false; for (int i = 0; i < listRole.Count; i++) { bool isHigher = false; var listuserinfo = GetUserByStateCode(listRole[i].RoleName, UserID, PostID,ref isHigher); if (!isHigher) { if (listRole[i].IsOtherCompany != null&&listRole[i].IsOtherCompany.Value == true) { listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList(); } else { listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList(); } } if (listuserinfo != null && listuserinfo.Count > 0) { bFlag = true; if (listuserinfo.FirstOrDefault(u => u.UserID == UserID) != null) { iscurruser = true; break; } //DataResult.Err = "没有找到审核人"; //DataResult.FlowResult = FlowResult.FAIL; //return; } DictCounterUser.Add(listRole[i], listuserinfo); } if (!bFlag) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } //iscurruser = false; #endregion } #endregion } } #endregion } DataResult.IsCountersign = IsCountersign; DataResult.AppState = strNextState; DataResult.CountersignType = CountersignType; if (!IsCountersign) { #region if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.UserInfo = AppUserInfo; #endregion } else { #region DataResult.DictCounterUser = DictCounterUser; List<Role_UserType> listkeys = DictCounterUser.Keys.ToList(); for (int i = 0; i < listkeys.Count; i++) { Role_UserType key = listkeys[i]; if (DictCounterUser[key].Count > 1) { DataResult.FlowResult = FlowResult.Countersign; break; } } #endregion } } catch (Exception ex) { throw new Exception("GetUserByFlow2:" + ex.Message); } finally { strCurrState = null; strNextState = null; //RuleName = null; AppUserInfo = null; Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }
public DataResult DoFlowRecord_Approval(OracleConnection con, WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, Dictionary<Role_UserType, List<UserInfo>> dictUserInfo, Dictionary<UserInfo, UserInfo> dictAgentUserInfo, SubmitFlag SubmitFlag, FlowType FlowType) { DataResult tmpDataResult = new DataResult(); tmpDataResult.DictCounterUser = dictUserInfo; try { #region 更新流程 //如果NextStateCode为空则自动获取模型中的下一状态,如果不为空则使用传入状态代码,并使用传入下一任务人ID //更新本流程 entity = UpdateFlowRecord2(con, entity); string stateCode = ""; if (NextStateCode.ToUpper() == "ENDFLOW") { stateCode = NextStateCode; } else { stateCode = string.IsNullOrEmpty(NextStateCode) ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; } //string stateCode = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; tmpDataResult.AppState = stateCode; if (stateCode == "EndFlow") { entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "2"; //设为终审通过 if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.AGENTUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.AGENTERNAME; } else //正常审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.EDITUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.EDITUSERNAME; } entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowRecord2(con, entity); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END tmpDataResult.CheckState = "2"; } else { dictUserInfo.Values.ToList().ForEach(users => { users.ForEach(user => { #region //添加下一状态 //FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); ////添加下一状态 //entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); //entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; //entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;// entity.StateCode; ////entity2.Content = ""; //entity2.STATECODE = stateCode; //entity2.FLAG = "0"; //entity2.CHECKSTATE = "2"; //entity2.CREATEPOSTID = entity.CREATEPOSTID; //entity2.CREATECOMPANYID = entity.CREATECOMPANYID; //entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; ////if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 ////{ //// entity2.CREATEUSERID = entity.AGENTUSERID; //// entity2.CREATEUSERNAME = entity.AGENTERNAME; ////} ////else //正常审核时 ////{ //entity2.CREATEUSERID = entity.EDITUSERID; //entity2.CREATEUSERNAME = entity.EDITUSERNAME; ////} //entity2.EDITUSERID = user.UserID; //entity2.EDITUSERNAME = user.UserName; //entity2.EDITCOMPANYID = user.CompanyID; //entity2.EDITDEPARTMENTID = user.DepartmentID; //entity2.EDITPOSTID = user.PostID; //entity2.CREATEDATE = DateTime.Now; //entity2.EDITDATE = DateTime.Now; //if (dictAgentUserInfo.ContainsKey(user)) //{ // entity2.AGENTUSERID = dictAgentUserInfo[user].UserID; // entity2.AGENTERNAME = dictAgentUserInfo[user].UserName; // entity2.AGENTEDITDATE = DateTime.Now; //} //AddFlowRecord2(entity2); #endregion #region FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.STATECODE = stateCode; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.CREATEDATE = DateTime.Now; entity2.EDITUSERID = user.UserID; entity2.EDITUSERNAME = user.UserName; entity2.EDITCOMPANYID = user.CompanyID; entity2.EDITDEPARTMENTID = user.DepartmentID; entity2.EDITPOSTID = user.PostID; entity2.EDITDATE = DateTime.Now; if (dictAgentUserInfo.ContainsKey(user)) { entity2.AGENTUSERID = dictAgentUserInfo[user].UserID; entity2.AGENTERNAME = dictAgentUserInfo[user].UserName; entity2.AGENTEDITDATE = DateTime.Now; } AddFlowRecord2(con, entity2); #endregion }); }); tmpDataResult.AppState = stateCode; tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } tmpDataResult.IsCountersignComplete = true; return tmpDataResult; #endregion } catch (Exception ex) { LogHelper.WriteLog("DoFlowRecord_Approval异常信息 :" + ex.ToString()); throw new Exception("DoFlowRecord_Approval:" + ex.InnerException + ex.Message); //tmpDataResult.FlowResult = FlowResult.FAIL; //tmpDataResult.Err = ex.Message; //return tmpDataResult; } }
/// <summary> /// 启动与工作流程相同类型流程,查询对应节点用户 /// </summary> /// <param name="CompanyID">公司ID</param> /// <param name="ModelCode">模块代码</param> /// <param name="FlowGUID">待审批流GUID,新增时为空或者为StartFlow</param> /// <returns></returns> public DataResult GetAppUser(OracleConnection con, string CompanyID, string ModelCode, string FlowGUID, string xml) { DataResult GetAppUserResult = new DataResult(); try { string StateName = null; if (FlowGUID == "" || FlowGUID == "StartFlow") { StateName = "StartFlow"; } else { //根据待审批流程GUID,检索待审批状态节点代码 List<FLOW_FLOWRECORDDETAIL_T> FlowRecord = FlowBLL2.GetFlowInfo(con, "", FlowGUID, "", "", "", "", "", null); if (FlowRecord == null) { GetAppUserResult.Err = "没有待处理的审核"; GetAppUserResult.UserInfo = null; return GetAppUserResult; } StateName = FlowRecord[0].STATECODE; } //根据公司ID,模块代码获取配置的流程 WorkflowInstance instance = null; LogHelper.WriteLog("根据公司ID,模块代码获取配置的流程FlowBLL2.GetFlowByModelName:OgrType='0'"); List<FLOW_MODELFLOWRELATION_T> MODELFLOWRELATION = FlowBLL2.GetFlowByModelName(con, CompanyID, "", ModelCode, "0"); if (MODELFLOWRELATION == null || MODELFLOWRELATION.Count == 0) { GetAppUserResult.Err = "没有可使用的流程"; GetAppUserResult.UserInfo = null; return GetAppUserResult; } FLOW_FLOWDEFINE_T Xoml = MODELFLOWRELATION[0].FLOW_FLOWDEFINE_T; XmlReader readerxoml, readerule; StringReader strXoml = new StringReader(Xoml.XOML); StringReader strRules = new StringReader(Xoml.RULES == null ? "" : Xoml.RULES); readerxoml = XmlReader.Create(strXoml); readerule = XmlReader.Create(strRules); WorkflowRuntime workflowRuntime = new WorkflowRuntime(); workflowRuntime.StartRuntime(); FlowEvent ExternalEvent = new FlowEvent(); ExternalDataExchangeService objService = new ExternalDataExchangeService(); workflowRuntime.AddService(objService); objService.AddService(ExternalEvent); TypeProvider typeProvider = new TypeProvider(null); workflowRuntime.AddService(typeProvider); //XmlReader readerxoml = XmlReader.Create(HttpContext.Current.Server.MapPath ("TestFlow.xml")); // instance = workflowRuntime.CreateWorkflow(readerxoml); if (Xoml.RULES == null) instance = workflowRuntime.CreateWorkflow(readerxoml); else instance = workflowRuntime.CreateWorkflow(readerxoml, readerule, null); // instance = workflowRuntime.CreateWorkflow(typeof(TestFlow)); instance.Start(); StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); //从实例中获取定义 if (1 == 2) { System.Workflow.Activities.StateMachineWorkflowActivity smworkflow = new StateMachineWorkflowActivity(); smworkflow = workflowinstance.StateMachineWorkflow; RuleDefinitions ruleDefinitions = smworkflow.GetValue(RuleDefinitions.RuleDefinitionsProperty) as RuleDefinitions; WorkflowMarkupSerializer markupSerializer = new WorkflowMarkupSerializer(); StringBuilder xoml = new StringBuilder(); StringBuilder rule = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(xoml); XmlWriter ruleWriter = XmlWriter.Create(rule); markupSerializer.Serialize(xmlWriter, smworkflow); markupSerializer.Serialize(ruleWriter, ruleDefinitions); xmlWriter.Close(); ruleWriter.Close(); StringReader readxoml = new StringReader(xoml.ToString()); StringReader readrule = new StringReader(rule.ToString()); XmlReader readerxoml2 = XmlReader.Create(readxoml); XmlReader readerrule2 = XmlReader.Create(readrule); WorkflowInstance instance1 = workflowRuntime.CreateWorkflow(readerxoml2, readerrule2, null); instance1.Start(); StateMachineWorkflowInstance workflowinstance1 = new StateMachineWorkflowInstance(workflowRuntime, instance1.InstanceId); workflowinstance1.SetState(StateName); } //从实例中获取定义并启动新实例 //跳转到节点StateName workflowinstance.SetState(StateName); FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = xml; // FlowData.Flow_FlowRecord_T = null; ExternalEvent.OnDoFlow(instance.InstanceId, FlowData);//激发流程引擎流转到下一状态 System.Threading.Thread.Sleep(1000); PermissionServiceClient WcfPermissionService = new PermissionServiceClient(); string CurrentStateName = workflowinstance.CurrentStateName == null ? "End" : workflowinstance.CurrentStateName; //取得当前状态 List<UserInfo> listUser = new List<UserInfo>(); if (CurrentStateName != "End") { if (CurrentStateName.Substring(0, 5) == "State") { CurrentStateName = CurrentStateName.Substring(5); } string WFCurrentStateName = new Guid(CurrentStateName).ToString("D"); T_SYS_USER[] User = WcfPermissionService.GetSysUserByRole(WFCurrentStateName); //检索本状态(角色)对应用户 if (User != null) for (int i = 0; i < User.Length; i++) { UserInfo tmp = new UserInfo(); tmp.UserID = User[i].EMPLOYEEID; tmp.UserName = User[i].EMPLOYEENAME; listUser.Add(tmp); } } else { //已经到流程结束状态 UserInfo tmp = new UserInfo(); tmp.UserID = "End"; tmp.UserName = "******"; listUser.Add(tmp); } GetAppUserResult.UserInfo = listUser.Count > 0 ? listUser : null; if (GetAppUserResult.UserInfo == null) GetAppUserResult.Err = "没有找到用户"; return GetAppUserResult; // return listUser; //return workflowinstance.CurrentStateName == null ? "End" : workflowinstance.CurrentStateName; } catch (Exception ex) { GetAppUserResult.Err = ex.Message; GetAppUserResult.UserInfo = null; return GetAppUserResult; } }
/// <summary> /// 通过持久化服务查询下一处理人 /// </summary> /// <param name="WfRuntimeClone">持久化运行时</param> /// <param name="instanceClone">持久化实例</param> /// <param name="xml">条件XML</param> /// <param name="CurrentStateName">当前状态代码</param> /// <param name="DataResult">操作结果</param> public void GetUserByInstance(WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string xml, string CurrentStateName, string UserID, string PostID, ref DataResult DataResult) { if (!WfRuntimeClone.IsStarted) { WfRuntimeClone.StartRuntime(); } WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; try { WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime); string strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, CurrentStateName, xml); bool isHigher = false; List<UserInfo> AppUserInfo = GetUserByStateCode(strNextState, UserID, PostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人D(strNextState" + strNextState + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; } else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.UserInfo = AppUserInfo; } catch (Exception ex) { LogHelper.WriteLog("GetUserByInstance异常信息 :" + ex.ToString()); throw new Exception(ex.Message); } finally { Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }
/// <summary> /// 通过持久化服务查询下一处理人(对应SubmitFlow) /// </summary> /// <param name="WfRuntimeClone">持久化运行时</param> /// <param name="instanceClone">持久化实例</param> /// <param name="xml">条件XML</param> /// <param name="CurrentStateName">当前状态代码</param> /// <param name="DataResult">操作结果</param> public void GetUserByInstance(string companyID, WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string Layout, string xml, string CurrentStateName, List<string> UserID, List<string> PostID, FlowType FlowType, ref DataResult DataResult) { WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; List<UserInfo> AppUserInfo = null; string strNextState = CurrentStateName; Role_UserType RuleName; try { if (!WfRuntimeClone.IsStarted) { WfRuntimeClone.StartRuntime(); } WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime); bool iscurruser = true; while (iscurruser) { // CurrentStateName = strNextState; strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml); //if (FlowType == FlowType.Task && strNextState != "EndFlow") //{ // XmlReader XmlReader; // StringReader tmpLayout = new StringReader(Layout); // XmlReader = XmlReader.Create(tmpLayout); // XElement XElementS = XElement.Load(XmlReader); // var a = from c in XElementS.Descendants("Activity") // where c.Attribute("Name").Value == strNextState // select c.Attribute("RoleName").Value; // if (a.Count() > 0) // { // strNextState = a.First().ToString(); // } // else // { // DataResult.Err = "没有找到对应角色"; // DataResult.FlowResult = FlowResult.FAIL; // return; // } // tmpLayout = null; // XmlReader = null; // XElementS = null; // a = null; //} RuleName = Utility.GetRlueName(Layout, strNextState); if (RuleName == null) { DataResult.Err = "没有找到对应角色"; DataResult.FlowResult = FlowResult.FAIL; return; } string tmpPostID = RuleName.UserType == "CREATEUSER" ? PostID[0] : PostID[1]; bool isHigher = false; AppUserInfo = GetUserByStateCode(RuleName.RoleName, null, tmpPostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人E(RuleName.RoleName=" + RuleName.RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && RuleName.IsOtherCompany != null) { if (RuleName.IsOtherCompany.Value == true) { names += "是否指定公司:" + RuleName.IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + RuleName.OtherCompanyID + "\r\n"; } else if (RuleName.IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion #region beyond if (!isHigher && RuleName.IsOtherCompany != null) { if (RuleName.IsOtherCompany.Value == true) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == RuleName.OtherCompanyID).ToList(); } else if (RuleName.IsOtherCompany.Value == false) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList(); } } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } if (AppUserInfo.Where(c => c.UserID == UserID[1]).Count() == 0) iscurruser = false; } if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.AppState = strNextState; DataResult.UserInfo = AppUserInfo; } catch (Exception ex) { LogHelper.WriteLog("GetUserByInstance异常信息 :" + ex.ToString()); throw new Exception("GetUserByInstance:" + ex.Message); } finally { strNextState = null; AppUserInfo = null; RuleName = null; Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }
/// <summary> /// 通过流程查找审核人 /// </summary> /// <param name="Xoml"></param> /// <param name="Rules"></param> /// <param name="xml"></param> /// <param name="UserID"></param> /// <param name="DataResult"></param> //public void GetUserByFlow(string Xoml, string Rules, string xml, string UserID, ref DataResult DataResult) //{ // WorkflowRuntime WfRuntime = null; // WorkflowInstance Instance = null; // try // { // WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); // Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); // string strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, "StartFlow", xml); // List<UserInfo> AppUserInfo = GetUserByStateCode(strNextState, UserID); // if (AppUserInfo == null || AppUserInfo.Count == 0) // { // DataResult.Err = "没有找到审核人"; // DataResult.FlowResult = FlowResult.FAIL; // } // else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 // { // DataResult.FlowResult = FlowResult.MULTIUSER; // } // DataResult.UserInfo = AppUserInfo; // } // catch (Exception ex) // { // throw new Exception(ex.Message); // } // finally // { // Instance = null; // SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); // } //} #endregion #region 通过流程查找审核人(对应SubmitFlow) /// <summary> /// 通过流程查找审核人(对应SubmitFlow) /// </summary> /// <param name="Xoml"></param> /// <param name="Rules"></param> /// <param name="Layout"></param> /// <param name="xml"></param> /// <param name="UserID"></param> /// <param name="FlowType"></param> /// <param name="DataResult"></param> public void GetUserByFlow(string companyID, string Xoml, string Rules, string Layout, string xml, string UserID, string PostID, FlowType FlowType, ref DataResult DataResult) { string Msg = "companyID=" + companyID + "\r\n"; Msg += "Xoml=" + Xoml + "\r\n"; Msg += "Rules=" + Rules + "\r\n"; Msg += "Layout=" + Layout + "\r\n"; Msg += "xml=" + xml + "\r\n"; Msg += "UserID=" + UserID + "\r\n"; Msg += "PostID=" + PostID + "\r\n"; Msg += "FlowType=" + FlowType + "\r\n"; WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; string strCurrState = "StartFlow"; string strNextState = "StartFlow"; Role_UserType RuleName; List<UserInfo> AppUserInfo = null; try { WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); LogHelper.WriteLog("GetUserByFlow创建工作流实例ID=" + Instance.InstanceId); bool iscurruser = true; while (iscurruser) { strCurrState = strNextState; strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml); if (strNextState == "EndFlow") { strNextState = strCurrState; iscurruser = false; } else { RuleName = Utility.GetRlueName(Layout, strNextState); if (RuleName == null) { DataResult.Err = "没有找到对应角色"; DataResult.FlowResult = FlowResult.FAIL; return; } bool isHigher = false; AppUserInfo = GetUserByStateCode(RuleName.RoleName, UserID, PostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人A(listRole[0].RoleName=" + RuleName.RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && RuleName.IsOtherCompany != null) { if (RuleName.IsOtherCompany.Value == true) { names += "是否指定公司:" + RuleName.IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + RuleName.OtherCompanyID + "\r\n"; } else if (RuleName.IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion #region beyond if (!isHigher && RuleName.IsOtherCompany != null) { if (RuleName.IsOtherCompany.Value == true) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == RuleName.OtherCompanyID).ToList(); } else if (RuleName.IsOtherCompany.Value == false) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList(); } } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } if (AppUserInfo.Where(c => c.UserID == UserID).Count() == 0) iscurruser = false; } } //if (AppUserInfo == null || AppUserInfo.Count == 0) //{ // DataResult.Err = "没有找到审核人"; // DataResult.FlowResult = FlowResult.FAIL; //} // else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.AppState = strNextState; DataResult.UserInfo = AppUserInfo; } catch (Exception ex) { LogHelper.WriteLog("GetUserByFlow发生异常:" + Msg); throw new Exception("GetUserByFlow:" + ex.ToString()); } finally { strCurrState = null; strNextState = null; RuleName = null; AppUserInfo = null; Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }
public void GetUserByFlow2(string companyID, string Xoml, string Rules, string Layout, string xml, string UserID, string PostID, FlowType FlowType, ref DataResult DataResult, ref string msg) { WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; string strCurrState = "StartFlow"; string strNextState = "StartFlow"; bool IsCountersign = false; string CountersignType = "0"; //Role_UserType RuleName; List<UserInfo> AppUserInfo = null; Dictionary<Role_UserType, List<UserInfo>> DictCounterUser = null; try { msg += " SMTWorkFlowManage.CreateWorkFlowRuntime(false)" + DateTime.Now.ToString() + "\r\n"; WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); msg += " SMTWorkFlowManage.CreateWorkFlowRuntime(false)完成" + DateTime.Now.ToString() + "\r\n"; msg += " SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules)" + DateTime.Now.ToString() + "\r\n"; Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); LogHelper.WriteLog("GetUserByFlow2创建工作流实例ID=" + Instance.InstanceId); msg += " SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules)完成" + DateTime.Now.ToString() + "\r\n"; bool iscurruser = true; int testflag = 0; msg += " iscurruser" + DateTime.Now.ToString() + "\r\n"; while (iscurruser) { testflag++; if (testflag > 10) { throw new Exception("循环超过10次"); } #region strCurrState = strNextState; msg += " SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml)" + DateTime.Now.ToString() + "\r\n"; strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml); msg += " SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml)完成" + DateTime.Now.ToString() + "\r\n"; if (strNextState == "EndFlow") { strNextState = strCurrState; iscurruser = false; } else { List<Role_UserType> listRole = Utility.GetRlueName2(Layout, strNextState, ref IsCountersign, ref CountersignType); if (listRole.Count == 0) { DataResult.Err = "没有找到对应角色"; DataResult.FlowResult = FlowResult.FAIL; return; } if (!IsCountersign) { #region bool isHigher = false; //根据角色找人 AppUserInfo = GetUserByStateCode(listRole[0].RoleName, UserID, PostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人B(listRole[0].RoleName=" + listRole[0].RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && listRole[0].IsOtherCompany != null) { if (listRole[0].IsOtherCompany.Value == true) { names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n"; } else if (listRole[0].IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion #region beyond if (!isHigher) { if (listRole[0].IsOtherCompany != null && listRole[0].IsOtherCompany.Value == true) { //过滤人 AppUserInfo = AppUserInfo.Where(user => user.CompanyID == listRole[0].OtherCompanyID).ToList(); } else { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList(); } } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } if (AppUserInfo.Where(c => c.UserID == UserID).Count() == 0) iscurruser = false; #endregion } else { #region DictCounterUser = new Dictionary<Role_UserType, List<UserInfo>>(); if (CountersignType == "0") { #region for (int i = 0; i < listRole.Count; i++) { bool isHigher = false; var listuserinfo = GetUserByStateCode(listRole[i].RoleName, UserID, PostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人C(listRole[0].RoleName=" + listRole[i].RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && listRole[i].IsOtherCompany != null) { if (listRole[i].IsOtherCompany.Value == true) { names += "是否指定公司:" + listRole[i].IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + listRole[i].OtherCompanyID + "\r\n"; } else if (listRole[i].IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion if (!isHigher) { if (listRole[i].IsOtherCompany != null && listRole[i].IsOtherCompany.Value == true) { listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList(); } else { listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList(); } } if (listuserinfo == null || listuserinfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } DictCounterUser.Add(listRole[i], listuserinfo); } iscurruser = false; #endregion } else { #region iscurruser = false; bool bFlag = false; msg += "GetUserByStateCode" + DateTime.Now.ToString() + "\r\n"; for (int i = 0; i < listRole.Count; i++) { #region bool isHigher = false; var listuserinfo = GetUserByStateCode(listRole[i].RoleName, UserID, PostID, ref isHigher); if (!isHigher) { if (listRole[i].IsOtherCompany != null && listRole[i].IsOtherCompany.Value == true) { listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList(); } else { listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList(); } } if (listuserinfo != null && listuserinfo.Count > 0) { bFlag = true; if (listuserinfo.FirstOrDefault(u => u.UserID == UserID) != null) { iscurruser = true; break; } //DataResult.Err = "没有找到审核人"; //DataResult.FlowResult = FlowResult.FAIL; //return; } DictCounterUser.Add(listRole[i], listuserinfo); #endregion } if (!bFlag) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } msg += " GetUserByStateCode完成" + DateTime.Now.ToString() + "\r\n"; //iscurruser = false; #endregion } #endregion } } #endregion } DataResult.IsCountersign = IsCountersign; DataResult.AppState = strNextState; DataResult.CountersignType = CountersignType; if (!IsCountersign) { #region if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.UserInfo = AppUserInfo; #endregion } else { #region DataResult.DictCounterUser = DictCounterUser; List<Role_UserType> listkeys = DictCounterUser.Keys.ToList(); for (int i = 0; i < listkeys.Count; i++) { Role_UserType key = listkeys[i]; if (DictCounterUser[key].Count > 1) { DataResult.FlowResult = FlowResult.Countersign; break; } } #endregion } msg += " iscurruser完成" + DateTime.Now.ToString() + "\r\n"; } catch (Exception ex) { LogHelper.WriteLog("GetUserByFlow2异常信息 :" + ex.ToString()); throw new Exception("GetUserByFlow2:" + ex.Message); } finally { strCurrState = null; strNextState = null; //RuleName = null; AppUserInfo = null; Instance = null; msg += " SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime)" + DateTime.Now.ToString() + "\r\n"; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); msg += " SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime)完成" + DateTime.Now.ToString() + "\r\n"; } }
private bool GetUser(string OptFlag, string Xoml, string Rules, string xml, ref DataResult DataResult) { #region 旧代码 try { WorkflowRuntime WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); WorkflowInstance Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); string strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, "StartFlow", xml); } catch (Exception ex) { } finally { } return true; #endregion }
public DataResult SubimtFlow(SubmitData submitData) { StringBuilder sb = new StringBuilder(); sb.AppendLine("SubmitData.FlowSelectType =\"" + submitData.FlowSelectType + "\";"); sb.AppendLine("SubmitData.FormID = \"" + submitData.FormID + "\";"); sb.AppendLine("SubmitData.ModelCode = \"" + submitData.ModelCode + "\";"); sb.AppendLine("SubmitData.ApprovalUser = \"" + submitData.ApprovalUser + "\";"); sb.AppendLine("SubmitData.ApprovalUser.CompanyID = \"" + submitData.ApprovalUser.CompanyID + "\";"); sb.AppendLine("SubmitData.ApprovalUser.DepartmentID = \"" + submitData.ApprovalUser.DepartmentID + "\";"); sb.AppendLine("SubmitData.ApprovalUser.PostID = \"" + submitData.ApprovalUser.PostID + "\";"); sb.AppendLine("SubmitData.ApprovalUser.UserID = \"" + submitData.ApprovalUser.UserID + "\";"); sb.AppendLine("SubmitData.ApprovalUser.UserName = \"" + submitData.ApprovalUser.UserName + "\";"); sb.AppendLine("SubmitData.NextStateCode = \"\";"); sb.AppendLine("SubmitData.NextApprovalUser = \"" + submitData.NextApprovalUser + "\";"); sb.AppendLine("SubmitData.NextApprovalUser.CompanyID = \"\";"); sb.AppendLine("SubmitData.NextApprovalUser.DepartmentID = \"\";"); sb.AppendLine("SubmitData.NextApprovalUser.PostID = \"\";"); sb.AppendLine("SubmitData.NextApprovalUser.UserID = \"\";"); sb.AppendLine("SubmitData.NextApprovalUser.UserName = \"\";"); sb.AppendLine("SubmitData.SubmitFlag = \"" + submitData.SubmitFlag + "\";"); //sb.AppendLine("SubmitData.XML = \"" + submitData.XML + "\";"); sb.AppendLine("SubmitData.FlowType = \"" + submitData.FlowType + "\";"); sb.AppendLine("SubmitData.ApprovalResult = \"" + submitData.ApprovalResult + "\";"); sb.AppendLine("SubmitData.ApprovalContent = \"" + submitData .ApprovalContent+ "\";"); LogHelper.WriteLog("***********************************************开始" + DateTime.Now.ToString() + "***********************************************\r\n"); LogHelper.WriteLog("提交审核的信息:\r\n" + sb.ToString() + "\r\n"); string msg = ""; // MsOracle.BeginTransaction(con); DateTime dtStart = DateTime.Now; DateTime dtEngineStart = DateTime.Now; DateTime dtEnd = DateTime.Now; DateTime dtCheckData = DateTime.Now; //using (TransactionScope ts = new TransactionScope()) //设置2分钟超时时间 using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(DateTime.Now.AddMinutes(2).Ticks))) { OracleConnection con = ADOHelper.GetOracleConnection(); #region 事务处理 //System.Threading.Thread.Sleep(60000); DataResult dataResult = new DataResult(); FlowBLL2 Flowbill = new FlowBLL2(); string AppCompanyID = ""; //申请公司 string MessageUserID = ""; //申请人ID string MessageUserName = ""; //申请人名 dataResult.FlowResult = FlowResult.SUCCESS; try { #region 检查流程数据是否规范 if (!FlowBLL2.CheckFlowData(submitData, ref dataResult)) { dataResult.FlowResult = FlowResult.FAIL; { //ts.Complete(); return dataResult; } } #endregion submitData.ApprovalResult = submitData.SubmitFlag == SubmitFlag.New ? ApprovalResult.Pass : submitData.ApprovalResult; submitData.FlowSelectType = submitData.FlowSelectType == null ? FlowSelectType.FixedFlow : submitData.FlowSelectType; #region #region 检查是否已提交流程(对数据库操作) msg += "检查是否已提交流程"+DateTime.Now.ToString()+"\r\n"; LogHelper.WriteLog("检查是否已提交流程FormID = " + submitData.FormID); OracleConnection ocon = ADOHelper.GetOracleConnection(); CheckResult CheckFlowResult = Flowbill.CheckFlow2(ocon, submitData, dataResult);//对数据库操作 msg += "检查是否已提交流程完成" + DateTime.Now.ToString() + "\r\n"; LogHelper.WriteLog("检查是否已提交流程完成FormID =" + submitData.FormID); dtCheckData = DateTime.Now; dataResult = CheckFlowResult.APPDataResult; if (CheckFlowResult.Flag == 0)//已审批:1,未审批:0 { //ts.Complete(); //return dataResult; } if (ocon.State == ConnectionState.Open) { ocon.Close(); } #endregion dataResult.AppState = submitData.NextStateCode; //提交新流程 if (submitData.SubmitFlag == SubmitFlag.New) { LogHelper.WriteLog("新增(开始) FormID =" + submitData.FormID); #region 新增 AppCompanyID = submitData.ApprovalUser.CompanyID; if (submitData.FlowSelectType == FlowSelectType.FreeFlow) { //自选流程 LogHelper.WriteLog("自选流程.Flowbill.AddFlow2 FormID =" + submitData.FormID); dataResult = Flowbill.AddFreeFlow(con, submitData, dataResult);//对数据库操作 } else { //固定流程 msg += "固定流程" + DateTime.Now.ToString() + "\r\n"; LogHelper.WriteLog("固定流程.Flowbill.AddFlow2 FormID =" + submitData.FormID); dataResult = Flowbill.AddFlow2(con, submitData, dataResult, ref msg);//对数据库操作 msg += "固定流程完成" + DateTime.Now.ToString() + "\r\n"; } #endregion LogHelper.WriteLog("新增(结束) FormID =" + submitData.FormID); } else if (submitData.SubmitFlag == SubmitFlag.Cancel) { #region 撤单 LogHelper.WriteLog("撤单(开始) FormID =" + submitData.FormID); if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT)) { submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT; } submitData.ApprovalContent = ""; dataResult = Flowbill.CancelFlow(submitData, dataResult, CheckFlowResult.fd); dataResult.SubmitFlag = submitData.SubmitFlag; LogHelper.WriteLog("撤单(结束) FormID =" + submitData.FormID); #endregion } //审批流程 else { msg += "审核" + DateTime.Now.ToString() + "\r\n"; LogHelper.WriteLog("审核(开始) FormID =" + submitData.FormID); #region 审核 if (!string.IsNullOrEmpty(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT)) { submitData.XML = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.BUSINESSOBJECT; } //引擎消息数据 AppCompanyID = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID; MessageUserID = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERID; MessageUserName = CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME; submitData.ApprovalUser.CompanyID = CheckFlowResult.fd[0].EDITCOMPANYID; submitData.ApprovalUser.DepartmentID = CheckFlowResult.fd[0].EDITDEPARTMENTID; submitData.ApprovalUser.PostID = CheckFlowResult.fd[0].EDITPOSTID; submitData.FlowSelectType = (FlowSelectType)Convert.ToInt32(CheckFlowResult.fd[0].FLOW_FLOWRECORDMASTER_T.FLOWSELECTTYPE); if (submitData.FlowSelectType == FlowSelectType.FreeFlow) dataResult = Flowbill.ApprovalFreeFlow(con, submitData, dataResult, CheckFlowResult.fd);//对数据库操作、对服务操作 else dataResult = Flowbill.ApprovalFlow2(con, submitData, dataResult, CheckFlowResult.fd, ref msg); #endregion LogHelper.WriteLog("审核(结束) FormID =" + submitData.FormID); msg += "审核完成" + DateTime.Now.ToString() + "\r\n"; } #endregion ModelInfo modelinfo = FlowBLL2.GetSysCodeByModelCode(con, submitData.ModelCode); #region 记录审核人日志信息 string loginfo = "===================================FormID=" + submitData.FormID + "============================================\r\n"; if (dataResult.IsCountersign.ToString().ToLower() == "true") { loginfo += "是否会签=" + dataResult.IsCountersign.ToString() + "\r\n"; loginfo += "是否会签完成" + dataResult.IsCountersignComplete.ToString() + "\r\n"; } loginfo += "模块关联流程ID=" + dataResult.ModelFlowRelationID + "\r\n"; loginfo += "子模块代码=" + dataResult.SubModelCode + "\r\n"; if (dataResult.AgentUserInfo != null) { loginfo = "\r\n 代理审核人 \r\n"; loginfo += "代理公司ID=" + dataResult.AgentUserInfo.CompanyID + "\r\n"; loginfo += "代理部门ID=" + dataResult.AgentUserInfo.DepartmentID + "\r\n"; loginfo += "代理岗位ID" + dataResult.AgentUserInfo.PostID + "\r\n"; loginfo += "代理用户ID=" + dataResult.AgentUserInfo.UserID + "\r\n"; loginfo += "代理用户名称=" + dataResult.AgentUserInfo.UserName + "\r\n"; } if (dataResult.UserInfo.Count > 0) { if (dataResult.FlowResult == FlowResult.MULTIUSER) {//如果检出有多个审核人时,返回界面让用户选择一个人进行审核 loginfo = "\r\n 检出有多个审核人 \r\n"; } loginfo += "dataResult.UserInfo 审核人员信息\r\n"; foreach (var u in dataResult.UserInfo) { loginfo += "公司ID=" + u.CompanyID + "\r\n"; loginfo += "部门ID= " + u.DepartmentID + "\r\n"; loginfo += "岗位ID= " + u.PostID + "\r\n"; loginfo += "用户ID= " + u.UserID + "\r\n"; loginfo += "用户名= " + u.UserName + "\r\n"; loginfo += "------------------------------------\r\n"; } } loginfo += "模块代码 ModelCode=" + submitData.ModelCode + "\r\n"; loginfo += "模块名称 ModelName=" + modelinfo.ModelName + "\r\n"; loginfo += "下一审批人 公司ID=" + submitData.NextApprovalUser.CompanyID + "\r\n"; loginfo += "下一审批人 部门ID=" + submitData.NextApprovalUser.DepartmentID + "\r\n"; loginfo += "下一审批人 岗位ID=" + submitData.NextApprovalUser.PostID + "\r\n"; loginfo += "下一审批人 用户ID=" + submitData.NextApprovalUser.UserID + "\r\n"; loginfo += "下一审批人 用户名=" + submitData.NextApprovalUser.UserName + "\r\n"; loginfo += "下一审批状态 NextStateCode=" + submitData.NextStateCode + "\r\n"; loginfo += "使用流程类型 submitData.FlowSelectType=" + submitData.FlowSelectType + "\r\n"; loginfo += "业务数据 submitData.XML(AppXML)=" + submitData.XML + "\r\n"; loginfo += "================================================================================\r\n"; LogHelper.WriteLog(loginfo); #endregion //return dataResult;//测试检查流程用的,不能提交事务 //ts.Complete(); //提交事务 if (string.IsNullOrEmpty(strIsFlowEngine) || strIsFlowEngine.ToLower() == "true") { msg += "发送审批消息(调用引擎服务)" + DateTime.Now.ToString() + "\r\n"; #region 发送审批消息(调用引擎服务) LogHelper.WriteLog("开始(调用引擎服务):SubmitEngineService FormID =" + submitData.FormID); SubmitEngineService(con, submitData, dataResult, modelinfo, CheckFlowResult, Flowbill, AppCompanyID, MessageUserID, MessageUserName,ref msg); LogHelper.WriteLog("结束(调用引擎服务):SubmitEngineService FormID =" + submitData.FormID); #endregion msg += "发送审批消息(调用引擎服务)完成" + DateTime.Now.ToString() + "\r\n"; } dtEnd = DateTime.Now; dataResult.SubmitFlag = submitData.SubmitFlag; msg += "开始时间" + dtStart.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n"; msg += "结束时间" + dtEnd.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "\r\n"; msg += "完成时间" + DateDiff(dtEnd, dtStart); ts.Complete();//提交事务 MsOracle.Close(con);//关闭数据库 LogHelper.WriteLog("执行流程成功:FormID=" + submitData.FormID); //LogHelper.WriteLog(msg); return dataResult; } catch (Exception ex) { ts.Dispose(); if (con.State == System.Data.ConnectionState.Open) { con.Close(); con.Dispose(); } dataResult.RunTime += "---FlowEnd:" + DateTime.Now.ToString(); dataResult.FlowResult = FlowResult.FAIL; dataResult.Err = ex.Message; //Tracer.Debug("FlowService: -" + submitData.FormID + "--submitDataXML:" + submitData.XML + "-" + ex.InnerException + ex.Message); LogHelper.WriteLog("执行流程失败:FormID=" + submitData.FormID+" 异常信息:"+ ex.ToString()); return dataResult; } finally { if (Flowbill.workflowRuntime != null && Flowbill.workflowRuntime.IsStarted) { Flowbill.workflowRuntime.Dispose(); } // LogHelper.WriteLog(msg); if (con.State == System.Data.ConnectionState.Open) { con.Close(); con.Dispose(); } dataResult = null; //Tracer.Debug("-------Trace--FormID:" + submitData.FormID + "DateTime: Start:" + dtStart.ToString() + " EngineStart:" + dtEngineStart.ToString() + " End:" + dtEnd.ToString() + "\n"); } #endregion } }
/// <summary> /// 通过持久化服务查询下一处理人 /// </summary> /// <param name="WfRuntimeClone">持久化运行时</param> /// <param name="instanceClone">持久化实例</param> /// <param name="xml">条件XML</param> /// <param name="CurrentStateName">当前状态代码</param> /// <param name="DataResult">操作结果</param> public void GetUserByInstance(WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string xml, string CurrentStateName, string UserID, string PostID, ref DataResult DataResult) { WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; try { WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime); string strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, CurrentStateName, xml); bool isHigher = false; List<UserInfo> AppUserInfo = GetUserByStateCode(strNextState, UserID, PostID,ref isHigher); if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; } else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.UserInfo = AppUserInfo; } catch (Exception ex) { throw new Exception(ex.Message); } finally { Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }
/// <summary> /// 检查流程参数是否符合规则 /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <returns></returns> public static bool CheckFlowData(SubmitData ApprovalData, ref DataResult APPDataResult) { try { if (ApprovalData.FormID == null || ApprovalData.FormID == "") { APPDataResult.Err = "业务对象的FORMID为空"; return false; } if (ApprovalData.ModelCode == null || ApprovalData.ModelCode == "") { APPDataResult.Err = "模块代码为空"; return false; } //if (ApprovalData.SubmitFlag == null || (ApprovalData.SubmitFlag != SubmitFlag.New && ApprovalData.SubmitFlag != SubmitFlag.Approval)) //{ // APPDataResult.Err = "流程提交标志(SubmitFlag)有误,需要设置成SubmitFlag.New或者SubmitFlag.Approval"; // return false; //} if (ApprovalData.SubmitFlag == null) { APPDataResult.Err = "流程提交标志(SubmitFlag)不能为空"; return false; } if (ApprovalData.FlowSelectType == null || (ApprovalData.FlowSelectType != FlowSelectType.FixedFlow && ApprovalData.FlowSelectType != FlowSelectType.FreeFlow)) { APPDataResult.Err = "流程审批类型设置有误,应设置成FlowSelectType.FixedFlow或FlowSelectType.FreeFlow"; return false; } if (ApprovalData.ApprovalUser == null) { APPDataResult.Err = "提交用户信息不能为空"; return false; } else if (ApprovalData.ApprovalUser.CompanyID == null || ApprovalData.ApprovalUser.CompanyID == "") { APPDataResult.Err = "提交用户所属公司不能为空"; return false; } else if (ApprovalData.ApprovalUser.DepartmentID == null || ApprovalData.ApprovalUser.DepartmentID == "") { APPDataResult.Err = "提交用户所属部门不能为空"; return false; } else if (ApprovalData.ApprovalUser.PostID == null || ApprovalData.ApprovalUser.PostID == "") { APPDataResult.Err = "提交用户所属岗位不能为空"; return false; } else if (ApprovalData.ApprovalUser.UserID == null || ApprovalData.ApprovalUser.UserID == "") { APPDataResult.Err = "提交用户ID不能为空"; return false; } else if (ApprovalData.ApprovalUser.UserName == null || ApprovalData.ApprovalUser.UserName == "") { APPDataResult.Err = "提交用户名称不能为空"; return false; } if (ApprovalData.NextApprovalUser != null) { if ((ApprovalData.NextApprovalUser.CompanyID != null && ApprovalData.NextApprovalUser.CompanyID != "") || (ApprovalData.NextApprovalUser.DepartmentID != null && ApprovalData.NextApprovalUser.DepartmentID != "") || (ApprovalData.NextApprovalUser.PostID != null && ApprovalData.NextApprovalUser.PostID != "") || (ApprovalData.NextApprovalUser.UserID != null && ApprovalData.NextApprovalUser.UserID != "") || (ApprovalData.NextApprovalUser.UserName != null && ApprovalData.NextApprovalUser.UserName != "")) { if (ApprovalData.NextStateCode == null || ApprovalData.NextStateCode == "") { //APPDataResult.Err = "设置了下一审核人时下一审核节点代码不能为空"; //return false; } else if (ApprovalData.NextApprovalUser.CompanyID == null || ApprovalData.NextApprovalUser.CompanyID == "") { //APPDataResult.Err = "下一审核用户所属公司不能为空"; //return false; } else if (ApprovalData.NextApprovalUser.DepartmentID == null || ApprovalData.NextApprovalUser.DepartmentID == "") { //APPDataResult.Err = "下一审核用户所属部门不能为空"; //return false; } else if (ApprovalData.NextApprovalUser.PostID == null || ApprovalData.NextApprovalUser.PostID == "") { //APPDataResult.Err = "下一审核用户所属岗位不能为空"; //return false; } else if (ApprovalData.NextApprovalUser.UserID == null || ApprovalData.NextApprovalUser.UserID == "") { //APPDataResult.Err = "下一审核用户ID不能为空"; //return false; } else if (ApprovalData.NextApprovalUser.UserName == null || ApprovalData.NextApprovalUser.UserName == "") { //APPDataResult.Err = "下一审核用户名称不能为空"; //return false; } } else if (ApprovalData.NextStateCode != null && ApprovalData.NextStateCode != "") { //APPDataResult.Err = "未设置下一审核人时,不能设置下一审核节点代码"; //return false; } } else if (ApprovalData.NextStateCode != null && ApprovalData.NextStateCode != "") { //APPDataResult.Err = "未设置下一审核人时,不能设置下一审核节点代码"; //return false; } return true; } catch (Exception e) { throw e; } }
/// <summary> /// /// </summary> /// <param name="companyID"></param> /// <param name="WfRuntimeClone"></param> /// <param name="instanceClone"></param> /// <param name="Layout"></param> /// <param name="xml"></param> /// <param name="CurrentStateName"></param> /// <param name="UserID"></param> /// <param name="PostID"></param> /// <param name="FlowType"></param> /// <param name="DataResult"></param> public void GetUserByInstance2(string companyID, WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string Layout, string xml, string CurrentStateName, List<string> UserID, List<string> PostID, FlowType FlowType, ref DataResult DataResult) { WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; List<UserInfo> AppUserInfo = null; string strNextState = CurrentStateName; bool IsCountersign = false; string CountersignType = "0"; //Role_UserType RuleName; //List<UserInfo> AppUserInfo = null; Dictionary<Role_UserType, List<UserInfo>> DictCounterUser = null; try { if (!WfRuntimeClone.IsStarted) { WfRuntimeClone.StartRuntime(); } WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CloneWorkflowInstance(WfRuntimeClone, instanceClone, WfRuntime); bool iscurruser = true; int testflag = 0; while (iscurruser) { testflag++; if (testflag > 10) { throw new Exception("循环处理流程超过10次,请联系系统管理员"); } #region strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml); List<Role_UserType> listRole = Utility.GetRlueName2(Layout, strNextState, ref IsCountersign, ref CountersignType); if (listRole.Count == 0) { DataResult.Err = "没有找到对应角色"; DataResult.FlowResult = FlowResult.FAIL; return; } if (!IsCountersign) { #region string tmpPostID = listRole[0].UserType == "CREATEUSER" ? PostID[0] : PostID[1]; bool isHigher = false; AppUserInfo = GetUserByStateCode(listRole[0].RoleName, null, tmpPostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人F(listRole[0].RoleName=" + listRole[0].RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && listRole[0].IsOtherCompany != null) { if (listRole[0].IsOtherCompany.Value == true) { names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n"; } else if (listRole[0].IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion #region beyond if (!isHigher && strNextState.ToUpper() != "ENDFLOW") { if (listRole[0].IsOtherCompany != null && listRole[0].IsOtherCompany.Value == true) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == listRole[0].OtherCompanyID).ToList(); } else { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList(); } } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } if (AppUserInfo.Where(c => c.UserID == UserID[1]).Count() == 0) iscurruser = false; #endregion } else { #region DictCounterUser = new Dictionary<Role_UserType, List<UserInfo>>(); if (CountersignType == "0") { #region for (int i = 0; i < listRole.Count; i++) { string tmpPostID = listRole[i].UserType == "CREATEUSER" ? PostID[0] : PostID[1]; bool isHigher = false; var listuserinfo = GetUserByStateCode(listRole[i].RoleName, null, tmpPostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人G(listRole[i].RoleName=" + listRole[0].RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && listRole[0].IsOtherCompany != null) { if (listRole[0].IsOtherCompany.Value == true) { names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n"; } else if (listRole[0].IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion if (!isHigher) { if (listRole[i].IsOtherCompany != null && listRole[i].IsOtherCompany.Value == true) { listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList(); } else { listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList(); } } if (listuserinfo == null || listuserinfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } DictCounterUser.Add(listRole[i], listuserinfo); } iscurruser = false; #endregion } else { #region iscurruser = false; bool bFlag = false; for (int i = 0; i < listRole.Count; i++) { string tmpPostID = listRole[i].UserType == "CREATEUSER" ? PostID[0] : PostID[1]; bool isHigher = false; var listuserinfo = GetUserByStateCode(listRole[i].RoleName, null, tmpPostID, ref isHigher); #region 打印审核人 string names = "=======打印审核人H(listRole[0].RoleName=" + listRole[i].RoleName + ";UserID=" + UserID + ";PostID=" + PostID + ";isHigher=" + isHigher.ToString() + ")=======\r\n"; foreach (var user in AppUserInfo) { names += "CompanyID:" + user.CompanyID + "\r\n"; names += "DepartmentID:" + user.DepartmentID + "\r\n"; names += "PostID:" + user.PostID + "\r\n"; names += "UserID:" + user.UserID + "\r\n"; names += "UserName:"******"\r\n"; } if (!isHigher && listRole[0].IsOtherCompany != null) { if (listRole[0].IsOtherCompany.Value == true) { names += "是否指定公司:" + listRole[0].IsOtherCompany.Value.ToString() + "\r\n"; names += "公司的ID:" + listRole[0].OtherCompanyID + "\r\n"; } else if (listRole[0].IsOtherCompany.Value == false) { names += "实际要查找公司的ID:" + companyID + "\r\n"; } } LogHelper.WriteLog(names); #endregion if (!isHigher) { if (listRole[i].IsOtherCompany != null && listRole[i].IsOtherCompany.Value == true) { listuserinfo = listuserinfo.Where(user => user.CompanyID == listRole[i].OtherCompanyID).ToList(); } else { listuserinfo = listuserinfo.Where(user => user.CompanyID == companyID).ToList(); } } if (listuserinfo != null && listuserinfo.Count > 0) { bFlag = true; if (listuserinfo.FirstOrDefault(u => u.UserID == UserID[1]) != null) { iscurruser = true; break; } //DataResult.Err = "没有找到审核人"; //DataResult.FlowResult = FlowResult.FAIL; //return; } DictCounterUser.Add(listRole[i], listuserinfo); } if (!bFlag) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } #endregion } #endregion } #endregion } DataResult.IsCountersign = IsCountersign; DataResult.AppState = strNextState; DataResult.CountersignType = CountersignType; if (!IsCountersign) { #region if (AppUserInfo != null && AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.UserInfo = AppUserInfo; #endregion } else { #region DataResult.DictCounterUser = DictCounterUser; List<Role_UserType> listkeys = DictCounterUser.Keys.ToList(); for (int i = 0; i < listkeys.Count; i++) { Role_UserType key = listkeys[i]; if (DictCounterUser[key].Count > 1) { DataResult.FlowResult = FlowResult.Countersign; break; } } #endregion } } catch (Exception ex) { //throw new Exception("GetUserByInstance2:" + ex.Message);//旧的 LogHelper.WriteLog(this, "GetUserByInstance2(string companyID,WorkflowRuntime WfRuntimeClone, WorkflowInstance instanceClone, string Layout, string xml, string CurrentStateName, List<string> UserID, List<string> PostID, FlowType FlowType, ref DataResult DataResult):", "", ex); throw new Exception(ex.Message); } finally { strNextState = null; AppUserInfo = null; //RuleName = null; Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }
/// <summary> /// 会签 /// </summary> /// <param name="workflowRuntime"></param> /// <param name="instance"></param> /// <param name="entity"></param> /// <param name="NextStateCode"></param> /// <param name="dictUserInfo"></param> /// <param name="dictAgentUserInfo"></param> /// <param name="SubmitFlag"></param> /// <param name="FlowType"></param> /// <returns></returns> public DataResult DoFlowRecord_Add(OracleConnection con, WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, Dictionary<Role_UserType, List<UserInfo>> dictUserInfo, Dictionary<UserInfo, UserInfo> dictAgentUserInfo, SubmitFlag SubmitFlag, FlowType FlowType) { DataResult tmpDataResult = new DataResult(); tmpDataResult.DictCounterUser = dictUserInfo; try { if (SubmitFlag == SubmitFlag.New) { #region 添加启动状态 entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; FLOW_FLOWRECORDMASTER_TDAL.Add(con, entity.FLOW_FLOWRECORDMASTER_T); AddFlowRecord2(con, entity); #endregion } else { #region //entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; entity.CHECKSTATE = "6"; entity.STATECODE = "ReSubmit"; entity.FLAG = "1"; AddFlowRecord2(con, entity); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); #endregion } //System.Threading.Thread.Sleep(1000); string stateCode = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; tmpDataResult.AppState = stateCode; if (stateCode != "EndFlow") { #region dictUserInfo.Values.ToList().ForEach(users => { users.ForEach(user => { #region FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.STATECODE = stateCode; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.CREATEDATE = DateTime.Now; entity2.EDITUSERID = user.UserID; entity2.EDITUSERNAME = user.UserName; entity2.EDITCOMPANYID = user.CompanyID; entity2.EDITDEPARTMENTID = user.DepartmentID; entity2.EDITPOSTID = user.PostID; entity2.EDITDATE = DateTime.Now; if (dictAgentUserInfo.ContainsKey(user)) { entity2.AGENTUSERID = dictAgentUserInfo[user].UserID; entity2.AGENTERNAME = dictAgentUserInfo[user].UserName; entity2.AGENTEDITDATE = DateTime.Now; } AddFlowRecord2(con, entity2); #endregion }); }); #endregion tmpDataResult.AppState = stateCode; tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.CheckState = "2"; tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END } tmpDataResult.IsCountersignComplete = true; return tmpDataResult; } catch (Exception ex) { LogHelper.WriteLog("DoFlowRecord_Add异常信息 :" + ex.ToString()); throw new Exception("DoFlowRecord_Add:" + ex.InnerException + ex.Message); //tmpDataResult.FlowResult = FlowResult.FAIL; //tmpDataResult.Err = ex.Message; //return tmpDataResult; } }
/// <summary> /// 检查是否已提交流程(对数据库操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <returns></returns> public CheckResult CheckFlow2(OracleConnection con, SubmitData ApprovalData, DataResult APPDataResult) { CheckResult CheckFlowResult = new CheckResult(); try { CheckFlowResult.APPDataResult = APPDataResult; APPDataResult.RunTime += "---GetFlowInfoStart:" + DateTime.Now.ToString(); List<FlowType> FlowTypeList = new List<FlowWFService.FlowType>(); FlowTypeList.Add(ApprovalData.FlowType); List<FLOW_FLOWRECORDDETAIL_T> fd = FlowBLL2.GetFlowInfo(con, ApprovalData.FormID, "", "", "0", ApprovalData.ModelCode, "", "", FlowTypeList);//对数据库操作 CheckFlowResult.fd = fd; APPDataResult.RunTime += "---GetFlowInfoEnd:" + DateTime.Now.ToString(); if (ApprovalData.SubmitFlag == SubmitFlag.New) { #region if (fd != null && fd.Count > 0) { CheckFlowResult.APPDataResult.FlowResult = FlowResult.SUCCESS; CheckFlowResult.Flag = 0; UserInfo AppUser = new UserInfo();//下一审核人 AppUser.UserID = fd[0].EDITUSERID; AppUser.UserName = fd[0].EDITUSERNAME; AppUser.CompanyID = fd[0].EDITCOMPANYID; AppUser.DepartmentID = fd[0].EDITDEPARTMENTID; AppUser.PostID = fd[0].EDITPOSTID; CheckFlowResult.APPDataResult.UserInfo.Add(AppUser); CheckFlowResult.APPDataResult.AppState = fd[0].STATECODE; return CheckFlowResult; } #endregion } else if (ApprovalData.SubmitFlag == SubmitFlag.Cancel) { } else { if (fd == null || fd.Count == 0) { CheckFlowResult.APPDataResult.FlowResult = FlowResult.FAIL; CheckFlowResult.APPDataResult.Err = "没有待审批节点,请检查流程是否已经结束或流程有异常!"; CheckFlowResult.Flag = 0; return CheckFlowResult; } else { if (fd.Where(c => c.EDITUSERID == ApprovalData.ApprovalUser.UserID || c.AGENTUSERID == ApprovalData.ApprovalUser.UserID).ToList().Count == 0) { APPDataResult.FlowResult = FlowResult.SUCCESS; CheckFlowResult.Flag = 0; UserInfo AppUser = new UserInfo(); AppUser.UserID = fd[0].EDITUSERID; AppUser.UserName = fd[0].EDITUSERNAME; AppUser.CompanyID = fd[0].EDITCOMPANYID; AppUser.DepartmentID = fd[0].EDITDEPARTMENTID; AppUser.PostID = fd[0].EDITPOSTID; CheckFlowResult.APPDataResult.UserInfo.Add(AppUser); CheckFlowResult.APPDataResult.AppState = fd[0].STATECODE; return CheckFlowResult; } } } CheckFlowResult.Flag = 1; return CheckFlowResult; } catch (Exception e) { throw new Exception(e.Message); } finally { CheckFlowResult = null; } }
/// <summary> /// 流程数据处理(对应SubmitFlow)对数据库操作 /// </summary> /// <param name="workflowRuntime"></param> /// <param name="instance"></param> /// <param name="entity"></param> /// <param name="NextStateCode"></param> /// <param name="EditUserId"></param> /// <param name="EditUserName"></param> /// <param name="SubmitFlag"></param> /// <param name="FlowType"></param> /// <returns></returns> public DataResult DoFlowRecord(OracleConnection con, WorkflowRuntime workflowRuntime, WorkflowInstance instance, FLOW_FLOWRECORDDETAIL_T entity, string NextStateCode, UserInfo AppUser, UserInfo AgentUser, SubmitFlag SubmitFlag, FlowType FlowType) { DataResult tmpDataResult = new DataResult(); UserInfo tmpUserInfo = AppUser; //tmpUserInfo.UserID = EditUserId; //tmpUserInfo.UserName = EditUserName; tmpDataResult.UserInfo.Add(tmpUserInfo); try { if (SubmitFlag == SubmitFlag.New) { #region 新增流程 //添加启动状态 entity.FLOW_FLOWRECORDMASTER_T.FLOWRECORDMASTERID = Guid.NewGuid().ToString(); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "1"; entity.FLOW_FLOWRECORDMASTER_T.CREATECOMPANYID = entity.CREATECOMPANYID; entity.FLOW_FLOWRECORDMASTER_T.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.CREATEUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.CREATEUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.CREATEUSERNAME; entity.FLOW_FLOWRECORDMASTER_T.CREATEDATE = DateTime.Now; entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); // entity.FLOW_FLOWRECORDMASTER_T .INSTANCEID = instance.InstanceId.ToString(); entity.FLAG = "1"; entity.CHECKSTATE = "1"; //entity.FlowCode = "TestFlow"; //正式使用时关屏蔽 entity.STATECODE = "StartFlow"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; #region 引擎自动提交时停留在提交人处 if (FlowType == FlowType.Pending) { entity.FLAG = "0"; entity.EDITUSERID = AppUser.UserID; entity.EDITUSERNAME = AppUser.UserName; entity.EDITCOMPANYID = AppUser.CompanyID; entity.EDITDEPARTMENTID = AppUser.DepartmentID; entity.EDITPOSTID = AppUser.PostID; FLOW_FLOWRECORDMASTER_TDAL.Add(con, entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 AddFlowRecord(con, entity, NextStateCode, AppUser.UserID); tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; return tmpDataResult; } #endregion FLOW_FLOWRECORDMASTER_TDAL.Add(con, entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 AddFlowRecord(con, entity, NextStateCode, AppUser.UserID); FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); //添加下一状态 entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; entity2.STATECODE = NextStateCode == "" ? SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE) : NextStateCode; entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;//entity.StateCode; //entity2.Content = "."; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; entity2.CREATEDATE = DateTime.Now; entity2.EDITUSERID = AppUser.UserID; entity2.EDITUSERNAME = AppUser.UserName; entity2.EDITCOMPANYID = AppUser.CompanyID; entity2.EDITDEPARTMENTID = AppUser.DepartmentID; entity2.EDITPOSTID = AppUser.PostID; entity2.EDITDATE = DateTime.Now; if (AgentUser != null) //如果启用了代理,把代理人信息写入 { entity2.AGENTUSERID = AgentUser.UserID; entity2.AGENTERNAME = AgentUser.UserName; entity2.AGENTEDITDATE = DateTime.Now; } tmpDataResult.AppState = entity2.STATECODE; if (entity2.STATECODE != "EndFlow") { AddFlowRecord(con, entity2, NextStateCode, AppUser.UserID);//对数据库操作 tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.CheckState = "2"; tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END } return tmpDataResult; #endregion } else { #region 更新流程 //如果NextStateCode为空则自动获取模型中的下一状态,如果不为空则使用传入状态代码,并使用传入下一任务人ID //更新本流程 entity = UpdateFlowRecord(con, entity, NextStateCode, AppUser.UserID);//对数据库操作 //添加下一状态 FLOW_FLOWRECORDDETAIL_T entity2 = new FLOW_FLOWRECORDDETAIL_T(); //添加下一状态 entity2.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); if (NextStateCode != "") { entity2.STATECODE = NextStateCode; //entity2.EditUserID = EditUserId; //entity2.EditUserName = EditUserName; } else { entity2.STATECODE = SMTWorkFlowManage.GetNextState(workflowRuntime, instance, entity.STATECODE); // entity2.EditUserID = entity2.StateCode=="EndFlow" ? "" : "EditUserId"; //根据状态查询权限表中用户ID } if (entity2.STATECODE == "EndFlow") { entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "2"; //设为终审通过 if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.AGENTUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.AGENTERNAME; } else //正常审核时 { entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = entity.EDITUSERID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = entity.EDITUSERNAME; } entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; UpdateFlowRecord(con, entity, NextStateCode, AppUser.UserID);//对数据库操作 FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T);//对数据库操作 } entity2.PARENTSTATEID = entity.FLOWRECORDDETAILID;// entity.StateCode; //entity2.Content = ""; entity2.FLAG = "0"; entity2.CHECKSTATE = "2"; entity2.CREATEPOSTID = entity.CREATEPOSTID; entity2.CREATECOMPANYID = entity.CREATECOMPANYID; entity2.CREATEDEPARTMENTID = entity.CREATEDEPARTMENTID; //if (entity.EDITDATE == entity.AGENTEDITDATE) //代理审核时 //{ // entity2.CREATEUSERID = entity.AGENTUSERID; // entity2.CREATEUSERNAME = entity.AGENTERNAME; //} //else //正常审核时 //{ entity2.CREATEUSERID = entity.EDITUSERID; entity2.CREATEUSERNAME = entity.EDITUSERNAME; //} entity2.EDITUSERID = AppUser.UserID; entity2.EDITUSERNAME = AppUser.UserName; entity2.EDITCOMPANYID = AppUser.CompanyID; entity2.EDITDEPARTMENTID = AppUser.DepartmentID; entity2.EDITPOSTID = AppUser.PostID; entity2.CREATEDATE = DateTime.Now; entity2.EDITDATE = DateTime.Now; if (AgentUser != null) //如果启用了代理,把代理人信息写入 { entity2.AGENTUSERID = AgentUser.UserID; entity2.AGENTERNAME = AgentUser.UserName; entity2.AGENTEDITDATE = DateTime.Now; } tmpDataResult.AppState = entity2.STATECODE; if (entity2.STATECODE != "EndFlow") { entity2.FLOW_FLOWRECORDMASTER_T = entity.FLOW_FLOWRECORDMASTER_T; AddFlowRecord(con, entity2, NextStateCode, AppUser.UserID);//对数据库操作 tmpDataResult.FlowResult = FlowResult.SUCCESS; tmpDataResult.CheckState = "1"; } else { tmpDataResult.FlowResult = FlowResult.END; //如果没有下一处理节点,则返回END tmpDataResult.CheckState = "2"; } return tmpDataResult; //如有下一节点,返回SUCCESS #endregion } } catch (Exception ex) { LogHelper.WriteLog("DoFlowRecord异常信息 :" + ex.ToString()); throw new Exception("DoFlowRecord:" + ex.InnerException + ex.Message); //tmpDataResult.FlowResult = FlowResult.FAIL; //tmpDataResult.Err = ex.Message; //return tmpDataResult; } }
/// <summary> /// 新增流程(对数据库操作) /// </summary> /// <param name="ApprovalData"></param> /// <param name="APPDataResult"></param> /// <returns></returns> public DataResult AddFlow2(OracleConnection con, SubmitData submitData, DataResult dataResult, ref string msg) { // WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; try { msg += "获取定义的流程" + DateTime.Now.ToString() + "\r\n"; #region 获取定义的流程 LogHelper.WriteLog("获取定义的流程.GetFlowByModelName:submitData.ApprovalUser.DepartmentID=" + submitData.ApprovalUser.DepartmentID + ";OrgType='" + ((int)submitData.FlowType).ToString() + "'"); List<FLOW_MODELFLOWRELATION_T> MODELFLOWRELATION = GetFlowByModelName(con, submitData.ApprovalUser.CompanyID, submitData.ApprovalUser.DepartmentID, submitData.ModelCode, ((int)submitData.FlowType).ToString());//对数据库操作 if (MODELFLOWRELATION == null || MODELFLOWRELATION.Count == 0) { dataResult.FlowResult = FlowResult.FAIL; dataResult.Err = "没有找到可使用的流程"; return dataResult; } msg += "获取定义的流程完成" + DateTime.Now.ToString() + "\r\n"; #endregion FLOW_MODELFLOWRELATION_T flowRelation = MODELFLOWRELATION[0]; FLOW_FLOWDEFINE_T flowDefine = flowRelation.FLOW_FLOWDEFINE_T; if (flowDefine.RULES != null && flowDefine.RULES.Trim() == "") { flowDefine.RULES = null; } //if (string.IsNullOrEmpty(flowDefine.RULES.Trim())) //{ // flowDefine.RULES = null; //} msg += " SMTWorkFlowManage.CreateWorkFlowRuntime(true)" + DateTime.Now.ToString() + "\r\n"; workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); instance = SMTWorkFlowManage.CreateWorkflowInstance(workflowRuntime, flowDefine.XOML, flowDefine.RULES); LogHelper.WriteLog("AddFlow2创建工作流实例ID=" + instance.InstanceId); workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { instance = null; }; msg += " SMTWorkFlowManage.CreateWorkFlowRuntime(true)完成" + DateTime.Now.ToString() + "\r\n"; #region master赋值 FLOW_FLOWRECORDMASTER_T master = new FLOW_FLOWRECORDMASTER_T(); master.INSTANCEID = instance.InstanceId.ToString(); master.BUSINESSOBJECT = submitData.XML; master.FORMID = submitData.FormID; master.MODELCODE = submitData.ModelCode; master.ACTIVEROLE = Utility.GetActiveRlue(flowDefine.LAYOUT); master.FLOWTYPE = ((int)submitData.FlowType).ToString(); master.FLOWSELECTTYPE = ((int)submitData.FlowSelectType).ToString(); master.FLOWCODE = flowDefine.FLOWCODE; #endregion #region 获取下一状态数据 msg += " 获取下一状态数据" + DateTime.Now.ToString() + "\r\n"; DateTime star = DateTime.Now; GetUserByFlow2(submitData.ApprovalUser.CompanyID, flowDefine.XOML, flowDefine.RULES, master.ACTIVEROLE, submitData.XML, submitData.ApprovalUser.UserID, submitData.ApprovalUser.PostID, submitData.FlowType, ref dataResult, ref msg); DateTime end = DateTime.Now; msg += " 获取下一状态数据完成" + DateTime.Now.ToString() + "\r\n"; string str = Service2.DateDiff(end, star); if (dataResult.FlowResult == FlowResult.FAIL) { return dataResult; } submitData.NextStateCode = dataResult.AppState; if (dataResult.IsCountersign) { #region if (dataResult.FlowResult == FlowResult.Countersign) { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.DictCounterUser = dataResult.DictCounterUser; } } #endregion } else { #region if (dataResult.FlowResult == FlowResult.MULTIUSER) { if (submitData.NextApprovalUser == null || (Utility.GetString(submitData.NextApprovalUser.UserID) == "" || Utility.GetString(submitData.NextApprovalUser.UserName) == "")) { return dataResult; } } else { if (submitData.DictCounterUser == null || submitData.DictCounterUser.Keys.Count == 0) { submitData.NextApprovalUser = dataResult.UserInfo[0]; } } #endregion } #endregion #region 实体赋值 FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); entity.FLOW_FLOWRECORDMASTER_T = master; entity.CREATECOMPANYID = submitData.ApprovalUser.CompanyID; entity.CREATEDEPARTMENTID = submitData.ApprovalUser.DepartmentID; entity.CREATEPOSTID = submitData.ApprovalUser.PostID; entity.CREATEUSERID = submitData.ApprovalUser.UserID; entity.CREATEUSERNAME = submitData.ApprovalUser.UserName; #endregion msg += " 处理kpi时间" + DateTime.Now.ToString() + "\r\n"; #region 处理kpi时间 string KPITime = ""; #region 加入缓存 string pscResult = CacheProvider.GetCache<string>(flowRelation.MODELFLOWRELATIONID); if (string.IsNullOrEmpty(pscResult)) { PerformanceServiceWS.PerformanceServiceClient psc = new PerformanceServiceWS.PerformanceServiceClient(); pscResult = psc.GetKPIPointsByBusinessCode(flowRelation.MODELFLOWRELATIONID);//调用服务 CacheProvider.Add<string>(flowRelation.MODELFLOWRELATIONID, pscResult); psc.Close(); } #endregion //PerformanceServiceWS.PerformanceServiceClient psc = new PerformanceServiceWS.PerformanceServiceClient(); //string pscResult = psc.GetKPIPointsByBusinessCode(flowRelation.MODELFLOWRELATIONID);//调用服务 //psc.Close(); if (!string.IsNullOrEmpty(pscResult)) { XElement xe = XElement.Parse(pscResult); Func<XElement, bool> f = (x) => { XAttribute xid = x.Attribute("id"); XAttribute xvalue = x.Attribute("value"); if (xid == null || xvalue == null) return false; else { if (xid.Value == dataResult.AppState) return true; else return false; } }; XElement FlowNode = xe.Elements("FlowNode").FirstOrDefault(f); if (FlowNode != null) { KPITime = FlowNode.Attribute("value").Value; } } dataResult.KPITime = KPITime; master.KPITIMEXML = pscResult; #endregion msg += " 处理kpi时间完成" + DateTime.Now.ToString() + "\r\n"; FlowDataType.FlowData FlowData = new FlowDataType.FlowData(); FlowData.xml = submitData.XML; if (!dataResult.IsCountersign) { #region 非会签 UserInfo AppUser = new UserInfo(); //下一审核人 AppUser = submitData.NextApprovalUser; dataResult.UserInfo.Clear(); dataResult.UserInfo.Add(AppUser); UserInfo AgentAppUser = GetAgentUserInfo(submitData.ModelCode, AppUser.UserID);//查询是否启用了代理人 dataResult = DoFlowRecord2(con, workflowRuntime, instance, entity, submitData.NextStateCode, AppUser, AgentAppUser, submitData.SubmitFlag, submitData.FlowType); //处理流程数据 dataResult.IsCountersign = false; dataResult.AgentUserInfo = AgentAppUser; #endregion } else { msg += " 会签" + DateTime.Now.ToString() + "\r\n"; #region 会签 //Tracer.Debug("-----DoFlowRecord_Add:" + DateTime.Now.ToString()+"\n"); dataResult.DictCounterUser = submitData.DictCounterUser; Dictionary<UserInfo, UserInfo> dictAgentUserInfo = GetAgentUserInfo2(submitData.ModelCode, submitData.DictCounterUser); dataResult = DoFlowRecord_Add(con, workflowRuntime, instance, entity, submitData.NextStateCode, submitData.DictCounterUser, dictAgentUserInfo, submitData.SubmitFlag, submitData.FlowType); //处理流程数据 //Tracer.Debug("-----DoFlowRecord_AddEnd:" + DateTime.Now.ToString()+"\n"); dataResult.IsCountersign = true; dataResult.DictAgentUserInfo = dictAgentUserInfo; #endregion msg += "会签完成" + DateTime.Now.ToString() + "\r\n"; } msg += "激发流程引擎执行到一下流程" + DateTime.Now.ToString() + "\r\n"; #region 激发流程引擎执行到一下流程 string ss = ""; int n = 0; if (dataResult.AppState == null || dataResult.AppState == "") { msg += " workflowRuntime.GetService<FlowEvent>()" + DateTime.Now.ToString() + "\r\n"; workflowRuntime.GetService<FlowEvent>().OnDoFlow(instance.InstanceId, FlowData); //激发流程引擎执行到一下流程 msg += " workflowRuntime.GetService<FlowEvent>()完成" + DateTime.Now.ToString() + "\r\n"; } else { StateMachineWorkflowInstance workflowinstance = new StateMachineWorkflowInstance(workflowRuntime, instance.InstanceId); workflowinstance.SetState(dataResult.AppState); //流程跳转到指定节点 while (true) { ss += (n++).ToString() + "|" + workflowinstance.CurrentStateName + "\r\n"; string stateName = workflowinstance.CurrentStateName; if (stateName != null && stateName.ToUpper().IndexOf("STATE") >= 0) { break; } } } #endregion msg += "激发流程引擎执行到一下流程完成" + DateTime.Now.ToString() + "\r\n"; msg += "System.Threading.Thread.Sleep(1000)" + DateTime.Now.ToString() + "\r\n"; //System.Threading.Thread.Sleep(1000);//当前用到 dataResult.ModelFlowRelationID = flowRelation.MODELFLOWRELATIONID; //返回关联ID dataResult.KPITime = KPITime; //dataResult.CanSendMessage = true; if (submitData.FlowType == FlowType.Task) { dataResult.SubModelCode = Utility.GetSubModelCode(master.ACTIVEROLE, dataResult.AppState); //返回下一子模块代码 } msg += "System.Threading.Thread.Sleep(1000)完成" + DateTime.Now.ToString() + "\r\n"; return dataResult; } catch (Exception e) { throw new Exception(e.Message); } finally { instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(workflowRuntime); } }
private bool GetUser(OracleConnection con, string OptFlag, string Xoml, string Rules, string xml, ref DataResult DataResult) { try { WorkflowRuntime WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); WorkflowInstance Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); LogHelper.WriteLog("GetUser(try)下根据模型文件创建工作流实例(完成) ID=" + Instance.InstanceId); string strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, "StartFlow", xml); } catch (Exception ex) { } finally { } return true; }
public DataResult CancelFlow(SubmitData submitData, DataResult dataResult, List<FLOW_FLOWRECORDDETAIL_T> fd) { //WorkflowRuntime workflowRuntime = null; WorkflowInstance instance = null; FLOW_FLOWRECORDDETAIL_T entity = new FLOW_FLOWRECORDDETAIL_T(); #region entity.FLOWRECORDDETAILID = Guid.NewGuid().ToString(); entity.CREATECOMPANYID = submitData.ApprovalUser.CompanyID; entity.CREATEDEPARTMENTID = submitData.ApprovalUser.DepartmentID; entity.CREATEPOSTID = submitData.ApprovalUser.PostID; entity.CREATEUSERID = submitData.ApprovalUser.UserID; entity.CREATEUSERNAME = submitData.ApprovalUser.UserName; entity.EDITDATE = DateTime.Now; entity.CONTENT = submitData.ApprovalContent; entity.CHECKSTATE = "9"; entity.STATECODE = "Cancel"; entity.FLAG = "1"; entity.PARENTSTATEID = entity.FLOWRECORDDETAILID; entity.CREATEDATE = DateTime.Now; entity.EDITDATE = DateTime.Now; entity.EDITUSERID = entity.CREATEUSERID; entity.EDITUSERNAME = entity.CREATEUSERNAME; entity.EDITCOMPANYID = entity.CREATECOMPANYID; entity.EDITDEPARTMENTID = entity.CREATEDEPARTMENTID; entity.EDITPOSTID = entity.CREATEPOSTID; entity.FLOW_FLOWRECORDMASTER_T = fd[0].FLOW_FLOWRECORDMASTER_T; entity.FLOW_FLOWRECORDMASTER_T.FLOW_FLOWRECORDDETAIL_T.Add(entity); entity.FLOW_FLOWRECORDMASTER_T.CHECKSTATE = "9"; //设为撤销 entity.FLOW_FLOWRECORDMASTER_T.EDITUSERID = submitData.ApprovalUser.UserID; entity.FLOW_FLOWRECORDMASTER_T.EDITUSERNAME = submitData.ApprovalUser.UserName; entity.FLOW_FLOWRECORDMASTER_T.EDITDATE = DateTime.Now; #endregion workflowRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(true); LogHelper.WriteLog("CancelFlow从持久化库在恢复创建工作流实例ID=" + entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID); instance = SMTWorkFlowManage.GetWorkflowInstance(workflowRuntime, entity.FLOW_FLOWRECORDMASTER_T.INSTANCEID); instance.Terminate("0"); FLOW_FLOWRECORDDETAIL_TDAL Dal = new FLOW_FLOWRECORDDETAIL_TDAL(); entity.FLAG = "1"; //Dal.AddFlowRecord(entity); FLOW_FLOWRECORDDETAIL_TDAL.Add(entity); FLOW_FLOWRECORDMASTER_TDAL.Update(entity.FLOW_FLOWRECORDMASTER_T); fd.Where(detail => detail.FLAG == "0").ToList().ForEach(item => { //Dal.Delete(item); //Dal.DeleteFlowRecord(item); FLOW_FLOWRECORDDETAIL_TDAL.Delete(item); }); dataResult.CheckState = "9";// dataResult.FlowResult = FlowResult.SUCCESS; return dataResult; }
/// <summary> /// 发送审批消息(调用引擎服务) /// </summary> /// <param name="submitData"></param> /// <param name="dataResult"></param> /// <param name="modelinfo"></param> /// <param name="CheckFlowResult"></param> /// <param name="Flowbill"></param> /// <param name="AppCompanyID">申请公司</param> /// <param name="MessageUserID">申请人ID</param> /// <param name="MessageUserName">申请人名</param> private void SubmitEngineService(OracleConnection con, SubmitData submitData, DataResult dataResult, ModelInfo modelinfo, CheckResult CheckFlowResult, FlowBLL2 Flowbill, string AppCompanyID, string MessageUserID, string MessageUserName, ref string ErroMessage) { bool bOK = true; #region 发送审批消息(调用引擎服务) try { if (dataResult.FlowResult == FlowResult.SUCCESS || dataResult.FlowResult == FlowResult.END) { #region 调用引擎服务(原有调用WCF服务) ////EngineWcfGlobalFunctionService.EngineWcfGlobalFunctionClient engineClient = new EngineWcfGlobalFunctionService.EngineWcfGlobalFunctionClient();//旧引擎服务 //FlowEngineService.EngineWcfGlobalFunctionClient FlowEngine = new FlowEngineService.EngineWcfGlobalFunctionClient(); //string IsTask = dataResult.FlowResult == FlowResult.SUCCESS ? "1" : "0"; //MessageData tmpMessageData = null; //StringBuilder FlowResultXml = null; //#region //switch (submitData.SubmitFlag) //{ // case SubmitFlag.New: // #region 新增 // if (dataResult.IsCountersign) // { // #region // if (dataResult.FlowResult == FlowResult.SUCCESS) // { // List<string> listUserID = new List<string>(); // List<string> listUserName = new List<string>(); // if (dataResult.DictCounterUser != null && dataResult.DictCounterUser.Keys.Count > 0) // { // dataResult.DictCounterUser.Values.ToList().ForEach(users => // { // users.ForEach(user => // { // listUserID.Add(user.UserID); // listUserName.Add(user.UserName); // }); // }); // MessageUserID = string.Join("|", listUserID); // MessageUserName = string.Join("|", listUserName); // } // } // if (dataResult.DictAgentUserInfo != null && dataResult.DictAgentUserInfo.Count > 0) // { // dataResult.DictAgentUserInfo.Values.ToList().ForEach(user => // { // MessageUserID += "|" + user.UserID.Trim(); // MessageUserName += "|" + user.UserName.Trim(); // }); // } // #endregion // } // else // { // #region // if (dataResult.FlowResult == FlowResult.SUCCESS) // { // MessageUserID = dataResult.UserInfo[0].UserID.Trim(); // MessageUserName = dataResult.UserInfo[0].UserName.Trim(); // } // if (dataResult.AgentUserInfo != null) // { // MessageUserID += "|" + dataResult.AgentUserInfo.UserID.Trim(); // MessageUserName += "|" + dataResult.AgentUserInfo.UserName.Trim(); // } // #endregion // } // tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, // submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); // FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); // DateTime s = DateTime.Now; // LogHelper.WriteLog("开始新增FlowEngine.SaveFlowTriggerData"); // bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // LogHelper.WriteLog("bOK=" + bOK.ToString()); // LogHelper.WriteLog("结束新增FlowEngine.SaveFlowTriggerData"); // //bOK = engineClient.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // DateTime e = DateTime.Now; // string str = DateDiff(e, s); // if (!bOK) // { // Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); // } // #endregion // break; // case SubmitFlag.Cancel: // #region 撤单 // tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, // submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); // FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); // LogHelper.WriteLog("开始撤单FlowEngine.FlowCancel"); // bool bCancel = FlowEngine.FlowCancel(FlowResultXml.ToString(), submitData.XML); // LogHelper.WriteLog("bCancel=" + bCancel.ToString()); // LogHelper.WriteLog("结束撤单FlowEngine.FlowCancel"); // //bool bCancel = engineClient.FlowCancel(FlowResultXml.ToString(), submitData.XML); // if (!bCancel) // { // Tracer.Debug("FlowEngineService:DateTime:" + DateTime.Now.ToString() + "\n" + "FlowCancel:submitData.XML" + "\n\nFlowResultXml" + FlowResultXml.ToString()); // } // #endregion // break; // case SubmitFlag.Approval: // LogHelper.WriteLog("开始审核"); // #region 审核 // if (dataResult.CurrentIsCountersign) // { // LogHelper.WriteLog("第1次:TaskMsgClose"); // FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); // //engineClient.TaskMsgClose(modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); // //einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); // #region // if (submitData.ApprovalResult == ApprovalResult.NoPass) // { // #region // List<string> listMessageUserID = new List<string>(); // CheckFlowResult.fd.Where(detail => detail.EDITUSERID != submitData.ApprovalUser.UserID).ToList().ForEach(item => // { // listMessageUserID.Add(item.EDITUSERID); // if (!string.IsNullOrEmpty(item.AGENTUSERID)) // { // listMessageUserID.Add(item.AGENTUSERID); // } // }); // if (listMessageUserID.Count > 0) // { // string messageUserID = string.Join(",", listMessageUserID); // LogHelper.WriteLog("第2次:TaskMsgClose"); // FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, messageUserID); // //engineClient.TaskMsgClose(modelinfo.SysCode, submitData.FormID, messageUserID); // //einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, messageUserID); // } // tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, // submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); // FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); // DateTime s2 = DateTime.Now; // bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // //bOK = engineClient.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // // bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML); // DateTime e2 = DateTime.Now; // string str2 = DateDiff(e2, s2); // if (!bOK) // { // Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); // } // #endregion // } // else if (dataResult.IsGotoNextState) // { // #region // List<string> listMessageUserID = new List<string>(); // CheckFlowResult.fd.Where(detail => detail.EDITUSERID != submitData.ApprovalUser.UserID).ToList().ForEach(item => // { // listMessageUserID.Add(item.EDITUSERID); // if (!string.IsNullOrEmpty(item.AGENTUSERID)) // { // listMessageUserID.Add(item.AGENTUSERID); // } // }); // if (listMessageUserID.Count > 0) // { // string messageUserID = string.Join(",", listMessageUserID); // LogHelper.WriteLog("第3次:TaskMsgClose"); // FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, messageUserID); // //engineClient.TaskMsgClose(modelinfo.SysCode, submitData.FormID, messageUserID); // //einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, messageUserID); // } // if (dataResult.IsCountersign) // { // #region // if (dataResult.FlowResult == FlowResult.SUCCESS) // { // List<string> listUserID = new List<string>(); // List<string> listUserName = new List<string>(); // if (dataResult.DictCounterUser != null && dataResult.DictCounterUser.Keys.Count > 0) // { // dataResult.DictCounterUser.Values.ToList().ForEach(users => // { // users.ForEach(user => // { // listUserID.Add(user.UserID); // listUserName.Add(user.UserName); // }); // }); // MessageUserID = string.Join("|", listUserID); // MessageUserName = string.Join("|", listUserName); // } // } // if (dataResult.DictAgentUserInfo != null && dataResult.DictAgentUserInfo.Count > 0) // { // dataResult.DictAgentUserInfo.Values.ToList().ForEach(user => // { // MessageUserID += "|" + user.UserID.Trim(); // MessageUserName += "|" + user.UserName.Trim(); // }); // } // #endregion // } // else // { // #region // if (dataResult.FlowResult == FlowResult.SUCCESS) // { // MessageUserID = dataResult.UserInfo[0].UserID.Trim(); // MessageUserName = dataResult.UserInfo[0].UserName.Trim(); // } // if (dataResult.AgentUserInfo != null) // { // MessageUserID += "|" + dataResult.AgentUserInfo.UserID.Trim(); // MessageUserName += "|" + dataResult.AgentUserInfo.UserName.Trim(); // } // #endregion // } // tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, // submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); // FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); // DateTime s3 = DateTime.Now; // bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // //bOK = engineClient.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // //bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML); // DateTime e3 = DateTime.Now; // string str3 = DateDiff(e3, s3); // if (!bOK) // { // Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); // } // #endregion // } // #endregion // } // else // { // #region // if (dataResult.IsCountersign) // { // #region // if (dataResult.FlowResult == FlowResult.SUCCESS) // { // List<string> listUserID = new List<string>(); // List<string> listUserName = new List<string>(); // if (dataResult.DictCounterUser != null && dataResult.DictCounterUser.Keys.Count > 0) // { // dataResult.DictCounterUser.Values.ToList().ForEach(users => // { // users.ForEach(user => // { // listUserID.Add(user.UserID); // listUserName.Add(user.UserName); // }); // }); // MessageUserID = string.Join("|", listUserID); // MessageUserName = string.Join("|", listUserName); // } // } // if (dataResult.DictAgentUserInfo != null && dataResult.DictAgentUserInfo.Count > 0) // { // dataResult.DictAgentUserInfo.Values.ToList().ForEach(user => // { // MessageUserID += "|" + user.UserID.Trim(); // MessageUserName += "|" + user.UserName.Trim(); // }); // } // #endregion // } // else // { // #region // if (dataResult.FlowResult == FlowResult.SUCCESS) // { // MessageUserID = dataResult.UserInfo[0].UserID.Trim(); // MessageUserName = dataResult.UserInfo[0].UserName.Trim(); // } // if (dataResult.AgentUserInfo != null) // { // MessageUserID += "|" + dataResult.AgentUserInfo.UserID.Trim(); // MessageUserName += "|" + dataResult.AgentUserInfo.UserName.Trim(); // } // #endregion // } // tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, // submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); // FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); // DateTime s4 = DateTime.Now; // LogHelper.WriteLog("开始FlowEngine.SaveFlowTriggerData"); // bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // LogHelper.WriteLog("bOK=" + bOK.ToString()); // LogHelper.WriteLog("结束FlowEngine.SaveFlowTriggerData"); // //bOK = engineClient.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); // //bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML); // DateTime e4 = DateTime.Now; // string str4 = DateDiff(e4, s4); // if (!bOK) // { // Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); // } // else // { // LogHelper.WriteLog("第4次:TaskMsgClose"); // FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); // //engineClient.TaskMsgClose(modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); // //einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); // } // #endregion // } // #endregion // LogHelper.WriteLog("结束审核"); // break; //} //#endregion #endregion 调用引擎服务(原有调用WCF服务) #region 调用引擎服务(调用本地服DLL) string IsTask = dataResult.FlowResult == FlowResult.SUCCESS ? "1" : "0"; MessageData tmpMessageData = null; StringBuilder FlowResultXml = null; #region switch (submitData.SubmitFlag) { case SubmitFlag.New: #region 新增 if (dataResult.IsCountersign) { #region if (dataResult.FlowResult == FlowResult.SUCCESS) { List<string> listUserID = new List<string>(); List<string> listUserName = new List<string>(); if (dataResult.DictCounterUser != null && dataResult.DictCounterUser.Keys.Count > 0) { dataResult.DictCounterUser.Values.ToList().ForEach(users => { users.ForEach(user => { listUserID.Add(user.UserID); listUserName.Add(user.UserName); }); }); MessageUserID = string.Join("|", listUserID); MessageUserName = string.Join("|", listUserName); } } if (dataResult.DictAgentUserInfo != null && dataResult.DictAgentUserInfo.Count > 0) { dataResult.DictAgentUserInfo.Values.ToList().ForEach(user => { MessageUserID += "|" + user.UserID.Trim(); MessageUserName += "|" + user.UserName.Trim(); }); } #endregion } else { #region if (dataResult.FlowResult == FlowResult.SUCCESS) { MessageUserID = dataResult.UserInfo[0].UserID.Trim(); MessageUserName = dataResult.UserInfo[0].UserName.Trim(); } if (dataResult.AgentUserInfo != null) { MessageUserID += "|" + dataResult.AgentUserInfo.UserID.Trim(); MessageUserName += "|" + dataResult.AgentUserInfo.UserName.Trim(); } #endregion } tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); LogHelper.WriteLog("开始新增FlowEngine.SaveFlowTriggerData"); LogHelper.WriteLog("流程引擎的XML数据", "新增: FormID=" + submitData.FormID + ";SysCode=" + modelinfo.SysCode + " ModelName=" + modelinfo.ModelName + "\r\n FlowResultXml= \r\n" + FlowResultXml + "\r\n submitData.XML= \r\n" + submitData.XML); bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML, ref ErroMessage); LogHelper.WriteLog("bOK=" + bOK.ToString()); LogHelper.WriteLog("结束新增FlowEngine.SaveFlowTriggerData"); if (!bOK) { Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); } #endregion break; case SubmitFlag.Cancel: #region 撤单 tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); //bool bCancel = FlowEngine.FlowCancel(FlowResultXml.ToString(), submitData.XML); LogHelper.WriteLog("流程引擎的XML数据", "撤单: FormID=" + submitData.FormID + ";SysCode=" + modelinfo.SysCode + " ModelName=" + modelinfo.ModelName + "\r\n FlowResultXml= \r\n" + FlowResultXml + "\r\n submitData.XML= \r\n" + submitData.XML); bool bCancel = einginBll.FlowCancel(con, FlowResultXml.ToString(), submitData.XML, ref ErroMessage); if (!bCancel) { Tracer.Debug("FlowEngineService:DateTime:" + DateTime.Now.ToString() + "\n" + "FlowCancel:submitData.XML" + "\n\nFlowResultXml" + FlowResultXml.ToString()); } #endregion break; case SubmitFlag.Approval: #region 审核 //FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, submitData.ApprovalUser.UserID); if (dataResult.CurrentIsCountersign) { #region if (submitData.ApprovalResult == ApprovalResult.NoPass) { #region List<string> listMessageUserID = new List<string>(); CheckFlowResult.fd.Where(detail => detail.EDITUSERID != submitData.ApprovalUser.UserID).ToList().ForEach(item => { listMessageUserID.Add(item.EDITUSERID); if (!string.IsNullOrEmpty(item.AGENTUSERID)) { listMessageUserID.Add(item.AGENTUSERID); } }); if (listMessageUserID.Count > 0) { string messageUserID = string.Join(",", listMessageUserID); //FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, messageUserID); einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, messageUserID); } tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); //bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); LogHelper.WriteLog("开始审核FlowEngine.SaveFlowTriggerData"); LogHelper.WriteLog("流程引擎的XML数据", "审核: FormID=" + submitData.FormID + ";SysCode=" + modelinfo.SysCode + " ModelName=" + modelinfo.ModelName + "\r\n FlowResultXml= \r\n" + FlowResultXml + "\r\n submitData.XML= \r\n" + submitData.XML); bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML, ref ErroMessage); LogHelper.WriteLog("bOK=" + bOK.ToString()); LogHelper.WriteLog("结束审核FlowEngine.SaveFlowTriggerData"); if (!bOK) { Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); } #endregion } else if (dataResult.IsGotoNextState) { #region List<string> listMessageUserID = new List<string>(); CheckFlowResult.fd.Where(detail => detail.EDITUSERID != submitData.ApprovalUser.UserID).ToList().ForEach(item => { listMessageUserID.Add(item.EDITUSERID); if (!string.IsNullOrEmpty(item.AGENTUSERID)) { listMessageUserID.Add(item.AGENTUSERID); } }); if (listMessageUserID.Count > 0) { string messageUserID = string.Join(",", listMessageUserID); // FlowEngine.TaskMsgClose(modelinfo.SysCode, submitData.FormID, messageUserID); einginBll.TaskMsgClose(con, modelinfo.SysCode, submitData.FormID, messageUserID); } if (dataResult.IsCountersign) { #region if (dataResult.FlowResult == FlowResult.SUCCESS) { List<string> listUserID = new List<string>(); List<string> listUserName = new List<string>(); if (dataResult.DictCounterUser != null && dataResult.DictCounterUser.Keys.Count > 0) { dataResult.DictCounterUser.Values.ToList().ForEach(users => { users.ForEach(user => { listUserID.Add(user.UserID); listUserName.Add(user.UserName); }); }); MessageUserID = string.Join("|", listUserID); MessageUserName = string.Join("|", listUserName); } } if (dataResult.DictAgentUserInfo != null && dataResult.DictAgentUserInfo.Count > 0) { dataResult.DictAgentUserInfo.Values.ToList().ForEach(user => { MessageUserID += "|" + user.UserID.Trim(); MessageUserName += "|" + user.UserName.Trim(); }); } #endregion } else { #region if (dataResult.FlowResult == FlowResult.SUCCESS) { MessageUserID = dataResult.UserInfo[0].UserID.Trim(); MessageUserName = dataResult.UserInfo[0].UserName.Trim(); } if (dataResult.AgentUserInfo != null) { MessageUserID += "|" + dataResult.AgentUserInfo.UserID.Trim(); MessageUserName += "|" + dataResult.AgentUserInfo.UserName.Trim(); } #endregion } tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); //bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); DateTime s3 = DateTime.Now; bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML, ref ErroMessage); DateTime e3 = DateTime.Now; string str3 = DateDiff(e3, s3); if (!bOK) { Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); } #endregion } #endregion } else { #region if (dataResult.IsCountersign) { #region if (dataResult.FlowResult == FlowResult.SUCCESS) { List<string> listUserID = new List<string>(); List<string> listUserName = new List<string>(); if (dataResult.DictCounterUser != null && dataResult.DictCounterUser.Keys.Count > 0) { dataResult.DictCounterUser.Values.ToList().ForEach(users => { users.ForEach(user => { listUserID.Add(user.UserID); listUserName.Add(user.UserName); }); }); MessageUserID = string.Join("|", listUserID); MessageUserName = string.Join("|", listUserName); } } if (dataResult.DictAgentUserInfo != null && dataResult.DictAgentUserInfo.Count > 0) { dataResult.DictAgentUserInfo.Values.ToList().ForEach(user => { MessageUserID += "|" + user.UserID.Trim(); MessageUserName += "|" + user.UserName.Trim(); }); } #endregion } else { #region if (dataResult.FlowResult == FlowResult.SUCCESS) { MessageUserID = dataResult.UserInfo[0].UserID.Trim(); MessageUserName = dataResult.UserInfo[0].UserName.Trim(); } if (dataResult.AgentUserInfo != null) { MessageUserID += "|" + dataResult.AgentUserInfo.UserID.Trim(); MessageUserName += "|" + dataResult.AgentUserInfo.UserName.Trim(); } #endregion } tmpMessageData = new MessageData("Flow", modelinfo.SysCode, AppCompanyID, submitData.ModelCode, modelinfo.ModelName, submitData.FormID, dataResult.AppState, dataResult.CheckState, IsTask, MessageUserID, MessageUserName, dataResult.KPITime); FlowResultXml = Flowbill.BuildMessageData(tmpMessageData); // bOK = FlowEngine.SaveFlowTriggerData(FlowResultXml.ToString(), submitData.XML); DateTime s4 = DateTime.Now; bOK = einginBll.SaveFlowTriggerData(con, FlowResultXml.ToString(), submitData.XML, ref ErroMessage); DateTime e4 = DateTime.Now; string str4 = DateDiff(e4, s4); if (!bOK) { Tracer.Debug("FlowEngineService:FormID-" + submitData.FormID + "--submitDataXML:" + submitData.XML); } #endregion } #endregion break; } #endregion #endregion 调用引擎服务(调用本地服DLL) } } catch (Exception ex) { //Tracer.Debug("FlowEngineService: -" + "\n\nError:" + ex.InnerException + ex.Message); LogHelper.WriteLog(this, "SubmitEngineService", "", ex); throw new Exception(ErroMessage); } #endregion }
/// <summary> /// 通过流程查找审核人 /// </summary> /// <param name="Xoml"></param> /// <param name="Rules"></param> /// <param name="xml"></param> /// <param name="UserID"></param> /// <param name="DataResult"></param> //public void GetUserByFlow(string Xoml, string Rules, string xml, string UserID, ref DataResult DataResult) //{ // WorkflowRuntime WfRuntime = null; // WorkflowInstance Instance = null; // try // { // WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); // Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); // string strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, "StartFlow", xml); // List<UserInfo> AppUserInfo = GetUserByStateCode(strNextState, UserID); // if (AppUserInfo == null || AppUserInfo.Count == 0) // { // DataResult.Err = "没有找到审核人"; // DataResult.FlowResult = FlowResult.FAIL; // } // else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 // { // DataResult.FlowResult = FlowResult.MULTIUSER; // } // DataResult.UserInfo = AppUserInfo; // } // catch (Exception ex) // { // throw new Exception(ex.Message); // } // finally // { // Instance = null; // SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); // } //} #endregion #region 通过流程查找审核人(对应SubmitFlow) /// <summary> /// 通过流程查找审核人(对应SubmitFlow) /// </summary> /// <param name="Xoml"></param> /// <param name="Rules"></param> /// <param name="Layout"></param> /// <param name="xml"></param> /// <param name="UserID"></param> /// <param name="FlowType"></param> /// <param name="DataResult"></param> public void GetUserByFlow(string companyID,string Xoml, string Rules, string Layout, string xml, string UserID, string PostID, FlowType FlowType, ref DataResult DataResult) { WorkflowRuntime WfRuntime = null; WorkflowInstance Instance = null; string strCurrState = "StartFlow"; string strNextState = "StartFlow"; Role_UserType RuleName; List<UserInfo> AppUserInfo = null; try { WfRuntime = SMTWorkFlowManage.CreateWorkFlowRuntime(false); Instance = SMTWorkFlowManage.CreateWorkflowInstance(WfRuntime, Xoml, Rules); bool iscurruser = true; while (iscurruser) { strCurrState = strNextState; strNextState = SMTWorkFlowManage.GetNextStateByEvent(WfRuntime, Instance, strNextState, xml); if (strNextState == "EndFlow") { strNextState = strCurrState; iscurruser = false; } else { RuleName = Utility.GetRlueName(Layout, strNextState); if (RuleName == null) { DataResult.Err = "没有找到对应角色"; DataResult.FlowResult = FlowResult.FAIL; return; } bool isHigher = false; AppUserInfo = GetUserByStateCode(RuleName.RoleName, UserID, PostID,ref isHigher); #region beyond if (!isHigher&& RuleName.IsOtherCompany != null) { if (RuleName.IsOtherCompany.Value==true) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == RuleName.OtherCompanyID).ToList(); } else if(RuleName.IsOtherCompany.Value==false) { AppUserInfo = AppUserInfo.Where(user => user.CompanyID == companyID).ToList(); } } #endregion if (AppUserInfo == null || AppUserInfo.Count == 0) { DataResult.Err = "没有找到审核人"; DataResult.FlowResult = FlowResult.FAIL; return; } if (AppUserInfo.Where(c => c.UserID == UserID).Count() == 0) iscurruser = false; } } //if (AppUserInfo == null || AppUserInfo.Count == 0) //{ // DataResult.Err = "没有找到审核人"; // DataResult.FlowResult = FlowResult.FAIL; //} // else if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 if (AppUserInfo.Count > 1) //处理角色对应多个用户,返回用户集给提交人,选择一个处理人 { DataResult.FlowResult = FlowResult.MULTIUSER; } DataResult.AppState = strNextState; DataResult.UserInfo = AppUserInfo; } catch (Exception ex) { throw new Exception("GetUserByFlow:" + ex.Message); } finally { strCurrState = null; strNextState = null; RuleName = null; AppUserInfo = null; Instance = null; SMTWorkFlowManage.ColseWorkFlowRuntime(WfRuntime); } }