/// <summary> /// 插入并行环节 /// </summary> /// <param name="formId">票单号</param> /// <param name="supportInfo">支持人ID>、支持组ID</param> /// <param name="instanceEntity"> </param> /// <param name="currentDealPerson">当前处理人(id,name)</param> /// <returns></returns> public static bool InsertParallelStates(Guid formId, Dictionary<string, string> supportInfo, WfInstanceEntity instanceEntity, out Dictionary<string, string> currentDealPerson) { currentDealPerson = new Dictionary<string, string>(); try { var result = false; if (supportInfo != null && supportInfo.Count > 0) { // var instanceEntity = WfInstanceBusiness.GetWfInstanceBusinessByFormID(formId); foreach (KeyValuePair<string, string> support in supportInfo) { var supportGroup = WfSupportGroupBusiness.GetWfSupportGroup(new Guid(support.Value)); var stateEntity = WfInstanceStatesBusiness.GetLastWfInstanceStateByFormID(formId); var supportEntity = WfSupportGroupMembersBusiness.GetEntity(new Guid(support.Value), support.Key); var instanceState = new WfInstanceStatesEntity(); instanceState.ID = Guid.NewGuid(); instanceState.InstanceID = instanceEntity.InstanceID; instanceState.FormID = formId; instanceState.RunState = instanceEntity.CurrentRunState; instanceState.WfState = instanceEntity.CurrentWfState; // instanceState.WfDealWayId = Guid.Empty; instanceState.TransactType = string.Empty; instanceState.StateDescription = string.Empty; instanceState.DealPersonLevel = supportGroup.SupportGroupLevel; // stateEntity.DealDeptLevel = supportGroup.; instanceState.TransactUserID = Guid.Parse(support.Key); instanceState.TransactUserName = supportEntity.GroupMemberName; instanceState.TransactDepartmentID = Guid.Parse(supportGroup.DepartmentID); instanceState.TransactDepartmentName = supportGroup.DepartmentName; // stateEntity.TransactDepartmentName = supportGroup.; instanceState.CreateTime = stateEntity.CompleteTime; // instanceState.CompleteTime = DateTime.MinValue; instanceState.IsDeleted = false; instanceState.BlankCol1 = string.Empty; instanceState.BlankCol2 = string.Empty; instanceState.BlankCol3 = string.Empty; instanceState.BlankCol4 = string.Empty; currentDealPerson.Add(instanceState.TransactUserID.ToString(), instanceState.TransactUserName); result = WfInstanceStatesBusiness.Add(instanceState); } } return result; } catch (Exception exception) { LogWritter.WriteSystemExceptionLog(exception); return false; } }
/// <summary> /// 获取实体信息 /// </summary> /// <param name="row">数据行</param> /// <returns></returns> public static WfInstanceEntity GetEntity(DataRow row) { WfInstanceEntity entity = new WfInstanceEntity(); if (row["InstanceID"] != DBNull.Value) entity.InstanceID = Guid.Parse(row["InstanceID"].ToString()); if (row["TemplateID"] != DBNull.Value) entity.TemplateID = Guid.Parse(row["TemplateID"].ToString()); if (row["FormID"] != DBNull.Value) entity.FormID = Guid.Parse(row["FormID"].ToString()); if (row["StartUserID"] != DBNull.Value) entity.StartUserID = Guid.Parse(row["StartUserID"].ToString()); entity.StartUserName = row["StartUserName"].ToString(); if (row["StartDepartmentID"] != DBNull.Value) entity.StartDepartmentID = Guid.Parse(row["StartDepartmentID"].ToString()); entity.StartDepartmentName = row["StartDepartmentName"].ToString(); if (row["StartPreMapDeptID"] != DBNull.Value) entity.StartPreMapDeptID = Guid.Parse(row["StartPreMapDeptID"].ToString()); entity.StartPreMapDeptName = row["StartPreMapDeptName"].ToString(); entity.StartPreMapDeptAllPathName = row["StartPreMapDeptAllPathName"].ToString(); if (row["StartTime"] != DBNull.Value) entity.StartTime = Convert.ToDateTime(row["StartTime"]); entity.CurrentRunState = row["CurrentRunState"].ToString(); if (row["CurrentWfState"] != DBNull.Value) entity.CurrentWfState = Guid.Parse(row["CurrentWfState"].ToString()); if (row["CurrentDealDeptLevel"] != DBNull.Value) entity.CurrentDealDeptLevel = Convert.ToInt32(row["CurrentDealDeptLevel"]); if (row["CurrentDealPersonLevel"] != DBNull.Value) entity.CurrentDealPersonLevel = Convert.ToInt32(row["CurrentDealPersonLevel"]); entity.CurrentDealPersonID = row["CurrentDealPersonID"].ToString(); entity.CurrentDealPersonName = row["CurrentDealPersonName"].ToString(); entity.CurrentDealDeptId = row["CurrentDealDeptId"].ToString(); entity.CurrentDealDeptName = row["CurrentDealDeptName"].ToString(); if (row["CompleteTime"] != DBNull.Value) entity.CompleteTime = Convert.ToDateTime(row["CompleteTime"]); if (row["IsDeleted"] != DBNull.Value) entity.IsDeleted = Convert.ToBoolean(row["IsDeleted"]); if (row["CurrentStateType"] != DBNull.Value) entity.CurrentStateType = Convert.ToInt32(row["CurrentStateType"]); if (row["CurrentParallelCount"] != DBNull.Value) entity.CurrentParallelCount = Convert.ToInt32(row["CurrentParallelCount"]); if (row["TemBusiRelationId"] != DBNull.Value) entity.TemBusiRelationId = Guid.Parse(row["TemBusiRelationId"].ToString()); entity.BusinessType = row["BusinessType"].ToString(); entity.BusinessNo = row["BusinessNo"].ToString(); if (row["ParentInstanceId"] != DBNull.Value) entity.ParentInstanceId = Guid.Parse(row["ParentInstanceId"].ToString()); return entity; }
/// <summary> /// 驱动并发的子流程 /// </summary> private static bool ParalleStateDealNew(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity, List<DealPersonInfo> dealPersonInfo) { try { var sql = string.Format( " select WfInstanceId from WF_Messages with (nolock) where FormID='{0}' and ReceiveDeptId='{1}' and ReceiveUserId='{2}' and MessageType={3} ", wfInstanceEntity.FormID, wfInstanceStatesEntity.TransactDepartmentID, wfInstanceStatesEntity.TransactUserID, (int)EnumWfMessageType.WaitForDo); var instanceId = DataHelper.ExecuteScalar(sql) == null ? Guid.Empty : new Guid(DataHelper.ExecuteScalar(sql).ToString()); var sb = new StringBuilder(); if (dealPersonInfo != null && dealPersonInfo.Count > 0) { foreach (var personInfo in dealPersonInfo) { sb.Append(personInfo.PersonId + "," + personInfo.PersonName + "," + personInfo.DeptId + "," + personInfo.DeptName); sb.Append("$"); } } wfInstanceEntity.InstanceID = instanceId; wfInstanceStatesEntity.InstanceID = instanceId; var flowData = new FlowData { WFInstance = wfInstanceEntity, WfInstanceStates = wfInstanceStatesEntity, ParallelBranchesCount = 0, DealPersonInfo = sb.ToString() }; var inputParameter = new Dictionary<string, object> { {"FlowDataParm", flowData}, {"NextDeptType", ""}, { "DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper() } }; var cswfTemplateEntity = WfTemplateDataBusiness.GetWfTemplateDataByTemplateID(wfInstanceEntity.TemplateID); var activity = GetActivity(cswfTemplateEntity.TemplateData); var instance = new WorkflowApplication(activity); var instanceStore = new SqlWorkflowInstanceStore(DataHelper.CONNECTION_STRING); instanceStore.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30); //解决再次load时lock的问题 instance.InstanceStore = instanceStore; instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; instance.Load(wfInstanceEntity.InstanceID); instance.ResumeBookmark("GetFlowData", inputParameter); return false; } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); throw ex; } }
/// <summary> /// 转入处理 /// </summary> private static void Snatch(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity) { if (wfInstanceEntity.CurrentStateType == (int)EnumWfStateType.Parllel) //并行状态处理 { var sql = string.Format( " select * from WF_InstanceStates with (nolock) where FormID='{0}' and WfState='{1}' and UPPER(TransactUserID) in" + " (select UPPER(GroupMemberID) from WF_SupportGroupMembers with (nolock) " + " where SupportGroupID=(select SupportGroupID from WF_SupportGroupMembers with (nolock) where GroupMemberID='{2}'))", wfInstanceEntity.FormID, wfInstanceEntity.CurrentWfState, wfInstanceStatesEntity.TransactUserID); var dt = DataHelper.ExecuteQuery(sql); if (dt != null && dt.Rows.Count > 0) { sql = string.Format( " update WF_InstanceStates set TransactUserID='{0}',TransactUserName='******' " + " where InstanceID='{2}' and FormID='{3}' and TransactUserID='{4}' and CompleteTime is null ", wfInstanceStatesEntity.TransactUserID, wfInstanceStatesEntity.TransactUserName, wfInstanceEntity.InstanceID, wfInstanceEntity.FormID, dt.Rows[0]["TransactUserID"] ); DataHelper.ExecuteNoneQuery(sql); } } else { wfInstanceEntity.CurrentDealPersonName = wfInstanceStatesEntity.TransactUserName; wfInstanceEntity.CurrentDealPersonID = wfInstanceStatesEntity.TransactUserID.ToString(); wfInstanceEntity.CurrentDealDeptId = wfInstanceStatesEntity.TransactDepartmentID.ToString(); wfInstanceEntity.CurrentDealDeptName = wfInstanceStatesEntity.TransactDepartmentName; WfInstanceBusiness.UpdateWfInstanceBusiness(wfInstanceEntity); // wfInstanceStatesEntity.StateDescription = "转入票单"; wfInstanceStatesEntity.CompleteTime = DateTime.Now; WfInstanceStatesBusiness.Add(wfInstanceStatesEntity); } }
private static void DriveWorkFlowNew(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity, List<DealPersonInfo> dealPersonInfo, List<Guid> parallelDeptGuid) { try { var sb = new StringBuilder(); if (dealPersonInfo != null && dealPersonInfo.Count > 0) { foreach (var personInfo in dealPersonInfo) { sb.Append(personInfo.PersonId + "," + personInfo.PersonName + "," + personInfo.DeptId + "," + personInfo.DeptName); sb.Append("$"); } } var parallelBranchesCount = 0; if (wfInstanceEntity.CurrentStateType == (int)EnumWfStateType.Parllel) //并行状态处理 { if (dealPersonInfo != null && dealPersonInfo.Count > 0) { parallelBranchesCount = dealPersonInfo.Count; } } //var isContinueWf = true; //if (wfInstanceEntity.CurrentStateType == (int) EnumWfStateType.Parllel) //并行状态处理 //{ // isContinueWf = ParalleStateDealNew(wfInstanceEntity, wfInstanceStatesEntity, dealPersonInfo); //} //if (isContinueWf) //{ var flowData = new FlowData { WFInstance = wfInstanceEntity, WfInstanceStates = wfInstanceStatesEntity, ParallelBranchesCount = parallelBranchesCount, DealPersonInfo = sb.ToString() }; var inputParameter = new Dictionary<string, object> { {"FlowDataParm", flowData}, {"NextDeptType", ""}, { "DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper() } }; var cswfTemplateEntity = WfTemplateDataBusiness.GetWfTemplateDataByTemplateID(wfInstanceEntity.TemplateID); var activity = GetActivity(cswfTemplateEntity.TemplateData); var instance = new WorkflowApplication(activity); var instanceStore = new SqlWorkflowInstanceStore(Common.GetConnectString()); instanceStore.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30); //解决再次load时lock的问题 instance.InstanceStore = instanceStore; instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; instance.Load(wfInstanceEntity.InstanceID); instance.ResumeBookmark("GetFlowData", inputParameter); // } } catch (InstanceLockedException lockedException) { LogWritter.WriteSystemExceptionLog(lockedException); } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); throw ex; } }
private static bool ParalleStateDeal(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity, Dictionary<string, string> supportInfo) { var isContinue = false; var sql = string.Format( " select COUNT(*) from WF_InstanceStates with (nolock) where FormID='{0}' and WfState='{1}' and CompleteTime is null ", wfInstanceEntity.FormID, wfInstanceEntity.CurrentWfState); var result = (int)DataHelper.ExecuteScalar(sql); if (result == 1) //最后一个分支 { isContinue = true; } using (TransactionScope scope = new TransactionScope()) { sql = string.Format( " update WF_InstanceStates set WfDealWayId='{0}',TransactType='{1}',StateDescription='{2}',TransactDepartmentID='{3}'," + "TransactDepartmentName='{4}',CompleteTime='{5}' where InstanceID='{6}' and FormID='{7}' and TransactUserID='{8}' and CompleteTime is null ", wfInstanceStatesEntity.WfDealWayId, wfInstanceStatesEntity.TransactType, wfInstanceStatesEntity.StateDescription, wfInstanceStatesEntity.TransactDepartmentID, wfInstanceStatesEntity.TransactDepartmentName, DateTime.Now, wfInstanceStatesEntity.InstanceID, wfInstanceStatesEntity.FormID, wfInstanceStatesEntity.TransactUserID); DataHelper.ExecuteNoneQuery(sql); var newEntity = WfInstanceBusiness.GetWfInstanceBusinessByFormID(wfInstanceEntity.FormID); newEntity.CurrentDealPersonID = newEntity.CurrentDealPersonID.Replace(wfInstanceStatesEntity.TransactUserID.ToString(), ""); newEntity.CurrentDealPersonID = newEntity.CurrentDealPersonID.Replace(",,", ","); newEntity.CurrentDealPersonID = newEntity.CurrentDealPersonID.TrimStart(','); newEntity.CurrentDealPersonID = newEntity.CurrentDealPersonID.TrimEnd(','); newEntity.CurrentDealPersonName = newEntity.CurrentDealPersonName.Replace(wfInstanceStatesEntity.TransactUserName, ""); newEntity.CurrentDealPersonName = newEntity.CurrentDealPersonName.Replace(",,", ","); newEntity.CurrentDealPersonName = newEntity.CurrentDealPersonName.TrimStart(','); newEntity.CurrentDealPersonName = newEntity.CurrentDealPersonName.TrimEnd(','); sql = string.Format( " update WF_Instance set CurrentDealPersonID='{0}', CurrentDealPersonName='{1}' where FormID='{2}' ", newEntity.CurrentDealPersonID, newEntity.CurrentDealPersonName, wfInstanceStatesEntity.FormID); DataHelper.ExecuteNoneQuery(sql); scope.Complete(); } return isContinue; }
/// <summary> /// 启动工作流时候的实体赋值 /// </summary> /// <param name="wfInstance"></param> /// <param name="wfInstanceStates"></param> /// <param name="formId"></param> /// <param name="startUserId"></param> /// <param name="startUserName"></param> /// <param name="startDeptId"></param> /// <param name="startDeptName"></param> /// <param name="businessType"></param> private static void SetStartWfValue(WfInstanceEntity wfInstance, WfInstanceStatesEntity wfInstanceStates, Guid formId, Guid startUserId, string startUserName, Guid startDeptId, string startDeptName) { wfInstance.FormID = formId; wfInstance.StartUserID = startUserId; wfInstance.StartUserName = startUserName; wfInstance.StartDepartmentID = startDeptId; wfInstance.StartDepartmentName = startDeptName; wfInstance.StartTime = DateTime.Now; wfInstance.IsDeleted = false; wfInstanceStates.ID = Guid.NewGuid(); wfInstanceStates.FormID = formId; wfInstanceStates.StateDescription = "流程启动"; wfInstanceStates.TransactUserID = startUserId; wfInstanceStates.TransactUserName = startUserName; wfInstanceStates.TransactDepartmentID = startDeptId; wfInstanceStates.TransactDepartmentName = startDeptName; wfInstanceStates.CreateTime = wfInstance.StartTime; wfInstanceStates.CompleteTime = wfInstance.StartTime; wfInstanceStates.IsDeleted = false; wfInstanceStates.BlankCol1 = string.Empty; wfInstanceStates.BlankCol2 = string.Empty; wfInstanceStates.BlankCol3 = string.Empty; wfInstanceStates.BlankCol4 = string.Empty; }
/// <summary> /// /// </summary> private static void DriveWorkFlowofChange(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity) { var sql = string.Format(" select count(FormId) from WF_ModifyStatesInstance where FormId='{0}' and ExcuteState<>{1} ", wfInstanceEntity.FormID, (int)ExcuteState.Excuted); if (Convert.ToInt32(DataHelper.ExecuteScalar(sql)) > 0) { //var stateId = GetCurrentState(wfInstanceEntity.FormID); var res = WfModifyStatesInstanceBusiness.Deal(wfInstanceEntity.FormID.ToString(), wfInstanceStatesEntity.WfDealWayId.ToString(), wfInstanceStatesEntity.TransactUserID.ToString(), wfInstanceStatesEntity.StateDescription); var result = DataHelper.ExecuteScalar(sql); //所有状态都执行完了,继续主工作流程 if (res == 0 || Convert.ToInt32(result) == 0) { var flowData = new FlowData { WFInstance = wfInstanceEntity, WfInstanceStates = wfInstanceStatesEntity }; var inputParameter = new Dictionary<string, object> { {"FlowDataParm", flowData}, {"NextDeptType", ""}, {"DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper()} }; var cswfTemplateEntity = WfTemplateDataBusiness.GetWfTemplateDataByTemplateID(wfInstanceEntity.TemplateID); var activity = GetActivity(cswfTemplateEntity.TemplateData); var instance = new WorkflowApplication(activity); var instanceStore = new SqlWorkflowInstanceStore(Common.GetConnectString()); instanceStore.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30); //解决再次load时lock的问题 instance.InstanceStore = instanceStore; instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; instance.Load(wfInstanceEntity.InstanceID); instance.ResumeBookmark("GetFlowData", inputParameter); } } else //按照原来的处理方式处理 { var flowData = new FlowData { WFInstance = wfInstanceEntity, WfInstanceStates = wfInstanceStatesEntity }; var inputParameter = new Dictionary<string, object> { {"FlowDataParm", flowData}, {"NextDeptType", ""}, {"DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper()} }; var cswfTemplateEntity = WfTemplateDataBusiness.GetWfTemplateDataByTemplateID(wfInstanceEntity.TemplateID); var activity = GetActivity(cswfTemplateEntity.TemplateData); var instance = new WorkflowApplication(activity); var instanceStore = new SqlWorkflowInstanceStore(Common.GetConnectString()); instanceStore.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30); //解决再次load时lock的问题 instance.InstanceStore = instanceStore; instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; instance.Load(wfInstanceEntity.InstanceID); instance.ResumeBookmark("GetFlowData", inputParameter); } }
/// <summary> /// 启动子流程 /// </summary> /// <param name="formId"></param> /// <param name="startUserId"></param> /// <param name="startUserName"></param> /// <param name="startDeptId"></param> /// <param name="startDeptName"></param> /// <param name="businessType"></param> /// <param name="businessNo"></param> /// <param name="parentWfIntanceId"></param> /// <param name="wftempalteId"></param> /// <param name="dealPersons"></param> public static void StartWorkFlow(Guid formId, Guid startUserId, string startUserName, Guid startDeptId, string startDeptName, string businessType, string businessNo, Guid parentWfIntanceId, Guid wftempalteId, string dealPersons) { var wfInstance = new WfInstanceEntity(); var wfInstanceStates = new WfInstanceStatesEntity(); SetStartWfValue(wfInstance, wfInstanceStates, formId, startUserId, startUserName, startDeptId, startDeptName); wfInstance.BusinessType = businessType; wfInstance.BusinessNo = businessNo; StartWorkFlow(wftempalteId, wfInstance, wfInstanceStates, parentWfIntanceId, dealPersons); }
/// <summary> /// 获取流程实例 /// </summary> /// <param name="inputParameters"></param> /// <param name="templateId"></param> /// <param name="relationId">模板与业务的关系id </param> /// <param name="businessType"></param> /// <param name="wfInstance"></param> /// <returns></returns> private static WorkflowApplication GetStartWorkflowApplicationInstance( Dictionary<string, object> inputParameters, out Guid templateId, out Guid relationId, string businessType, WfInstanceEntity wfInstance) { templateId = Guid.Empty; relationId = Guid.Empty; try { var dt = GetTeplateData(businessType, wfInstance.StartDepartmentID); if (dt != null && dt.Rows.Count > 0) { templateId = new Guid(dt.Rows[0]["TemplateID"].ToString()); relationId = new Guid(dt.Rows[0]["RelationId"].ToString()); var activity = GetActivity(dt.Rows[0]["TemplateData"].ToString()); var instance = new WorkflowApplication(activity, inputParameters); return instance; } else { LogWritter.WriteSystemExceptionLog(new Exception("未找到模板")); return null; } } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); return null; } }
/// <summary> /// 对外提供接口,来启动流程实例(工作流来确定使用哪个模板) /// </summary> /// <param name="formId">表单号guid</param> /// <param name="startUserId">操作人ID</param> /// <param name="startUserName">操作人名称</param> /// <param name="startDeptId">操作人所在单位id</param> /// <param name="startDeptName">操作人所在单位名称</param> /// <param name="businessType">具体业务类型,用来确定要使用的流程模板</param> /// <param name="businessNo"> 表单号(给人看的)</param> public static void StartWorkFlow(Guid formId, Guid startUserId, string startUserName, Guid startDeptId, string startDeptName, Guid startPreMapDeptID, string startPreMapDeptName, string startPreMapDeptAllPathName, string businessType, string businessNo, string dealPersons) { var wfInstance = new WfInstanceEntity(); var wfInstanceStates = new WfInstanceStatesEntity(); SetStartWfValue(wfInstance, wfInstanceStates, formId, startUserId, startUserName, startDeptId, startDeptName, startPreMapDeptID, startPreMapDeptName, startPreMapDeptAllPathName); wfInstance.BusinessType = businessType; wfInstance.BusinessNo = businessNo; StartWorkFlow(wfInstance, wfInstanceStates, businessType, Guid.Empty, dealPersons); }
/// <summary> /// 根据指定模板启动工作流 /// </summary> private static void StartWorkFlow(Guid wfTemplateId, WfInstanceEntity wfInstance, WfInstanceStatesEntity wfInstanceStatesEntity) { try { var connectionString = Common.GetConnectString(); WorkflowApplication instance; var flowData = new FlowData() { WFInstance = wfInstance, WfInstanceStates = wfInstanceStatesEntity }; var inputParameter = new Dictionary<string, object> { {"FlowDataParm", flowData}, {"NextDeptType", ""}, {"DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper()} }; instance = GetStartWorkflowApplicationInstanceByTemplateId(wfTemplateId, inputParameter); if (instance != null) { ((FlowData)inputParameter["FlowDataParm"]).WFInstance.InstanceID = instance.Id; ((FlowData)inputParameter["FlowDataParm"]).WfInstanceStates.InstanceID = instance.Id; ((FlowData)inputParameter["FlowDataParm"]).WFInstance.TemplateID = wfTemplateId; var instanceStore = new SqlWorkflowInstanceStore(connectionString); InstanceView view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); instanceStore.DefaultInstanceOwner = view.InstanceOwner; instance.InstanceStore = instanceStore; instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; // instance.Aborted += InstanceAborted; instance.Run(); } else { throw new Exception("未找到对应的流程模板!请与系统管理员联系。"); } } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); throw new Exception("生成流程异常:" + ex.Message, ex.InnerException); } }
/// <summary> /// 转入处理 /// </summary> private static void Snatch(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity) { wfInstanceEntity.CurrentDealPersonName = wfInstanceStatesEntity.TransactUserName; wfInstanceEntity.CurrentDealPersonID = wfInstanceStatesEntity.TransactUserID.ToString(); wfInstanceEntity.CurrentDealDeptId = wfInstanceStatesEntity.TransactDepartmentID.ToString(); wfInstanceEntity.CurrentDealDeptName = wfInstanceStatesEntity.TransactDepartmentName; WfInstanceBusiness.UpdateWfInstanceBusiness(wfInstanceEntity); // wfInstanceStatesEntity.StateDescription = "转入票单"; WfInstanceStatesBusiness.Add(wfInstanceStatesEntity); }
/// <summary> /// 增加工作流当前处理状态基本信息 /// </summary> /// <param name="wfInstance">工作流当前处理状态基本信息对象实体</param> public static bool Add(WfInstanceEntity entity) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into WF_Instance ("); strSql.Append(" InstanceID, TemplateID, FormID, StartUserID, StartUserName, StartDepartmentID, StartDepartmentName, StartPreMapDeptID, StartPreMapDeptName, StartPreMapDeptAllPathName, StartTime, CurrentRunState, CurrentWfState, CurrentDealDeptLevel, CurrentDealPersonLevel, CurrentDealPersonID, CurrentDealPersonName, CurrentDealDeptId, CurrentDealDeptName, CompleteTime, IsDeleted, CurrentStateType, CurrentParallelCount, TemBusiRelationId, BusinessType, BusinessNo, ParentInstanceId)"); strSql.Append(" values ( "); strSql.Append("@InstanceID, @TemplateID, @FormID, @StartUserID, @StartUserName, @StartDepartmentID, @StartDepartmentName, @StartPreMapDeptID, @StartPreMapDeptName, @StartPreMapDeptAllPathName, @StartTime, @CurrentRunState, @CurrentWfState, @CurrentDealDeptLevel, @CurrentDealPersonLevel, @CurrentDealPersonID, @CurrentDealPersonName, @CurrentDealDeptId, @CurrentDealDeptName, @CompleteTime, @IsDeleted, @CurrentStateType, @CurrentParallelCount, @TemBusiRelationId, @BusinessType, @BusinessNo, @ParentInstanceId)"); SqlParameter[] parameters = { new SqlParameter("@InstanceID", SqlDbType.UniqueIdentifier), new SqlParameter("@TemplateID", SqlDbType.UniqueIdentifier), new SqlParameter("@FormID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartUserID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartUserName", SqlDbType.NVarChar), new SqlParameter("@StartDepartmentID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartDepartmentName", SqlDbType.NVarChar), new SqlParameter("@StartPreMapDeptID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartPreMapDeptName", SqlDbType.NVarChar), new SqlParameter("@StartPreMapDeptAllPathName", SqlDbType.NVarChar), new SqlParameter("@StartTime", SqlDbType.DateTime), new SqlParameter("@CurrentRunState", SqlDbType.VarChar), new SqlParameter("@CurrentWfState", SqlDbType.UniqueIdentifier), new SqlParameter("@CurrentDealDeptLevel", SqlDbType.Int), new SqlParameter("@CurrentDealPersonLevel", SqlDbType.Int), new SqlParameter("@CurrentDealPersonID", SqlDbType.VarChar), new SqlParameter("@CurrentDealPersonName", SqlDbType.NVarChar), new SqlParameter("@CurrentDealDeptId", SqlDbType.VarChar), new SqlParameter("@CurrentDealDeptName", SqlDbType.NVarChar), new SqlParameter("@CompleteTime", SqlDbType.DateTime), new SqlParameter("@IsDeleted", SqlDbType.Bit), new SqlParameter("@CurrentStateType", SqlDbType.Int), new SqlParameter("@CurrentParallelCount", SqlDbType.Int), new SqlParameter("@TemBusiRelationId", SqlDbType.UniqueIdentifier), new SqlParameter("@BusinessType", SqlDbType.VarChar), new SqlParameter("@BusinessNo", SqlDbType.VarChar), new SqlParameter("@ParentInstanceId", SqlDbType.UniqueIdentifier) }; int i = 0; parameters[i++].Value = entity.InstanceID; parameters[i++].Value = entity.TemplateID; parameters[i++].Value = entity.FormID; parameters[i++].Value = entity.StartUserID; parameters[i++].Value = entity.StartUserName; parameters[i++].Value = entity.StartDepartmentID; parameters[i++].Value = entity.StartDepartmentName; parameters[i++].Value = entity.StartPreMapDeptID; parameters[i++].Value = entity.StartPreMapDeptName; parameters[i++].Value = entity.StartPreMapDeptAllPathName; if (entity.StartTime == DateTime.MinValue) entity.StartTime = (DateTime)SqlDateTime.MinValue; parameters[i++].Value = entity.StartTime; parameters[i++].Value = entity.CurrentRunState; parameters[i++].Value = entity.CurrentWfState; parameters[i++].Value = entity.CurrentDealDeptLevel; parameters[i++].Value = entity.CurrentDealPersonLevel; parameters[i++].Value = entity.CurrentDealPersonID; parameters[i++].Value = entity.CurrentDealPersonName; parameters[i++].Value = entity.CurrentDealDeptId; parameters[i++].Value = entity.CurrentDealDeptName; if (entity.CompleteTime != DateTime.MinValue) { parameters[i++].Value = entity.CompleteTime; } else { i++; } parameters[i++].Value = entity.IsDeleted; parameters[i++].Value = entity.CurrentStateType; parameters[i++].Value = entity.CurrentParallelCount; parameters[i++].Value = entity.TemBusiRelationId; parameters[i++].Value = entity.BusinessType; parameters[i++].Value = entity.BusinessNo; parameters[i++].Value = entity.ParentInstanceId; return DataHelper.ExecuteNoneQuery(strSql.ToString(), parameters) > 0; }
/// <summary> /// 根据指定模板启动工作流 /// </summary> private static void StartWorkFlow(Guid wfTemplateId, WfInstanceEntity wfInstance, WfInstanceStatesEntity wfInstanceStatesEntity, Guid parentWfInstaceId, string dealPersons) { try { var connectionString = DataHelper.CONNECTION_STRING; WorkflowApplication instance; var dealPersonInfo = dealPersons; var flowData = new FlowData() { WFInstance = wfInstance, WfInstanceStates = wfInstanceStatesEntity, DealPersonInfo = dealPersonInfo, ParallelBranchesCount = 0 }; var inputParameter = new Dictionary<string, object> { {"FlowDataParm", flowData}, {"NextDeptType", ""}, {"DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper()} }; instance = GetStartWorkflowApplicationInstanceByTemplateId(wfTemplateId, inputParameter); if (instance != null) { ((FlowData)inputParameter["FlowDataParm"]).WFInstance.InstanceID = instance.Id; ((FlowData)inputParameter["FlowDataParm"]).WfInstanceStates.InstanceID = instance.Id; ((FlowData)inputParameter["FlowDataParm"]).WFInstance.TemplateID = wfTemplateId; var instanceStore = new SqlWorkflowInstanceStore(connectionString); InstanceView view = instanceStore.Execute(instanceStore.CreateInstanceHandle(), new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(30)); instanceStore.DefaultInstanceOwner = view.InstanceOwner; instance.InstanceStore = instanceStore; instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; // instance.Aborted += InstanceAborted; if (parentWfInstaceId != Guid.Empty) //写流程实例关系表 { //WriteWfInstanceRelation(parentWfInstaceId,instance.Id,wfInstance.FormID); ((FlowData)inputParameter["FlowDataParm"]).WFInstance.ParentInstanceId = parentWfInstaceId; } instance.Run(); } else { throw new Exception("未找到对应的流程模板!请与系统管理员联系。"); } } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); throw new Exception("生成流程异常:" + ex.Message, ex.InnerException); } }
public static bool UpdateWfInstanceBusinessByFormId(WfInstanceEntity entity) { StringBuilder strSql = new StringBuilder(); strSql.Append("update WF_Instance set "); strSql.Append("InstanceID = @InstanceID, "); strSql.Append("TemplateID = @TemplateID, "); strSql.Append("FormID = @FormID, "); strSql.Append("StartUserID = @StartUserID, "); strSql.Append("StartUserName = @StartUserName, "); strSql.Append("StartDepartmentID = @StartDepartmentID, "); strSql.Append("StartDepartmentName = @StartDepartmentName, "); strSql.Append("StartPreMapDeptID = @StartPreMapDeptID, "); strSql.Append("StartPreMapDeptName = @StartPreMapDeptName, "); strSql.Append("StartPreMapDeptAllPathName = @StartPreMapDeptAllPathName, "); strSql.Append("StartTime = @StartTime, "); strSql.Append("CurrentRunState = @CurrentRunState, "); strSql.Append("CurrentWfState = @CurrentWfState, "); strSql.Append("CurrentDealDeptLevel = @CurrentDealDeptLevel, "); strSql.Append("CurrentDealPersonLevel = @CurrentDealPersonLevel, "); strSql.Append("CurrentDealPersonID = @CurrentDealPersonID, "); strSql.Append("CurrentDealPersonName = @CurrentDealPersonName, "); strSql.Append("CurrentDealDeptId = @CurrentDealDeptId, "); strSql.Append("CurrentDealDeptName = @CurrentDealDeptName, "); strSql.Append("CompleteTime = @CompleteTime, "); strSql.Append("IsDeleted = @IsDeleted, "); strSql.Append("CurrentStateType = @CurrentStateType, "); strSql.Append("CurrentParallelCount = @CurrentParallelCount, "); strSql.Append("TemBusiRelationId = @TemBusiRelationId, "); strSql.Append("BusinessType = @BusinessType, "); strSql.Append("BusinessNo = @BusinessNo, "); strSql.Append("ParentInstanceId = @ParentInstanceId"); strSql.Append(" where "); strSql.Append(" FormID = @FormID "); SqlParameter[] parameters = { new SqlParameter("@InstanceID", SqlDbType.UniqueIdentifier), new SqlParameter("@TemplateID", SqlDbType.UniqueIdentifier), new SqlParameter("@FormID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartUserID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartUserName", SqlDbType.NVarChar), new SqlParameter("@StartDepartmentID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartDepartmentName", SqlDbType.NVarChar), new SqlParameter("@StartPreMapDeptID", SqlDbType.UniqueIdentifier), new SqlParameter("@StartPreMapDeptName", SqlDbType.NVarChar), new SqlParameter("@StartPreMapDeptAllPathName", SqlDbType.NVarChar), new SqlParameter("@StartTime", SqlDbType.DateTime), new SqlParameter("@CurrentRunState", SqlDbType.VarChar), new SqlParameter("@CurrentWfState", SqlDbType.UniqueIdentifier), new SqlParameter("@CurrentDealDeptLevel", SqlDbType.Int), new SqlParameter("@CurrentDealPersonLevel", SqlDbType.Int), new SqlParameter("@CurrentDealPersonID", SqlDbType.VarChar), new SqlParameter("@CurrentDealPersonName", SqlDbType.NVarChar), new SqlParameter("@CurrentDealDeptId", SqlDbType.VarChar), new SqlParameter("@CurrentDealDeptName", SqlDbType.NVarChar), new SqlParameter("@CompleteTime", SqlDbType.DateTime), new SqlParameter("@IsDeleted", SqlDbType.Bit), new SqlParameter("@CurrentStateType", SqlDbType.Int), new SqlParameter("@CurrentParallelCount", SqlDbType.Int), new SqlParameter("@TemBusiRelationId", SqlDbType.UniqueIdentifier), new SqlParameter("@BusinessType", SqlDbType.VarChar), new SqlParameter("@BusinessNo", SqlDbType.VarChar), new SqlParameter("@ParentInstanceId", SqlDbType.UniqueIdentifier) }; int i = 0; parameters[i++].Value = entity.InstanceID; parameters[i++].Value = entity.TemplateID; parameters[i++].Value = entity.FormID; parameters[i++].Value = entity.StartUserID; parameters[i++].Value = entity.StartUserName; parameters[i++].Value = entity.StartDepartmentID; parameters[i++].Value = entity.StartDepartmentName; parameters[i++].Value = entity.StartPreMapDeptID; parameters[i++].Value = entity.StartPreMapDeptName; parameters[i++].Value = entity.StartPreMapDeptAllPathName; if (entity.StartTime == DateTime.MinValue) entity.StartTime = (DateTime)SqlDateTime.MinValue; parameters[i++].Value = entity.StartTime; parameters[i++].Value = entity.CurrentRunState; parameters[i++].Value = entity.CurrentWfState; parameters[i++].Value = entity.CurrentDealDeptLevel; parameters[i++].Value = entity.CurrentDealPersonLevel; parameters[i++].Value = entity.CurrentDealPersonID; parameters[i++].Value = entity.CurrentDealPersonName; parameters[i++].Value = entity.CurrentDealDeptId; parameters[i++].Value = entity.CurrentDealDeptName; if (entity.CompleteTime != DateTime.MinValue) { parameters[i++].Value = entity.CompleteTime; } else { i++; } parameters[i++].Value = entity.IsDeleted; parameters[i++].Value = entity.CurrentStateType; parameters[i++].Value = entity.CurrentParallelCount; parameters[i++].Value = entity.TemBusiRelationId; parameters[i++].Value = entity.BusinessType; parameters[i++].Value = entity.BusinessNo; parameters[i++].Value = entity.ParentInstanceId; return DataHelper.ExecuteNoneQuery(strSql.ToString(), parameters) > 0; }
/// <summary> /// 驱动工作流 /// </summary> private static void DriveWorkFlow(WfInstanceEntity wfInstanceEntity, WfInstanceStatesEntity wfInstanceStatesEntity) { try { //var businessType = wfInstanceEntity.BusinessType; //if (businessType == 5 || businessType == 6) //{ // DriveWorkFlowofChange(wfInstanceEntity, wfInstanceStatesEntity); //} //else //{ // if (wfInstanceStatesEntity.WfDealWayId == Guid.Empty) //转入,只更改处理人,不走流程,即:有权限的人把票单改到自己名下处理 // { // Snatch(wfInstanceEntity, wfInstanceStatesEntity); // } // else // { // var flowData = new FlowData // { // WFInstance = wfInstanceEntity, // WfInstanceStates = wfInstanceStatesEntity // }; // var inputParameter = new Dictionary<string, object> // { // {"FlowDataParm", flowData}, // {"NextDeptType", ""}, // { // "DealWay", wfInstanceStatesEntity.WfDealWayId.ToString().ToUpper() // } // }; // var cswfTemplateEntity = // WfTemplateDataBusiness.GetWfTemplateDataByTemplateID(wfInstanceEntity.TemplateID); // var activity = GetActivity(cswfTemplateEntity.TemplateData); // var instance = new WorkflowApplication(activity); // var instanceStore = new SqlWorkflowInstanceStore(Common.GetConnectString()); // instanceStore.InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry; // instanceStore.HostLockRenewalPeriod = TimeSpan.FromSeconds(30); //解决再次load时lock的问题 // instance.InstanceStore = instanceStore; // instance.PersistableIdle = (waiea) => PersistableIdleAction.Unload; // instance.Load(wfInstanceEntity.InstanceID); // instance.ResumeBookmark("GetFlowData", inputParameter); // } //} } catch (InstanceLockedException lockedException) { LogWritter.WriteSystemExceptionLog(lockedException); } catch (Exception ex) { LogWritter.WriteSystemExceptionLog(ex); throw ex; } }