/// <summary> /// 审核退回(不需要再发给别人了) /// </summary> /// <param name="currentId">当前主键</param> /// <param name="auditIdea">批示</param> /// <returns>影响行数</returns> private int StepAuditReject(string currentId, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId); // 1.记录当前的审核时间、审核人信息 workFlowCurrentEntity.AuditDate = DateTime.Now; workFlowCurrentEntity.AuditIdea = auditIdea; workFlowCurrentEntity.AuditUserId = this.UserInfo.Id; workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName; workFlowCurrentEntity.AuditStatus = AuditStatus.AuditReject.ToString(); workFlowCurrentEntity.AuditStatusName = AuditStatus.AuditReject.ToDescription(); if (!string.IsNullOrEmpty(workFlowCurrentEntity.ActivityFullName)) { workFlowCurrentEntity.Description = string.Format("从{0}退回到{1}{2}", workFlowCurrentEntity.ActivityFullName, workFlowStepEntity.ActivityFullName, !string.IsNullOrEmpty(workFlowStepEntity.Description) ? "," + workFlowStepEntity.Description : string.Empty); } // 2.记录审核日志 this.AddHistory(workFlowCurrentEntity); // 3.上一个审核结束了,新的审核又开始了,更新待审核情况 workFlowCurrentEntity.ActivityId = workFlowStepEntity.ActivityId; workFlowCurrentEntity.ActivityCode = workFlowStepEntity.ActivityCode; workFlowCurrentEntity.ActivityFullName = workFlowStepEntity.ActivityFullName; workFlowCurrentEntity.ActivityType = workFlowStepEntity.ActivityType; workFlowCurrentEntity.ToRoleId = workFlowStepEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = workFlowStepEntity.AuditRoleRealName; workFlowCurrentEntity.ToDepartmentId = workFlowStepEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName; workFlowCurrentEntity.ToUserId = workFlowStepEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = workFlowStepEntity.AuditUserRealName; workFlowCurrentEntity.SortCode = workFlowStepEntity.SortCode; return(this.UpdateObject(workFlowCurrentEntity)); }
/// <summary> /// 审核通过(不需要再发给别人了是完成审批了) /// </summary> /// <param name="currentId">当前主键</param> /// <param name="auditIdea">批示</param> /// <param name="toStepEntity">审核到第几步</param> /// <param name="workFlowAuditInfo">当前审核人信息</param> /// <returns>影响行数</returns> private int StepAuditPass(string currentId, string auditIdea, BaseWorkFlowStepEntity toStepEntity, BaseWorkFlowAuditInfo workFlowAuditInfo = null) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId); // 初始化审核信息,这里是显示当前审核人,可以不是当前操作员的功能 if (workFlowAuditInfo == null) { workFlowAuditInfo = new BaseWorkFlowAuditInfo(this.UserInfo); workFlowAuditInfo.AuditIdea = auditIdea; workFlowAuditInfo.AuditDate = DateTime.Now; workFlowAuditInfo.AuditUserId = this.UserInfo.Id; workFlowAuditInfo.AuditUserRealName = this.UserInfo.RealName; workFlowAuditInfo.AuditStatus = AuditStatus.AuditPass.ToString(); workFlowAuditInfo.AuditStatusName = AuditStatus.AuditPass.ToDescription(); } else { workFlowAuditInfo.AuditIdea = auditIdea; } // 审核意见是什么? workFlowCurrentEntity.AuditIdea = workFlowAuditInfo.AuditIdea; // 1.记录当前的审核时间、审核人信息 // 什么时间审核的? workFlowCurrentEntity.AuditDate = workFlowAuditInfo.AuditDate; // 审核的用户是谁? workFlowCurrentEntity.AuditUserId = workFlowAuditInfo.AuditUserId; // 审核人的姓名是谁? workFlowCurrentEntity.AuditUserRealName = workFlowAuditInfo.AuditUserRealName; // 审核状态是什么? workFlowCurrentEntity.AuditStatus = workFlowAuditInfo.AuditStatus; // 审核状态备注是什么? workFlowCurrentEntity.AuditStatusName = workFlowAuditInfo.AuditStatusName; if (!string.IsNullOrEmpty(workFlowCurrentEntity.ActivityFullName)) { workFlowCurrentEntity.Description = string.Format("从{0}提交到{1}{2}", workFlowCurrentEntity.ActivityFullName, toStepEntity.FullName, !string.IsNullOrEmpty(toStepEntity.Description) ? "," + toStepEntity.Description : string.Empty); } workFlowCurrentEntity.ToUserId = toStepEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = toStepEntity.AuditUserRealName; workFlowCurrentEntity.ToRoleId = toStepEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = toStepEntity.AuditRoleRealName; workFlowCurrentEntity.ToDepartmentId = toStepEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = toStepEntity.AuditDepartmentName; // 2.记录审核日志 this.AddHistory(workFlowCurrentEntity); // 3.上一个审核结束了,新的审核又开始了,更新待审核情况 workFlowCurrentEntity.ActivityId = toStepEntity.ActivityId; workFlowCurrentEntity.ActivityCode = toStepEntity.Code; workFlowCurrentEntity.ActivityFullName = toStepEntity.FullName; workFlowCurrentEntity.ActivityType = toStepEntity.ActivityType; workFlowCurrentEntity.SortCode = toStepEntity.SortCode; return(this.UpdateObject(workFlowCurrentEntity)); }
/// <summary> /// 更新实体 /// </summary> /// <param name="BaseWorkFlowStepEntity">实体</param> public int UpdateEntity(BaseWorkFlowStepEntity BaseWorkFlowStepEntity) { SQLBuilder sqlBuilder = new SQLBuilder(DbHelper); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetEntity(sqlBuilder, BaseWorkFlowStepEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowStepEntity.FieldModifiedOn); sqlBuilder.SetWhere(BaseWorkFlowStepEntity.FieldId, BaseWorkFlowStepEntity.Id); return(sqlBuilder.EndUpdate()); }
/// <summary> /// 设置实体 /// </summary> /// <param name="BaseWorkFlowStepEntity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, BaseWorkFlowStepEntity BaseWorkFlowStepEntity) { sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldCategoryCode, BaseWorkFlowStepEntity.CategoryCode); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldObjectId, BaseWorkFlowStepEntity.ObjectId); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldWorkFlowId, BaseWorkFlowStepEntity.WorkFlowId); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldActivityId, BaseWorkFlowStepEntity.ActivityId); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldCode, BaseWorkFlowStepEntity.Code); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldFullName, BaseWorkFlowStepEntity.FullName); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditDepartmentId, BaseWorkFlowStepEntity.AuditDepartmentId); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditDepartmentName, BaseWorkFlowStepEntity.AuditDepartmentName); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditUserId, BaseWorkFlowStepEntity.AuditUserId); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditUserCode, BaseWorkFlowStepEntity.AuditUserCode); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditUserRealName, BaseWorkFlowStepEntity.AuditUserRealName); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditRoleId, BaseWorkFlowStepEntity.AuditRoleId); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAuditRoleRealName, BaseWorkFlowStepEntity.AuditRoleRealName); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldActivityType, BaseWorkFlowStepEntity.ActivityType); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAllowPrint, BaseWorkFlowStepEntity.AllowPrint); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldAllowEditDocuments, BaseWorkFlowStepEntity.AllowEditDocuments); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldSortCode, BaseWorkFlowStepEntity.SortCode); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldEnabled, BaseWorkFlowStepEntity.Enabled); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldDeletionStateCode, BaseWorkFlowStepEntity.DeletionStateCode); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldDescription, BaseWorkFlowStepEntity.Description); }
/// <summary> /// 获取实体 /// </summary> /// <param name="id">主键</param> public BaseWorkFlowStepEntity GetEntity(string id) { BaseWorkFlowStepEntity BaseWorkFlowStepEntity = new BaseWorkFlowStepEntity(this.GetDataTable(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldId, id))); return(BaseWorkFlowStepEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="BaseWorkFlowStepEntity">实体</param> public int Update(BaseWorkFlowStepEntity BaseWorkFlowStepEntity) { return(this.UpdateEntity(BaseWorkFlowStepEntity)); }
/// <summary> /// 添加 /// </summary> /// <param name="BaseWorkFlowStepEntity">实体</param> /// <param name="identity">自增量方式</param> /// <param name="returnId">返回主鍵</param> /// <returns>主键</returns> public string Add(BaseWorkFlowStepEntity BaseWorkFlowStepEntity, bool identity, bool returnId) { this.Identity = identity; this.ReturnId = returnId; return(this.AddEntity(BaseWorkFlowStepEntity)); }
//----------------------------------------------------- // 启动工作流 步骤流 //----------------------------------------------------- /// <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="workFlowAuditInfo">流程信息</param> /// <returns>影响行数</returns> public int FreeAuditPass(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo) { // 返回值 int result = 0; // 这里用锁的机制,提高并发控制能力 lock (WorkFlowCurrentLock) { try { // 开始事务 this.DbHelper.BeginTransaction(); // 这里需要循环产生前面的没有审批的人的记录,默认都要让他们审批通过才可以? // 在这里处理连续跳过好几个审批的,自动能生成审批记录的功能? BaseWorkFlowCurrentEntity workFlowCurrentEntity = null; workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id); // 当前是什么步骤主键? int?startSortCode = BaseWorkFlowActivityManager.GetEntity(workFlowCurrentEntity.ActivityId).SortCode; // 现在要到什么步骤主键? int?endSortCode = BaseWorkFlowActivityManager.GetEntity(workFlowAuditInfo.ActivityId).SortCode; // 中间还有几个步骤被跳过了? var listEntity = BaseWorkFlowActivityManager.GetEntities().Where(entity => entity.SortCode > startSortCode && entity.SortCode <= endSortCode && entity.Enabled == 1 && entity.DeletionStateCode == 0).OrderBy(entity => entity.SortCode); int i = 0; foreach (var entity in listEntity) { // 这里是需要自动模拟产生的审批用的 BaseWorkFlowAuditInfo workFlowInfo = new BaseWorkFlowAuditInfo(); // 是最后一步了 if (entity.SortCode == endSortCode) { workFlowInfo = workFlowAuditInfo; workFlowInfo.AuditDate = DateTime.Now.AddMinutes(i * 10); } else { workFlowInfo.Id = workFlowAuditInfo.Id; workFlowInfo.ActivityId = entity.Id.ToString(); workFlowInfo.ActivityCode = entity.Code; workFlowInfo.ActivityFullName = entity.FullName; // 这个是默认写入的审核意见 workFlowInfo.AuditIdea = "通过"; workFlowInfo.AuditUserId = entity.DefaultAuditUserId; workFlowInfo.AuditUserCode = BaseUserManager.GetUserCodeByCache(entity.DefaultAuditUserId); workFlowInfo.AuditUserRealName = BaseUserManager.GetRealNameByCache(entity.DefaultAuditUserId); i++; // 这里是生成不一样的审核人日期的方法 workFlowInfo.AuditDate = DateTime.Now.AddMinutes(i * 10); workFlowInfo.AuditStatus = AuditStatus.AuditPass.ToString(); workFlowInfo.AuditStatusName = AuditStatus.AuditPass.ToDescription(); // workFlowInfo.ToUserId = entity.DefaultAuditUserId; // workFlowInfo.ToRoleId = string.Empty; // workFlowInfo.ToDepartmentId = string.Empty; } BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity(); if (!string.IsNullOrEmpty(workFlowInfo.ActivityId)) { workFlowStepEntity.ActivityId = int.Parse(workFlowInfo.ActivityId); workFlowStepEntity.ActivityCode = workFlowInfo.ActivityCode; workFlowStepEntity.ActivityFullName = workFlowInfo.ActivityFullName; } // 是否提交给用户审批 if (!string.IsNullOrEmpty(workFlowInfo.ToUserId)) { workFlowStepEntity.AuditUserId = workFlowInfo.ToUserId; workFlowStepEntity.AuditUserCode = BaseUserManager.GetUserCodeByCache(workFlowInfo.ToUserId); workFlowStepEntity.AuditUserRealName = BaseUserManager.GetRealNameByCache(workFlowInfo.ToUserId); } // 是否提交给部门审批 if (!string.IsNullOrEmpty(workFlowInfo.ToDepartmentId)) { workFlowStepEntity.AuditDepartmentId = workFlowInfo.ToDepartmentId; workFlowStepEntity.AuditDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowInfo.ToDepartmentId); } // 是否提交给角色审批 if (!string.IsNullOrEmpty(workFlowInfo.ToRoleId)) { workFlowStepEntity.AuditRoleId = workFlowInfo.ToRoleId; workFlowStepEntity.AuditRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowInfo.ToRoleId); } // 获取排序码 workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().Increment("WorkFlow", 10000000)); // 进行更新操作,这里有时候需要模拟别人登录 result = this.StepAuditPass(workFlowInfo.Id, workFlowInfo.AuditIdea, workFlowStepEntity, workFlowInfo); if (result == 0) { // 数据可能被删除 this.StatusCode = Status.ErrorDeleted.ToString(); } workFlowCurrentEntity = this.GetObject(workFlowInfo.Id); // 发送提醒信息 if (workFlowManager != null) { if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { workFlowStepEntity.AuditDepartmentId = null; workFlowStepEntity.AuditRoleId = null; } workFlowManager.OnAutoAuditPass(workFlowCurrentEntity); workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId); } } this.StatusMessage = this.GetStateMessage(this.StatusCode); this.DbHelper.CommitTransaction(); } catch (Exception ex) { this.DbHelper.RollbackTransaction(); BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex); this.StatusCode = Status.Error.ToString(); // throw; } finally { this.DbHelper.Close(); } return(result); } }
/// <summary> /// 自由审批退回 /// </summary> /// <param name="workFlowManager">流程控制管理器</param> /// <param name="workFlowAuditInfo">流程信息</param> /// <returns>影响行数</returns> public int FreeAuditReject(IWorkFlowManager workFlowManager, BaseWorkFlowAuditInfo workFlowAuditInfo) { // 返回值 int result = 0; // 这里用锁的机制,提高并发控制能力 lock (WorkFlowCurrentLock) { try { // 开始事务 this.DbHelper.BeginTransaction(); BaseWorkFlowStepEntity workFlowStepEntity = new BaseWorkFlowStepEntity(); if (!string.IsNullOrEmpty(workFlowAuditInfo.ActivityId)) { workFlowStepEntity.ActivityId = int.Parse(workFlowAuditInfo.ActivityId); workFlowStepEntity.ActivityCode = workFlowAuditInfo.ActivityCode; workFlowStepEntity.ActivityFullName = workFlowAuditInfo.ActivityFullName; } // 是否提交给用户审批 if (!string.IsNullOrEmpty(workFlowAuditInfo.ToUserId)) { workFlowStepEntity.AuditUserId = workFlowAuditInfo.ToUserId; workFlowStepEntity.AuditUserRealName = BaseUserManager.GetRealNameByCache(workFlowAuditInfo.ToUserId); } // 是否提交给部门审批 if (!string.IsNullOrEmpty(workFlowAuditInfo.ToDepartmentId)) { workFlowStepEntity.AuditDepartmentId = workFlowAuditInfo.ToDepartmentId; workFlowStepEntity.AuditDepartmentName = BaseOrganizeManager.GetNameByCache(workFlowAuditInfo.ToDepartmentId); } // 是否提交给角色审批 if (!string.IsNullOrEmpty(workFlowAuditInfo.ToRoleId)) { workFlowStepEntity.AuditRoleId = workFlowAuditInfo.ToRoleId; workFlowStepEntity.AuditRoleRealName = BaseRoleManager.GetRealNameByCache(this.UserInfo.SystemCode, workFlowAuditInfo.ToRoleId); } // 获取排序码 workFlowStepEntity.SortCode = int.Parse(new BaseSequenceManager().Increment("WorkFlow", 10000000)); // 进行更新操作 result = this.StepAuditReject(workFlowAuditInfo.Id, workFlowAuditInfo.AuditIdea, workFlowStepEntity); if (result == 0) { // 数据可能被删除 this.StatusCode = Status.ErrorDeleted.ToString(); } BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(workFlowAuditInfo.Id); // 发送提醒信息 if (workFlowManager != null) { if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { workFlowStepEntity.AuditDepartmentId = null; workFlowStepEntity.AuditRoleId = null; } workFlowManager.OnAutoAuditReject(workFlowCurrentEntity); workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditReject, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId); } this.StatusMessage = this.GetStateMessage(this.StatusCode); this.DbHelper.CommitTransaction(); } catch (Exception ex) { this.DbHelper.RollbackTransaction(); BaseExceptionManager.LogException(dbHelper, this.UserInfo, ex); this.StatusCode = Status.Error.ToString(); // throw; } finally { this.DbHelper.Close(); } return(result); } }
/// <summary> /// 审核通过 /// </summary> /// <param name="id">当前主键</param> /// <param name="auditIdea">批示</param> /// <returns>影响行数</returns> public int AuditPass(IWorkFlowManager workFlowManager, string currentId, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity) { int result = 0; // 进行更新操作 result = this.StepAuditPass(currentId, auditIdea, workFlowStepEntity); if (result == 0) { // 数据可能被删除 this.StatusCode = Status.ErrorDeleted.ToString(); } BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId); // 发送提醒信息 if (workFlowManager != null) { if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { workFlowStepEntity.AuditDepartmentId = null; workFlowStepEntity.AuditRoleId = null; } workFlowManager.OnAutoAuditPass(workFlowCurrentEntity); workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowStepEntity.AuditUserId }, workFlowStepEntity.AuditDepartmentId, workFlowStepEntity.AuditRoleId); } this.StatusMessage = this.GetStateMessage(this.StatusCode); return(result); }
/// <summary> /// 审核退回详细步骤 /// </summary> /// <param name="currentId">当前主键</param> /// <param name="auditIdea">批示</param> /// <param name="toUserId">发送给</param> /// <param name="activityId">退回到指定步骤</param> /// <returns>影响行数</returns> private BaseWorkFlowCurrentEntity StepAuditReject(string currentId, string auditIdea, string toUserId = null, string activityId = null) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId); // 1.记录审核时间、审核人 workFlowCurrentEntity.AuditUserId = this.UserInfo.Id; workFlowCurrentEntity.AuditUserCode = this.UserInfo.Code; workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName; workFlowCurrentEntity.AuditStatus = AuditStatus.AuditReject.ToString(); workFlowCurrentEntity.AuditStatusName = AuditStatus.AuditReject.ToDescription(); workFlowCurrentEntity.AuditDate = DateTime.Now; workFlowCurrentEntity.AuditIdea = auditIdea; // 2.记录日志 this.AddHistory(workFlowCurrentEntity); // 3.更新待审核情况,流程已经结束了 workFlowCurrentEntity.ActivityId = null; if (!string.IsNullOrEmpty(activityId)) { workFlowCurrentEntity.ActivityId = int.Parse(activityId); // 1:先看流程审核步骤里是否有这个记录 BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo); BaseWorkFlowStepEntity workFlowStepEntity = BaseEntity.Create <BaseWorkFlowStepEntity>( workFlowStepManager.GetDataTable( new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldActivityId, activityId) , new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId))); if (workFlowStepEntity != null && workFlowStepEntity.Id != null) { workFlowCurrentEntity.SortCode = workFlowStepEntity.SortCode; workFlowCurrentEntity.ToUserId = workFlowStepEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = workFlowStepEntity.AuditUserRealName; workFlowCurrentEntity.ToDepartmentId = workFlowStepEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName; workFlowCurrentEntity.ToRoleId = workFlowStepEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = workFlowStepEntity.AuditRoleRealName; workFlowCurrentEntity.Description = string.Format("从{0}退回到{1}", workFlowCurrentEntity.ActivityFullName, workFlowStepEntity.FullName); workFlowCurrentEntity.ActivityCode = workFlowStepEntity.Code; workFlowCurrentEntity.ActivityFullName = workFlowStepEntity.FullName; } else { // 2:若没在流程审核步骤里那就从定义里找 BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo); BaseWorkFlowActivityEntity workFlowActivityEntity = workFlowActivityManager.GetObject(activityId); workFlowCurrentEntity.SortCode = workFlowActivityEntity.SortCode; workFlowCurrentEntity.ToUserId = workFlowActivityEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = workFlowActivityEntity.AuditUserRealName; workFlowCurrentEntity.ToDepartmentId = workFlowActivityEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowActivityEntity.AuditDepartmentName; workFlowCurrentEntity.ToRoleId = workFlowActivityEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = workFlowActivityEntity.AuditRoleRealName; } } else { if (!string.IsNullOrEmpty(toUserId)) { BaseUserManager userManager = new BaseUserManager(UserInfo); BaseUserEntity userEntity = userManager.GetObject(toUserId); workFlowCurrentEntity.ToUserId = userEntity.Id; workFlowCurrentEntity.ToUserRealName = userEntity.RealName; workFlowCurrentEntity.ToDepartmentId = userEntity.DepartmentId; workFlowCurrentEntity.ToDepartmentName = userEntity.DepartmentName; workFlowCurrentEntity.ToRoleId = null; workFlowCurrentEntity.ToRoleRealName = null; } //workFlowCurrentEntity.SortCode = null; } workFlowCurrentEntity.SendDate = DateTime.Now; workFlowCurrentEntity.Enabled = 0; // 4.生成审核结束的记录 this.UpdateObject(workFlowCurrentEntity); return(workFlowCurrentEntity); }
//----------------------------------------------------- // 启动工作流 步骤流 //----------------------------------------------------- /// <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); }
private string StepAuditStatr(string categoryCode, string categoryFullName, string objectId, string objectFullName, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity) { BaseWorkFlowAuditInfo workFlowAuditInfo = new BaseWorkFlowAuditInfo(); workFlowAuditInfo.CategoryCode = categoryCode; workFlowAuditInfo.CategoryFullName = categoryFullName; workFlowAuditInfo.ObjectId = objectId; workFlowAuditInfo.ObjectFullName = objectFullName; workFlowAuditInfo.AuditIdea = auditIdea; workFlowAuditInfo.ProcessId = workFlowStepEntity.ProcessId; workFlowAuditInfo.ActivityId = workFlowStepEntity.ActivityId.ToString(); workFlowAuditInfo.ActivityCode = workFlowStepEntity.ActivityCode; workFlowAuditInfo.ActivityType = workFlowStepEntity.ActivityType; workFlowAuditInfo.ActivityFullName = workFlowStepEntity.FullName; workFlowAuditInfo.ToUserId = workFlowStepEntity.AuditUserId; workFlowAuditInfo.ToUserRealName = workFlowStepEntity.AuditUserRealName; workFlowAuditInfo.ToDepartmentId = workFlowStepEntity.AuditDepartmentId; workFlowAuditInfo.ToDepartmentName = workFlowStepEntity.AuditDepartmentName; workFlowAuditInfo.ToRoleId = workFlowStepEntity.AuditRoleId; workFlowAuditInfo.ToRoleRealName = workFlowStepEntity.AuditRoleRealName; workFlowAuditInfo.AuditStatus = AuditStatus.WaitForAudit.ToString(); workFlowAuditInfo.AuditStatusName = AuditStatus.WaitForAudit.ToDescription(); return(StepAuditStatr(workFlowAuditInfo)); }
private int UpdataAuditStatr(string id, string categoryCode, string categoryFullName, string objectId, string objectFullName, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(id); workFlowCurrentEntity.CategoryCode = categoryCode; workFlowCurrentEntity.CategoryFullName = categoryFullName; workFlowCurrentEntity.ObjectId = objectId; workFlowCurrentEntity.ObjectFullName = objectFullName; workFlowCurrentEntity.ProcessId = workFlowStepEntity.ProcessId; workFlowCurrentEntity.ActivityId = workFlowStepEntity.Id; workFlowCurrentEntity.ActivityType = workFlowStepEntity.ActivityType; workFlowCurrentEntity.SendDate = DateTime.Now; workFlowCurrentEntity.AuditDate = DateTime.Now; workFlowCurrentEntity.AuditStatus = AuditStatus.StartAudit.ToString(); workFlowCurrentEntity.AuditStatusName = AuditStatus.StartAudit.ToDescription(); // 是否提交给组织机构审批 workFlowCurrentEntity.ToDepartmentId = workFlowStepEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName; // 是否提交给角色审批 workFlowCurrentEntity.ToRoleId = workFlowStepEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = workFlowStepEntity.AuditRoleRealName; // 是否提交给用户审批 workFlowCurrentEntity.ToUserId = workFlowStepEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = workFlowStepEntity.AuditUserRealName; if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { BaseUserManager userManager = new BaseUserManager(UserInfo); BaseUserEntity userEntity = userManager.GetObject(workFlowStepEntity.AuditUserId); workFlowCurrentEntity.ToUserRealName = userEntity.RealName; // 用户的部门信息需要处理 if (!string.IsNullOrEmpty(userEntity.DepartmentId)) { BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo); BaseOrganizeEntity entity = organizeManager.GetObject(userEntity.DepartmentId); workFlowCurrentEntity.ToDepartmentName = entity.FullName; } } // 当前审核人的信息写入当前工作流 workFlowCurrentEntity.AuditUserId = string.Empty; workFlowCurrentEntity.AuditUserCode = string.Empty; workFlowCurrentEntity.AuditUserRealName = string.Empty; workFlowCurrentEntity.AuditIdea = auditIdea; workFlowCurrentEntity.AuditDate = DateTime.Now; int result = this.UpdateObject(workFlowCurrentEntity); this.AddHistory(workFlowCurrentEntity); return(result); }
/// <summary> /// 添加实体 /// </summary> /// <param name="workFlowActivityEntity">实体</param> public string AddEntity(BaseWorkFlowStepEntity workFlowActivityEntity) { string sequence = string.Empty; if (workFlowActivityEntity.SortCode == null || workFlowActivityEntity.SortCode == 0) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); workFlowActivityEntity.SortCode = int.Parse(sequence); } SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, BaseWorkFlowStepEntity.FieldId); if (!this.Identity) { sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldId, workFlowActivityEntity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseWorkFlowStepEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(BaseWorkFlowStepEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (workFlowActivityEntity.Id == null) { if (string.IsNullOrEmpty(sequence)) { BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } workFlowActivityEntity.Id = int.Parse(sequence); } sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldId, workFlowActivityEntity.Id); } } } this.SetEntity(sqlBuilder, workFlowActivityEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowStepEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowStepEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowStepEntity.FieldModifiedOn); if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// (点通过时)当审核通过时 /// </summary> /// <param name="currentId">审批流当前主键</param> /// <param name="auditIdea">批示</param> /// <returns>成功失败</returns> public int AutoAuditPass(IWorkFlowManager workFlowManager, string currentId, string auditIdea) { int result = 0; // 这里要加锁,防止并发提交 // 这里用锁的机制,提高并发控制能力 lock (WorkFlowCurrentLock) { // using (TransactionScope transactionScope = new TransactionScope()) //{ //try //{ // 1. 先获得现在的状态?当前的工作流主键、当前的审核步骤主键? BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetObject(currentId); // 只有待审核状态的,才可以通过,被退回的也可以重新提交 if (!(workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.StartAudit.ToString()) || workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditPass.ToString()) || workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.WaitForAudit.ToString()) || workFlowCurrentEntity.AuditStatus.Equals(AuditStatus.AuditReject.ToString()) )) { return(result); } // 是不是给当前人审核的,或者当前人在委托的人? if (!string.IsNullOrEmpty(workFlowCurrentEntity.ToUserId)) { if (!(workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.Id) || workFlowCurrentEntity.ToUserId.IndexOf(this.UserInfo.Id) >= 0 // || workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.TargetUserId) )) { return(result); } } // 获取下一步是谁审核。 BaseWorkFlowStepEntity workFlowStepEntity = this.GetNextWorkFlowStep(workFlowCurrentEntity); // 3. 进行下一步流转?转给角色?还是传给用户? if (workFlowStepEntity == null || workFlowStepEntity.Id == null) { // 4. 若没下一步了,那就得结束流程了?审核结束了 result = this.AuditComplete(workFlowManager, currentId, auditIdea); } else { // 审核进入下一步 // 当前是哪个步骤? // 4. 是否已经在工作流里了? // 5. 若已经在工作流里了,那就进行更新操作? if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { // 若是任意人可以审核的,需要进行一次人工选任的工作 if (workFlowStepEntity.AuditUserId.Equals("Anyone")) { return(result); } } // 按用户审核,审核通过 result = AuditPass(workFlowManager, currentId, auditIdea, workFlowStepEntity); } //} //catch (System.Exception ex) //{ // 在本地记录异常 // FileUtil.WriteException(UserInfo, ex); //} //finally //{ //} // transactionScope.Complete(); //} } return(result); }
private int UpdataAuditStatr(string id, string categoryCode, string categoryFullName, string objectId, string objectFullName, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(id); workFlowCurrentEntity.CategoryCode = categoryCode; workFlowCurrentEntity.CategoryFullName = categoryFullName; workFlowCurrentEntity.ObjectId = objectId; workFlowCurrentEntity.ObjectFullName = objectFullName; workFlowCurrentEntity.WorkFlowId = workFlowStepEntity.WorkFlowId; workFlowCurrentEntity.ActivityId = workFlowStepEntity.Id; workFlowCurrentEntity.SendDate = DateTime.Now; workFlowCurrentEntity.AuditDate = DateTime.Now; workFlowCurrentEntity.AuditStatus = AuditStatus.StartAudit.ToString(); workFlowCurrentEntity.AuditStatusName = AuditStatus.StartAudit.ToDescription(); // 是否提交给组织机构审批 if (!string.IsNullOrEmpty(workFlowStepEntity.AuditDepartmentId)) { workFlowCurrentEntity.ToDepartmentId = workFlowStepEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName; } // 是否提交给角色审批 if (!string.IsNullOrEmpty(workFlowStepEntity.AuditRoleId)) { workFlowCurrentEntity.ToDepartmentId = workFlowStepEntity.AuditRoleId; workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditRoleRealName; } // 是否提交给用户审批 if (!string.IsNullOrEmpty(workFlowStepEntity.AuditUserId)) { BaseUserManager userManager = new BaseUserManager(UserInfo); BaseUserEntity userEntity = userManager.GetEntity(workFlowStepEntity.AuditUserId); workFlowCurrentEntity.ToUserId = workFlowStepEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = userEntity.RealName; // TODO 用户的部门信息需要处理 if (!string.IsNullOrEmpty(userEntity.DepartmentId)) { BaseOrganizeManager organizeManager = new BaseOrganizeManager(UserInfo); BaseOrganizeEntity organizeEntity = organizeManager.GetEntity(userEntity.DepartmentId); workFlowCurrentEntity.ToDepartmentId = userEntity.DepartmentId; workFlowCurrentEntity.ToDepartmentName = organizeEntity.FullName; } } // 当前审核人的信息写入当前工作流 // workFlowCurrentEntity.AuditUserId = this.UserInfo.Id; // workFlowCurrentEntity.AuditUserCode = this.UserInfo.Code; // workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName; workFlowCurrentEntity.AuditIdea = auditIdea; workFlowCurrentEntity.AuditDate = DateTime.Now; return(this.UpdateEntity(workFlowCurrentEntity)); }
/// <summary> /// 添加 /// </summary> /// <param name="BaseWorkFlowStepEntity">实体</param> /// <returns>主键</returns> public string Add(BaseWorkFlowStepEntity BaseWorkFlowStepEntity) { return(this.AddEntity(BaseWorkFlowStepEntity)); }
private string StepAuditStatr(string categoryCode, string categoryFullName, string objectId, string objectFullName, string auditIdea, BaseWorkFlowStepEntity workFlowStepEntity) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = new BaseWorkFlowCurrentEntity(); // 1.这个是工作流的第一个发出日期,需要全局保留,其实也是创建日期了,但是有重新审核的这个说法,若有2次重新审核的事项,的确需要保留这个字段 // workFlowCurrentEntity.CallBack = workFlowManager.GetType().ToString(); workFlowCurrentEntity.WorkFlowId = workFlowStepEntity.WorkFlowId; workFlowCurrentEntity.ActivityId = workFlowStepEntity.Id; // 这里是为了优化越级审核用的,按排序嘛进行先后顺序排序 BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo); workFlowCurrentEntity.CategoryCode = categoryCode; workFlowCurrentEntity.CategoryFullName = categoryFullName; workFlowCurrentEntity.ObjectId = objectId; workFlowCurrentEntity.ObjectFullName = objectFullName; // 2.当前审核人的信息写入当前工作流 // workFlowCurrentEntity.AuditUserId = this.UserInfo.Id; // workFlowCurrentEntity.AuditUserCode = this.UserInfo.Code; // workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName; workFlowCurrentEntity.AuditIdea = auditIdea; workFlowCurrentEntity.AuditStatus = AuditStatus.StartAudit.ToString(); workFlowCurrentEntity.AuditStatusName = AuditStatus.StartAudit.ToDescription(); workFlowCurrentEntity.SendDate = DateTime.Now; // 3.接下来需要待审核的对象的信息 workFlowCurrentEntity.ToUserId = workFlowStepEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = workFlowStepEntity.AuditUserRealName; workFlowCurrentEntity.ToDepartmentId = workFlowStepEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowStepEntity.AuditDepartmentName; workFlowCurrentEntity.ToRoleId = workFlowStepEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = workFlowStepEntity.AuditRoleRealName; // 4.这些标志信息需要处理好,这里表示工作流还没完成生效,还在审批中的意思。 workFlowCurrentEntity.SortCode = workFlowStepEntity.SortCode; workFlowCurrentEntity.Enabled = 0; workFlowCurrentEntity.DeletionStateCode = 0; return(this.AddEntity(workFlowCurrentEntity)); }
/// <summary> /// 获取下一步是谁审核的功能 /// </summary> /// <param name="workFlowCurrentEntity">当前审核情况</param> /// <returns>下一步审核</returns> public BaseWorkFlowStepEntity GetNextWorkFlowStep(BaseWorkFlowCurrentEntity workFlowCurrentEntity) { BaseWorkFlowStepEntity workFlowStepEntity = null; DataTable dt = null; string nextActivityId = string.Empty; // 1. 从工作流审核步骤里选取审核步骤 BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo); // 若是会签 bool allPersons = false; if (!string.IsNullOrEmpty(workFlowCurrentEntity.ActivityType) && workFlowCurrentEntity.ActivityType.Equals("AllPersons")) { if (!string.IsNullOrEmpty(workFlowCurrentEntity.ToUserId) && workFlowCurrentEntity.ToUserId.IndexOf(",") >= 0) { // 这里是识别是会签 allPersons = true; List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldProcessId, workFlowCurrentEntity.ProcessId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldActivityId, workFlowCurrentEntity.ActivityId)); workFlowStepEntity = BaseEntity.Create <BaseWorkFlowStepEntity>(workFlowStepManager.GetDataTable(parameters)); // 这里是替换已经审核的人员 workFlowCurrentEntity.ToUserId = workFlowCurrentEntity.ToUserId.Replace(this.UserInfo.Id, "").Trim(','); workFlowStepEntity.AuditUserId = workFlowCurrentEntity.ToUserId; workFlowStepEntity.AuditUserRealName = new BaseUserManager().GetUsersName(workFlowCurrentEntity.ToUserId); } } // 若不是会签 if (!allPersons) { // 工作流主键 string workFlowId = workFlowCurrentEntity.ProcessId.ToString(); List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldCategoryCode, workFlowCurrentEntity.CategoryCode)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldObjectId, workFlowCurrentEntity.ObjectId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldProcessId, workFlowId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldDeletionStateCode, 0)); dt = workFlowStepManager.GetDataTable(parameters, BaseWorkFlowStepEntity.FieldSortCode); if (dt.Rows.Count > 0) { dt.Columns.Remove(BaseWorkFlowStepEntity.FieldId); dt.Columns[BaseWorkFlowStepEntity.FieldActivityId].ColumnName = BaseWorkFlowStepEntity.FieldId; } else { // 2. 从工作流审核模板里选取审核步骤 下一步是多少?按工作流进行查找审核步骤 BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldProcessId, workFlowId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldDeletionStateCode, 0)); dt = workFlowActivityManager.GetDataTable(parameters, BaseWorkFlowActivityEntity.FieldSortCode); } // 审核步骤主键 string activityId = string.Empty; if (workFlowCurrentEntity.ActivityId != null) { activityId = workFlowCurrentEntity.ActivityId.ToString(); } if (dt.Rows.Count == 0) { return(workFlowStepEntity); } if (!string.IsNullOrEmpty(activityId)) { nextActivityId = BaseSortLogic.GetNextId(dt, activityId.ToString()); } else { nextActivityId = dt.Rows[0][BaseWorkFlowActivityEntity.FieldId].ToString(); } } if (!string.IsNullOrEmpty(nextActivityId) && dt != null) { // workFlowActivityEntity = workFlowActivityManager.GetObject(nextActivityId); DataRow dr = BaseBusinessLogic.GetDataRow(dt, nextActivityId); workFlowStepEntity = BaseEntity.Create <BaseWorkFlowStepEntity>(dr); workFlowStepEntity.ActivityId = int.Parse(nextActivityId); } return(workFlowStepEntity); }
//----------------------------------------------------- // 启动工作流 自由流 //----------------------------------------------------- /// <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); }