//----------------------------------------------------- // 启动工作流 步骤流 //----------------------------------------------------- /// <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) { string currentId = string.Empty; if (dtWorkFlowActivity == null || dtWorkFlowActivity.Rows.Count == 0) { return currentId; } lock (WorkFlowCurrentLock) { BaseWorkFlowStepEntity workFlowStepEntity = null; // 这里需要读取一下 if (dtWorkFlowActivity == null) { } workFlowStepEntity = new 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. 把当前的流程设置保存好 foreach (DataRow dataRow in dtWorkFlowActivity.Rows) { workFlowStepEntity = new BaseWorkFlowStepEntity(dataRow); workFlowStepEntity.ActivityId = workFlowStepEntity.Id; workFlowStepEntity.CategoryCode = categoryCode; workFlowStepEntity.ObjectId = objectId; workFlowStepEntity.Id = null; workFlowStepManager.Add(workFlowStepEntity); } workFlowStepEntity = new 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()) { this.UpdataAuditStatr(currentId, categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity); } // 不是的话则返回 else { // 该单据已进入审核状态不能在次提交 this.ReturnStatusCode = StatusCode.ErrorChanged.ToString(); // 返回为空可以判断 currentId = null; } } else { workFlowManager.BeforeAutoStatr(objectId); currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity); workFlowCurrentEntity = this.GetEntity(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.AfterAutoStatr(objectId); } // 运行成功 this.ReturnStatusCode = StatusCode.OK.ToString(); this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode); } } return currentId; }
//----------------------------------------------------- // 启动工作流 自由流 //----------------------------------------------------- /// <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="toUserId"></param> /// <param name="toDepartmentId"></param> /// <param name="toRoleId"></param> /// <param name="auditIdea"></param> /// <returns></returns> public string FreeStart(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName, string workFlowCode, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null) { // 获取当前工作流步骤 string currentId = this.GetCurrentId(categoryCode, objectId); // 定义步骤实体 BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity(); // FreeWorkFlow 自由工作流 workFlowStepEntity.WorkFlowId = 0; // 获取排序码 workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence(workFlowCode, 10000000)); // 是否提交给用户审批 if (!string.IsNullOrEmpty(toUserId)) { workFlowStepEntity.AuditUserId = toUserId; workFlowStepEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName; } // 是否提交给部门审批 if (!string.IsNullOrEmpty(toDepartmentId)) { workFlowStepEntity.AuditDepartmentId = toDepartmentId; workFlowStepEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName; } // 是否提交给角色审批 if (!string.IsNullOrEmpty(toRoleId)) { workFlowStepEntity.AuditRoleId = toRoleId; workFlowStepEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName; } if (workFlowManager != null) { workFlowManager.BeforeAutoStatr(objectId); } // 如果已经存在 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); } // 不是的话则返回 else { // 该单据已进入审核状态不能在次提交 this.ReturnStatusCode = StatusCode.ErrorChanged.ToString(); // 返回为空可以判断 currentId = null; return currentId; } } else { // 新增 currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity); } BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(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 (workFlowManager != null && !string.IsNullOrEmpty(objectId)) { workFlowManager.AfterAutoStatr(objectId); } // 运行成功 this.ReturnStatusCode = StatusCode.OK.ToString(); this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode); return currentId; }
//----------------------------------------------------- // 启动工作流 自由流 //----------------------------------------------------- /// <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="toUserId"></param> /// <param name="toDepartmentId"></param> /// <param name="toRoleId"></param> /// <param name="auditIdea"></param> /// <returns></returns> public string FreeStart(IWorkFlowManager workFlowManager, string objectId, string objectFullName, string categoryCode, string categoryFullName, string workFlowCode, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null) { // 获取当前工作流步骤 string currentId = this.GetCurrentId(categoryCode, objectId); // 定义步骤实体 BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity(); // FreeWorkFlow 自由工作流 workFlowStepEntity.WorkFlowId = 0; // 获取排序码 workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence(workFlowCode, 10000000)); // 是否提交给用户审批 if (!string.IsNullOrEmpty(toUserId)) { workFlowStepEntity.AuditUserId = toUserId; workFlowStepEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName; } // 是否提交给部门审批 if (!string.IsNullOrEmpty(toDepartmentId)) { workFlowStepEntity.AuditDepartmentId = toDepartmentId; workFlowStepEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName; } // 是否提交给角色审批 if (!string.IsNullOrEmpty(toRoleId)) { workFlowStepEntity.AuditRoleId = toRoleId; workFlowStepEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName; } if (workFlowManager != null) { workFlowManager.BeforeAutoStatr(objectId); } // 如果已经存在 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); } // 不是的话则返回 else { // 该单据已进入审核状态不能在次提交 this.ReturnStatusCode = StatusCode.ErrorChanged.ToString(); // 返回为空可以判断 currentId = null; return(currentId); } } else { // 新增 currentId = this.StepAuditStatr(categoryCode, categoryFullName, objectId, objectFullName, auditIdea, workFlowStepEntity); } BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(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 (workFlowManager != null && !string.IsNullOrEmpty(objectId)) { workFlowManager.AfterAutoStatr(objectId); } // 运行成功 this.ReturnStatusCode = StatusCode.OK.ToString(); this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode); return(currentId); }