/// <summary> /// 获取数据 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>数据表</returns> public DataTable GetDataTable(BaseUserInfo userInfo, string id = null) { var dt = new DataTable(BaseWorkFlowProcessEntity.TableName); var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessWorkFlowDb(userInfo, parameter, (dbHelper) => { var workFlowManager = new BaseWorkFlowProcessManager(dbHelper, userInfo); if (string.IsNullOrEmpty(id)) { dt = workFlowManager.GetDataTable(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldDeletionStateCode, 0), BaseWorkFlowProcessEntity.FieldSortCode); } else { //dt = workFlowManager.GetDataTableById(id); List <KeyValuePair <string, object> > parametersList = new List <KeyValuePair <string, object> >(); parametersList.Add(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldDeletionStateCode, 0)); parametersList.Add(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldId, id)); dt = workFlowManager.GetDataTable(parametersList, BaseWorkFlowProcessEntity.FieldSortCode); } //result = workFlowManager.GetDataTable(); dt.TableName = BaseWorkFlowProcessEntity.TableName; }); return(dt); }
/// <summary> /// 获取数据 /// </summary> /// <param name="userInfo">用户</param> /// <param name="id">主键</param> /// <returns>数据表</returns> public DataTable GetDataTable(BaseUserInfo userInfo, string id = null) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif DataTable dataTable = new DataTable(BaseWorkFlowProcessEntity.TableName); using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.WorkFlowDbType)) { try { dbHelper.Open(WorkFlowDbConnection); BaseWorkFlowProcessManager workFlowManager = new BaseWorkFlowProcessManager(dbHelper, userInfo); if (string.IsNullOrEmpty(id)) { dataTable = workFlowManager.GetDataTable(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldDeletionStateCode, 0), BaseWorkFlowProcessEntity.FieldSortCode); } else { dataTable = workFlowManager.GetDataTable(id); } //dataTable = workFlowManager.GetDataTable(); dataTable.TableName = BaseWorkFlowProcessEntity.TableName; } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(dataTable); }
//----------------------------------------------------- // 启动工作流 步骤流 //----------------------------------------------------- /// <summary> /// 启动工作流(步骤流转) /// </summary> /// <param name="workFlowManager">审批流程管理器</param> /// <param name="objectId">单据主键</param> /// <param name="objectFullName">单据名称</param> /// <param name="categoryCode">单据分类</param> /// <param name="categoryFullName">单据分类名称</param> /// <param name="workFlowCode">工作流程</param> /// <param name="auditIdea">审批意见</param> /// <param name="dtWorkFlowActivity">需要走的流程</param> /// <returns>主键</returns> public string AutoStatr(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName = null, string workFlowCode = null, string auditIdea = null, DataTable dtWorkFlowActivity = null) { if (workFlowManager == null && !string.IsNullOrEmpty(categoryCode)) { if (string.IsNullOrEmpty(workFlowCode)) { workFlowCode = categoryCode; } workFlowManager = new BaseWorkFlowProcessManager(this.DbHelper, this.UserInfo).GetWorkFlowManagerByCode(workFlowCode); // workFlowManager = new BaseUserBillManager(this.DbHelper, this.UserInfo, categoryCode); } BaseWorkFlowAuditInfo workFlowAuditInfo = new BaseWorkFlowAuditInfo(); workFlowAuditInfo.CategoryCode = categoryCode; workFlowAuditInfo.ObjectId = objectId; workFlowAuditInfo.CallBackTable = workFlowManager.CurrentTableName; workFlowAuditInfo.ProcessCode = workFlowCode; string currentId = string.Empty; // 看审批流程是否被定义 if (dtWorkFlowActivity == null || dtWorkFlowActivity.Rows.Count == 0) { BaseWorkFlowProcessManager workFlowProcessManager = new BaseWorkFlowProcessManager(this.DbHelper, this.UserInfo); var dt = workFlowProcessManager.GetDataTable( new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldCode, workFlowCode) , new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldDeletionStateCode, 0), BaseWorkFlowProcessEntity.FieldSortCode); BaseWorkFlowProcessEntity workFlowProcessEntity = null; foreach (DataRow dr in dt.Rows) { workFlowProcessEntity = BaseEntity.Create <BaseWorkFlowProcessEntity>(dr); // 这里是进入条件,结束条件进行筛选 // 进入条件是否满足 if (!string.IsNullOrEmpty(workFlowProcessEntity.EnterConstraint)) { if (!Evaluate(workFlowAuditInfo.CallBackTable, objectId, workFlowProcessEntity.EnterConstraint)) { // 没有满足入口条件 dr.Delete(); } } } dt.AcceptChanges(); if (dt.Rows.Count == 0) { return(currentId); } workFlowProcessEntity = BaseEntity.Create <BaseWorkFlowProcessEntity>(dt); // 这里是获取用户的走的流程 dtWorkFlowActivity = new BaseWorkFlowActivityManager(this.UserInfo).GetActivityDTById(workFlowProcessEntity.Id.ToString()); // dtWorkFlowActivity = new BaseWorkFlowActivityManager(this.UserInfo).GetActivityDTByCode(workFlowCode); if (dtWorkFlowActivity.Rows.Count == 0) { return(currentId); } } lock (WorkFlowCurrentLock) { BaseWorkFlowStepEntity workFlowStepEntity = null; // 这里需要读取一下 if (dtWorkFlowActivity == null) { } workFlowStepEntity = BaseEntity.Create <BaseWorkFlowStepEntity>(dtWorkFlowActivity.Rows[0]); if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { // 若是任意人可以审核的,需要进行一次人工选任的工作 if (workFlowStepEntity.AuditUserId.Equals("Anyone")) { return(null); } } // 1. 先把已有的流程设置功能都删除掉 BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo); workFlowStepManager.Delete(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, categoryCode) , new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, objectId)); // 2. 把当前的流程设置保存好 BaseWorkFlowActivityEntity activityEntity = null; // 是否已经满足了条件了 bool endConstraint = false; foreach (DataRow dr in dtWorkFlowActivity.Rows) { // 是否已经结束流程了 if (endConstraint) { dr.Delete(); } else { activityEntity = BaseEntity.Create <BaseWorkFlowActivityEntity>(dr); // 这里是进入条件,结束条件进行筛选 // 进入条件是否满足 if (!string.IsNullOrEmpty(activityEntity.EnterConstraint)) { if (!Evaluate(workFlowAuditInfo.CallBackTable, objectId, activityEntity.EnterConstraint)) { // 没有满足入口条件 dr.Delete(); } } // 结束条件是否满足 if (!string.IsNullOrEmpty(activityEntity.EndConstraint)) { if (Evaluate(workFlowAuditInfo.CallBackTable, objectId, activityEntity.EndConstraint)) { // 已经满足了结束条件了 dr.Delete(); endConstraint = true; } } } } dtWorkFlowActivity.AcceptChanges(); // 没有任何审核流程步骤了 if (dtWorkFlowActivity.Rows.Count == 0) { return(null); } // 建立审核步骤表,需要走哪些审核步骤的具体步骤表 foreach (DataRow dr in dtWorkFlowActivity.Rows) { workFlowStepEntity = BaseEntity.Create <BaseWorkFlowStepEntity>(dr); // workFlowStepEntity.ActivityId = workFlowActivityEntity.Id; // workFlowStepEntity.ActivityType = workFlowActivityEntity.ActivityType; workFlowStepEntity.CategoryCode = categoryCode; workFlowStepEntity.ObjectId = objectId; workFlowStepEntity.Id = null; workFlowStepManager.Add(workFlowStepEntity); } workFlowStepEntity = BaseEntity.Create <BaseWorkFlowStepEntity>(dtWorkFlowActivity.Rows[0]); // 3. 启动审核流程 currentId = this.GetCurrentId(categoryCode, objectId); BaseWorkFlowCurrentEntity workFlowCurrentEntity = null; if (currentId.Length > 0) { // 获取当前处于什么状态 string auditstatus = this.GetProperty(currentId, BaseWorkFlowCurrentEntity.FieldAuditStatus); // 如果还是开始审批状态的话,允许他再次提交把原来的覆盖掉 if (auditstatus == AuditStatus.StartAudit.ToString() || auditstatus == AuditStatus.AuditReject.ToString()) { this.UpdataAuditStatr(currentId, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity); if (workFlowManager != null) { workFlowManager.AfterAutoStatr(workFlowAuditInfo); } } // 不是的话则返回 else { // 该单据已进入审核状态不能在次提交 this.StatusCode = Status.ErrorChanged.ToString(); // 返回为空可以判断 currentId = null; } } else { if (workFlowManager != null) { workFlowManager.BeforeAutoStatr(workFlowAuditInfo); } currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity); workFlowCurrentEntity = this.GetObject(currentId); // 发送提醒信息,若发给指定的某个人了,就不发给部门的提示信息了 if (workFlowManager != null) { if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { workFlowStepEntity.AuditDepartmentId = null; workFlowStepEntity.AuditRoleId = null; } workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.StartAudit, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId); } // 成功工作流后的处理 if (!string.IsNullOrEmpty(objectId) && workFlowManager != null) { workFlowManager.AfterAutoStatr(workFlowAuditInfo); } // 运行成功 this.StatusCode = Status.OK.ToString(); this.StatusMessage = this.GetStateMessage(this.StatusCode); } } return(currentId); }