Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
 private static void IncidentRise(WfInstanceStatesEntity wfInstanceStatesEntity)
 {
     wfInstanceStatesEntity.CompleteTime = DateTime.Now;
     WfInstanceStatesBusiness.Add(wfInstanceStatesEntity);
 }
Exemplo n.º 4
0
        /// <summary>
        /// 实体赋值
        /// </summary>
        /// <param name="wfInstanceStates"></param>
        /// <param name="dealUserId"></param>
        /// <param name="dealUserName"></param>
        /// <param name="dealDeptId"></param>
        /// <param name="dealDeptName"></param>
        /// <param name="dealwayId"></param>
        /// <param name="dealDescription"></param>
        private static void SetWfstatesValue(WfInstanceStatesEntity wfInstanceStates, Guid dealUserId,
            string dealUserName, Guid dealDeptId, string dealDeptName,
            string dealwayId, string dealDescription)
        {
            try
            {
                wfInstanceStates.ID = Guid.NewGuid();
                wfInstanceStates.StateDescription = dealDescription;
                wfInstanceStates.TransactUserID = dealUserId;
                wfInstanceStates.TransactUserName = dealUserName;
                wfInstanceStates.TransactDepartmentID = dealDeptId;
                wfInstanceStates.TransactDepartmentName = dealDeptName;
                wfInstanceStates.CreateTime = wfInstanceStates.CompleteTime;

                wfInstanceStates.WfDealWayId = new Guid(dealwayId);
                wfInstanceStates.IsDeleted = false;
                wfInstanceStates.BlankCol1 = string.Empty;
                wfInstanceStates.BlankCol2 = string.Empty;
                wfInstanceStates.BlankCol3 = string.Empty;
                wfInstanceStates.BlankCol4 = string.Empty;
            }
            catch (Exception ex)
            {
                LogWritter.WriteSystemExceptionLog(ex);
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 流程启动后看有无关联的票单,如果有则驱动该票单的流程继续
        /// </summary>
        private void DriveRelationFormWorkFlowForEnd(WfInstanceStatesEntity wfInstanceStatesEntity)
        {
            try
            {
                var sql =
                    string.Format(
                        " select FormId,RelationFormType from CS_Relation with (nolock) where  RelationFormId='{0}'  and AddType=2  and RelationFormType=5 ",    //这里写死了一个5??????????????????????????
                        wfInstanceStatesEntity.FormID);
                var dt = DataHelper.ExecuteQuery(sql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (!string.IsNullOrEmpty(dt.Rows[0]["FormId"].ToString()))
                    {
                        var formId = dt.Rows[0]["FormId"].ToString();
                        var formName = Common.GetBusinessType(dt.Rows[0]["RelationFormType"].ToString());
                        Guid billGuid = Guid.Empty;
                        Guid.TryParse(formId, out billGuid);

                        //Interfaces.DriveWorkFlow(billGuid,
                        //                               wfInstanceStatesEntity.TransactUserID,
                        //                               wfInstanceStatesEntity.TransactUserName,
                        //                               wfInstanceStatesEntity.TransactDepartmentID,
                        //                               wfInstanceStatesEntity.TransactDepartmentName,
                        //                               wfInstanceStatesEntity.WfDealWayId.ToString(), "结束" + formName);
                    }
                }
            }
            catch (Exception ex)
            {
                LogWritter.WriteSystemExceptionLog(ex);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// 获取实体信息
        /// </summary>
        /// <param name="row">数据行</param>
        /// <returns></returns>
        public static WfInstanceStatesEntity GetEntity(DataRow row)
        {
            WfInstanceStatesEntity entity = new WfInstanceStatesEntity();

            if (row["ID"] != DBNull.Value)
                entity.ID = Guid.Parse(row["ID"].ToString());
            if (row["InstanceID"] != DBNull.Value)
                entity.InstanceID = Guid.Parse(row["InstanceID"].ToString());
            if (row["FormID"] != DBNull.Value)
                entity.FormID = Guid.Parse(row["FormID"].ToString());
            entity.RunState = row["RunState"].ToString();
            if (row["WfState"] != DBNull.Value)
                entity.WfState = Guid.Parse(row["WfState"].ToString());
            if (row["WfDealWayId"] != DBNull.Value)
                entity.WfDealWayId = Guid.Parse(row["WfDealWayId"].ToString());
            entity.TransactType = row["TransactType"].ToString();
            entity.StateDescription = row["StateDescription"].ToString();
            if (row["DealPersonLevel"] != DBNull.Value)
                entity.DealPersonLevel = Convert.ToInt32(row["DealPersonLevel"]);
            if (row["DealDeptLevel"] != DBNull.Value)
                entity.DealDeptLevel = Convert.ToInt32(row["DealDeptLevel"]);
            if (row["TransactUserID"] != DBNull.Value)
                entity.TransactUserID = Guid.Parse(row["TransactUserID"].ToString());
            entity.TransactUserName = row["TransactUserName"].ToString();
            if (row["TransactDepartmentID"] != DBNull.Value)
                entity.TransactDepartmentID = Guid.Parse(row["TransactDepartmentID"].ToString());
            entity.TransactDepartmentName = row["TransactDepartmentName"].ToString();
            entity.DealPersonInfo = row["DealPersonInfo"].ToString();
            if (row["CreateTime"] != DBNull.Value)
                entity.CreateTime = Convert.ToDateTime(row["CreateTime"]);
            if (row["CompleteTime"] != DBNull.Value)
                entity.CompleteTime = Convert.ToDateTime(row["CompleteTime"]);
            if (row["IsDeleted"] != DBNull.Value)
                entity.IsDeleted = Convert.ToBoolean(row["IsDeleted"]);
            entity.BlankCol1 = row["BlankCol1"].ToString();
            entity.BlankCol2 = row["BlankCol2"].ToString();
            entity.BlankCol3 = row["BlankCol3"].ToString();
            entity.BlankCol4 = row["BlankCol4"].ToString();

            return entity;
        }
Exemplo n.º 8
0
        /// <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);
            }
        }
Exemplo n.º 9
0
 /// <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);
 }
Exemplo n.º 10
0
        /// <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);
            }
        }
Exemplo n.º 11
0
 /// <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);
 }
Exemplo n.º 12
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;
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 更新工作流历史处理状态基本信息
        /// </summary>
        /// <param name="wF_InstanceState">工作流历史处理状态基本信息</param>
        /// <returns>bool</returns>
        public static bool UpdateWfInstanceState(WfInstanceStatesEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update WF_InstanceStates set ");
            strSql.Append("ID = @ID, ");
            strSql.Append("InstanceID = @InstanceID, ");
            strSql.Append("FormID = @FormID, ");
            strSql.Append("RunState = @RunState, ");
            strSql.Append("WfState = @WfState, ");
            strSql.Append("WfDealWayId = @WfDealWayId, ");
            strSql.Append("TransactType = @TransactType, ");
            strSql.Append("StateDescription = @StateDescription, ");
            strSql.Append("DealPersonLevel = @DealPersonLevel, ");
            strSql.Append("DealDeptLevel = @DealDeptLevel, ");
            strSql.Append("TransactUserID = @TransactUserID, ");
            strSql.Append("TransactUserName = @TransactUserName, ");
            strSql.Append("TransactDepartmentID = @TransactDepartmentID, ");
            strSql.Append("TransactDepartmentName = @TransactDepartmentName, ");
            strSql.Append("DealPersonInfo = @DealPersonInfo, ");
            strSql.Append("CreateTime = @CreateTime, ");
            strSql.Append("CompleteTime = @CompleteTime, ");
            strSql.Append("IsDeleted = @IsDeleted, ");
            strSql.Append("BlankCol1 = @BlankCol1, ");
            strSql.Append("BlankCol2 = @BlankCol2, ");
            strSql.Append("BlankCol3 = @BlankCol3, ");
            strSql.Append("BlankCol4 = @BlankCol4");
            strSql.Append(" where ");
            strSql.Append(" ID = @ID ");

            SqlParameter[] parameters = {
                new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@InstanceID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@FormID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@RunState", SqlDbType.VarChar),
                new SqlParameter("@WfState", SqlDbType.UniqueIdentifier),
                new SqlParameter("@WfDealWayId", SqlDbType.UniqueIdentifier),
                new SqlParameter("@TransactType", SqlDbType.VarChar),
                new SqlParameter("@StateDescription", SqlDbType.NVarChar),
                new SqlParameter("@DealPersonLevel", SqlDbType.Int),
                new SqlParameter("@DealDeptLevel", SqlDbType.Int),
                new SqlParameter("@TransactUserID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@TransactUserName", SqlDbType.NVarChar),
                new SqlParameter("@TransactDepartmentID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@TransactDepartmentName", SqlDbType.NVarChar),
                new SqlParameter("@DealPersonInfo", SqlDbType.NVarChar),
                new SqlParameter("@CreateTime", SqlDbType.DateTime),
                new SqlParameter("@CompleteTime", SqlDbType.DateTime),
                new SqlParameter("@IsDeleted", SqlDbType.Bit),
                new SqlParameter("@BlankCol1", SqlDbType.VarChar),
                new SqlParameter("@BlankCol2", SqlDbType.VarChar),
                new SqlParameter("@BlankCol3", SqlDbType.NVarChar),
                new SqlParameter("@BlankCol4", SqlDbType.NVarChar)
            };

            int i = 0;
            parameters[i++].Value = entity.ID;
            parameters[i++].Value = entity.InstanceID;
            parameters[i++].Value = entity.FormID;
            parameters[i++].Value = entity.RunState;
            parameters[i++].Value = entity.WfState;
            parameters[i++].Value = entity.WfDealWayId;
            parameters[i++].Value = entity.TransactType;
            parameters[i++].Value = entity.StateDescription;
            parameters[i++].Value = entity.DealPersonLevel;
            parameters[i++].Value = entity.DealDeptLevel;
            parameters[i++].Value = entity.TransactUserID;
            parameters[i++].Value = entity.TransactUserName;
            parameters[i++].Value = entity.TransactDepartmentID;
            parameters[i++].Value = entity.TransactDepartmentName;
            parameters[i++].Value = entity.DealPersonInfo;
            if (entity.CreateTime == DateTime.MinValue)
                entity.CreateTime = (DateTime)SqlDateTime.MinValue;
            parameters[i++].Value = entity.CreateTime;
            if (entity.CompleteTime == DateTime.MinValue)
                entity.CompleteTime = (DateTime)SqlDateTime.MinValue;
            parameters[i++].Value = entity.CompleteTime;
            parameters[i++].Value = entity.IsDeleted;
            parameters[i++].Value = entity.BlankCol1;
            parameters[i++].Value = entity.BlankCol2;
            parameters[i++].Value = entity.BlankCol3;
            parameters[i++].Value = entity.BlankCol4;

            return DataHelper.ExecuteNoneQuery(strSql.ToString(), parameters) > 0;
        }
Exemplo n.º 14
0
        /// <summary>
        /// 增加工作流历史处理状态基本信息
        /// </summary>
        /// <param name="wfInstanceStates">工作流历史处理状态基本信息对象实体</param>
        public static bool Add(WfInstanceStatesEntity entity)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into WF_InstanceStates (");
            strSql.Append(" ID,  InstanceID,  FormID,  RunState,  WfState,  WfDealWayId,  TransactType,  StateDescription,  DealPersonLevel,  DealDeptLevel,  TransactUserID,  TransactUserName,  TransactDepartmentID,  TransactDepartmentName,  DealPersonInfo,  CreateTime,  CompleteTime,  IsDeleted,  BlankCol1,  BlankCol2,  BlankCol3,  BlankCol4)");
            strSql.Append(" values ( ");
            strSql.Append("@ID, @InstanceID, @FormID, @RunState, @WfState, @WfDealWayId, @TransactType, @StateDescription, @DealPersonLevel, @DealDeptLevel, @TransactUserID, @TransactUserName, @TransactDepartmentID, @TransactDepartmentName, @DealPersonInfo, @CreateTime, @CompleteTime, @IsDeleted, @BlankCol1, @BlankCol2, @BlankCol3, @BlankCol4)");

            SqlParameter[] parameters = {
                new SqlParameter("@ID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@InstanceID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@FormID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@RunState", SqlDbType.VarChar),
                new SqlParameter("@WfState", SqlDbType.UniqueIdentifier),
                new SqlParameter("@WfDealWayId", SqlDbType.UniqueIdentifier),
                new SqlParameter("@TransactType", SqlDbType.VarChar),
                new SqlParameter("@StateDescription", SqlDbType.NVarChar),
                new SqlParameter("@DealPersonLevel", SqlDbType.Int),
                new SqlParameter("@DealDeptLevel", SqlDbType.Int),
                new SqlParameter("@TransactUserID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@TransactUserName", SqlDbType.NVarChar),
                new SqlParameter("@TransactDepartmentID", SqlDbType.UniqueIdentifier),
                new SqlParameter("@TransactDepartmentName", SqlDbType.NVarChar),
                new SqlParameter("@DealPersonInfo", SqlDbType.NVarChar),
                new SqlParameter("@CreateTime", SqlDbType.DateTime),
                new SqlParameter("@CompleteTime", SqlDbType.DateTime),
                new SqlParameter("@IsDeleted", SqlDbType.Bit),
                new SqlParameter("@BlankCol1", SqlDbType.VarChar),
                new SqlParameter("@BlankCol2", SqlDbType.VarChar),
                new SqlParameter("@BlankCol3", SqlDbType.NVarChar),
                new SqlParameter("@BlankCol4", SqlDbType.NVarChar)
            };

            int i = 0;
            parameters[i++].Value = entity.ID;
            parameters[i++].Value = entity.InstanceID;
            parameters[i++].Value = entity.FormID;
            parameters[i++].Value = entity.RunState;
            parameters[i++].Value = entity.WfState;
            parameters[i++].Value = entity.WfDealWayId;
            parameters[i++].Value = entity.TransactType;
            parameters[i++].Value = entity.StateDescription;
            parameters[i++].Value = entity.DealPersonLevel;
            parameters[i++].Value = entity.DealDeptLevel;
            parameters[i++].Value = entity.TransactUserID;
            parameters[i++].Value = entity.TransactUserName;
            parameters[i++].Value = entity.TransactDepartmentID;
            parameters[i++].Value = entity.TransactDepartmentName;
            parameters[i++].Value = entity.DealPersonInfo;
            if (entity.CreateTime == DateTime.MinValue)
                entity.CreateTime = (DateTime)SqlDateTime.MinValue;
            parameters[i++].Value = entity.CreateTime;
            if (entity.CompleteTime != DateTime.MinValue)
            {
                parameters[i++].Value = entity.CompleteTime;
            }
            else
            {
                i++;
            }
            parameters[i++].Value = entity.IsDeleted;
            parameters[i++].Value = entity.BlankCol1;
            parameters[i++].Value = entity.BlankCol2;
            parameters[i++].Value = entity.BlankCol3;
            parameters[i++].Value = entity.BlankCol4;

            return DataHelper.ExecuteNoneQuery(strSql.ToString(), parameters) > 0;
        }
Exemplo n.º 15
0
        /// <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;
            }
        }
Exemplo n.º 16
0
 /// <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);
 }
Exemplo n.º 17
0
        /// <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);
            }
        }
Exemplo n.º 18
0
        /// <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;
        }
Exemplo n.º 19
0
        /// <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;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        ///流转后,维护流程实例ACL表和流程消息表()
        /// </summary>
        /// <param name="formId"></param>
        ///<param name="currentStateEntity"> </param>
        ///<param name="wfTemplateId"> </param>
        ///<param name="businessType"></param>
        /// <param name="dealPersonInfos"></param>
        /// <param name="wfInstancestates"> </param>
        public static void ManageWfInstanceAclandMessage(Guid formId, WfStatesEntity currentStateEntity, Guid wfTemplateId, string businessType, string dealPersons, WfInstanceStatesEntity wfInstancestates)
        {
            try
            {
                var currentWfStateId = currentStateEntity.StateId;

                var dealPersonInfos = GetDealPersonInfoFromStr(dealPersons);

                using (TransactionScope scope = new TransactionScope())
                {
                    var instanceStateDealPeronList = new List<DealPersonInfo>();

                    //更新待办为已办
                    UpdateWfMessages(formId, wfInstancestates.TransactUserID, wfInstancestates.InstanceID);

                    var way = WfDealWayEntity.Get(wfInstancestates.WfDealWayId);
                    if (wfInstancestates.WfDealWayId != Guid.Empty && way != null && way.DealWayType == 1)
                    {
                        #region 处理方式-撤回(找上一次流转人)

                        //通过处理方式的目标 环节 找流转记录
                        var wfInstanceStates = WfInstanceStatesBusiness.GetWfInstanceStatesByID(formId, wfInstancestates.WfState, wfInstancestates.InstanceID);

                        var newDealPersonList = new List<DealPersonInfo>();
                        var backPerson = new DealPersonInfo();
                        backPerson.DeptId = wfInstanceStates.TransactDepartmentID;
                        backPerson.DeptName = wfInstanceStates.TransactDepartmentName;
                        backPerson.PersonId = wfInstanceStates.TransactUserID;
                        backPerson.PersonName = wfInstanceStates.TransactUserName;
                        newDealPersonList.Add(backPerson);

                        WriteAcletc(formId, newDealPersonList, wfInstancestates.TransactUserID, wfInstancestates.InstanceID, businessType, currentWfStateId);

                        instanceStateDealPeronList = newDealPersonList;

                        #endregion
                    }
                    else if (wfInstancestates.WfDealWayId != Guid.Empty && way != null && way.DealWayType == 2)
                    {
                        #region 处理方式-退回

                        List<DealPersonInfo> listBack = Interfaces.GetDealPersonByLine(formId, wfInstancestates.WfDealWayId);

                        WriteAcletc(formId, listBack, wfInstancestates.TransactUserID, wfInstancestates.InstanceID, businessType, currentWfStateId);

                        instanceStateDealPeronList = listBack;

                        #endregion
                    }
                    else
                    {
                        #region 正常流转

                        var newDealPersonList = new List<DealPersonInfo>();

                        if (dealPersonInfos != null && dealPersonInfos.Count > 0) //外围选定下环节处理人,以外围选定发待办
                        {
                            #region 根据外围选择用户流转

                            foreach (var dealPerson in dealPersonInfos)
                            {
                                if (currentStateEntity.IsRestrictUserDept)//判断处理人是否限定部门
                                {
                                    var deptID = wfInstancestates.TransactDepartmentID;
                                    if (dealPerson.DeptId == deptID)
                                    {
                                        newDealPersonList.Add(dealPerson);
                                    }
                                }
                                else
                                {
                                    newDealPersonList.Add(dealPerson);
                                }
                            }

                            #endregion
                        }
                        else //外围不选,依据 WF_Define_ACL 定义
                        {
                            var sql = string.Format(" select distinct(a.RoleCode)  from WF_Define_ACL a with (nolock)  where a.WfTemplateID='{0}' and a.ObjectID='{1}'", wfTemplateId, currentWfStateId);
                            var dt = DataHelper.ExecuteQuery(sql);
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                #region 根据环节选择的角色流转

                                var roleCodes = new List<string>();

                                foreach (DataRow row in dt.Rows)
                                {
                                    roleCodes.Add(row["RoleCode"].ToString());
                                }

                                List<WFRoleUserEntity> list = new List<WFRoleUserEntity>();

                                #region 通过角色、部门信息获取处理人

                                Guid deptID = wfInstancestates.TransactDepartmentID;
                                if (currentStateEntity.IsRestrictUserDept)//判断处理人是否限定部门
                                {
                                    list = WFRoleUserBusiness.GetUserList(roleCodes, deptID);
                                }
                                else if (currentStateEntity.IsRestrictTopDept)
                                {
                                    //获取当前部门信息
                                    var current = WFCustomBusiness.GetCustomEntity(deptID);
                                    if (current != null && current.ParentGUID != Guid.Empty)
                                    {
                                        list = WFRoleUserBusiness.GetUserList(roleCodes, current.ParentGUID);
                                    }
                                }
                                else
                                {
                                    list = WFRoleUserBusiness.GetUserList(roleCodes, Guid.Empty);
                                }

                                #endregion

                                if (list != null && list.Count > 0)
                                {
                                    List<DealPersonInfo> listDeal = new List<DealPersonInfo>();
                                    foreach (var entity in list)
                                    {
                                        DealPersonInfo deal = new DealPersonInfo();
                                        deal.DeptId = entity.DeptGuid;
                                        deal.DeptName = entity.DeptName;
                                        deal.PersonId = entity.UserGuid;
                                        deal.PersonName = entity.UserName;
                                        newDealPersonList.Add(deal);
                                    }
                                }

                                #region 三统一接口获取处理人 - 优化去除

                                //var dealpersonInfos = Interfaces.GetDealPersonInfoFromOuter(roleCodes);  //根据角色ID列表得到具体处理人信息列表
                                //if (dealpersonInfos != null && dealpersonInfos.Count > 0)
                                //{
                                //    #region 判断是否验证关区

                                //    //判断是否验证关区
                                //    string checkCustom = ConfigurationManager.AppSettings["BillCustomCheck"];
                                //    bool isCheck = false;
                                //    if (!string.IsNullOrEmpty(checkCustom) && Convert.ToBoolean(checkCustom))
                                //    {
                                //        isCheck = true;
                                //    }

                                //    #endregion

                                //    if (currentStateEntity.IsRestrictUserDept)//判断处理人是否限定部门
                                //    {
                                //        #region 限定部门

                                //        var deptID = wfInstancestates.TransactDepartmentID;

                                //        foreach (var dealPerson in dealpersonInfos)
                                //        {
                                //            if (isCheck)
                                //            {
                                //                //根据用户路径匹配关区信息
                                //                var entity = WFCustomBusiness.GetBestMatchCustom(dealPerson.AllPathName);
                                //                if (entity != null)
                                //                {
                                //                    dealPerson.DeptId = entity.GUID;
                                //                    dealPerson.DeptName = entity.CustomName;
                                //                }
                                //            }

                                //            if (dealPerson.DeptId == deptID)
                                //            {
                                //                newDealPersonList.Add(dealPerson);
                                //            }
                                //        }

                                //        #endregion
                                //    }
                                //    else if (currentStateEntity.IsRestrictTopDept)
                                //    {
                                //        #region 限定上级部门

                                //        var deptID = wfInstancestates.TransactDepartmentID;

                                //        //获取当前部门信息
                                //        var current = WFCustomBusiness.GetCustomEntity(deptID);
                                //        if (current != null && current.ParentGUID != Guid.Empty)
                                //        {
                                //            foreach (var dealPerson in dealpersonInfos)
                                //            {
                                //                if (isCheck)
                                //                {
                                //                    //根据用户路径匹配关区信息
                                //                    var entity = WFCustomBusiness.GetBestMatchCustom(dealPerson.AllPathName);
                                //                    if (entity != null)
                                //                    {
                                //                        dealPerson.DeptId = entity.GUID;
                                //                        dealPerson.DeptName = entity.CustomName;
                                //                    }
                                //                }

                                //                if (dealPerson.DeptId == current.ParentGUID)
                                //                {
                                //                    newDealPersonList.Add(dealPerson);
                                //                }
                                //            }
                                //        }

                                //        #endregion
                                //    }
                                //    else
                                //    {
                                //        #region 默认处理

                                //        foreach (var dealPerson in dealpersonInfos)
                                //        {
                                //            if (isCheck)
                                //            {
                                //                //根据用户路径匹配关区信息
                                //                var entity = WFCustomBusiness.GetBestMatchCustom(dealPerson.AllPathName);
                                //                if (entity != null)
                                //                {
                                //                    dealPerson.DeptId = entity.GUID;
                                //                    dealPerson.DeptName = entity.CustomName;
                                //                }
                                //            }

                                //            newDealPersonList.Add(dealPerson);
                                //        }

                                //        #endregion
                                //    }
                                //}

                                #endregion

                                #endregion
                            }
                            else
                            {
                                #region 没有角色(默认提交人)

                                var submitPerson = new DealPersonInfo();
                                var instanceEntity = WfInstanceBusiness.GetWfInstanceBusinessByFormID(formId);
                                if (instanceEntity != null)
                                {
                                    submitPerson.DeptId = instanceEntity.StartDepartmentID;
                                    submitPerson.DeptName = instanceEntity.StartDepartmentName;
                                    submitPerson.PersonId = instanceEntity.StartUserID;
                                    submitPerson.PersonName = instanceEntity.StartUserName;
                                    newDealPersonList.Add(submitPerson);
                                }
                                else
                                {
                                    submitPerson.DeptId = wfInstancestates.TransactDepartmentID;
                                    submitPerson.DeptName = wfInstancestates.TransactDepartmentName;
                                    submitPerson.PersonId = wfInstancestates.TransactUserID;
                                    submitPerson.PersonName = wfInstancestates.TransactUserName;
                                    newDealPersonList.Add(submitPerson);
                                }

                                #endregion
                            }
                        }

                        if (newDealPersonList != null && newDealPersonList.Count > 0)
                        {
                            WriteAcletc(formId, newDealPersonList, wfInstancestates.TransactUserID, wfInstancestates.InstanceID, businessType, currentWfStateId);
                            instanceStateDealPeronList = newDealPersonList;
                        }

                        #endregion
                    }

                    #region 转换处理人员

                    var stateDealPersons = string.Empty;
                    if (instanceStateDealPeronList != null && instanceStateDealPeronList.Count > 0)
                    {
                        var strPerson = new StringBuilder();
                        foreach (var personInfo in instanceStateDealPeronList)
                        {
                            strPerson.Append(personInfo.PersonName);
                            strPerson.Append(",");
                        }
                        stateDealPersons = strPerson.ToString().TrimEnd(',');
                    }

                    #endregion

                    wfInstancestates.DealPersonInfo = stateDealPersons;
                    WfInstanceStatesBusiness.UpdateWfInstanceState(wfInstancestates);

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                LogWritter.WriteSystemExceptionLog(ex);
            }
        }