/// <summary> /// 设置实体 /// </summary> /// <param name="entity">实体</param> private void SetObject(SQLBuilder sqlBuilder, BaseWorkFlowActivityEntity entity) { sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldProcessId, entity.ProcessId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldCode, entity.Code); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldFullName, entity.FullName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldCommitmentDays, entity.CommitmentDays); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditDepartmentId, entity.AuditDepartmentId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditDepartmentName, entity.AuditDepartmentName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditUserId, entity.AuditUserId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditUserCode, entity.AuditUserCode); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditUserRealName, entity.AuditUserRealName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditRoleId, entity.AuditRoleId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditRoleRealName, entity.AuditRoleRealName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldActivityType, entity.ActivityType); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldDefaultAuditUserId, entity.DefaultAuditUserId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldDefaultAuditUserRealName, entity.DefaultAuditUserRealName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldEditFields, entity.EditFields); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowSkip, entity.AllowSkip); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowPrint, entity.AllowPrint); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowEditDocuments, entity.AllowEditDocuments); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowAuditQuash, entity.AllowAuditQuash); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowAuditPass, entity.AllowAuditPass); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldEnterConstraint, entity.EnterConstraint); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldEndConstraint, entity.EndConstraint); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldSortCode, entity.SortCode); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldEnabled, entity.Enabled); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldDeletionStateCode, entity.DeletionStateCode); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldDescription, entity.Description); }
/// <summary> /// 自由审批 /// </summary> /// <param name="workFlowManager"></param> /// <param name="currentId"></param> /// <param name="toUserId"></param> /// <param name="toDepartmentId"></param> /// <param name="toRoleId"></param> /// <param name="auditIdea"></param> /// <returns></returns> public int FreeAuditPass(IWorkFlowManager workFlowManager, string currentId, string toUserId, string toDepartmentId = null, string toRoleId = null, string auditIdea = null) { // 返回值 int returnValue = 0; // 这里用锁的机制,提高并发控制能力 lock (WorkFlowCurrentLock) { BaseWorkFlowActivityEntity workFlowActivityEntity = new BaseWorkFlowActivityEntity(); // FreeWorkFlow 自由工作流 workFlowActivityEntity.WorkFlowId = 0; // 获取排序码 workFlowActivityEntity.SortCode = int.Parse(new BaseSequenceManager().GetSequence("FreeWorkFlow", 10000000)); // 是否提交给用户审批 if (!string.IsNullOrEmpty(toUserId)) { workFlowActivityEntity.AuditUserId = toUserId; workFlowActivityEntity.AuditUserRealName = new BaseUserManager().GetEntity(toUserId).RealName; } // 是否提交给部门审批 if (!string.IsNullOrEmpty(toDepartmentId)) { workFlowActivityEntity.AuditDepartmentId = toDepartmentId; workFlowActivityEntity.AuditDepartmentName = new BaseOrganizeManager().GetEntity(toDepartmentId).FullName; } // 是否提交给角色审批 if (!string.IsNullOrEmpty(toRoleId)) { workFlowActivityEntity.AuditRoleId = toRoleId; workFlowActivityEntity.AuditRoleRealName = new BaseRoleManager().GetEntity(toRoleId).RealName; } // 进行更新操作 returnValue = this.StepAuditPass(currentId, auditIdea, workFlowActivityEntity); if (returnValue == 0) { // 数据可能被删除 this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString(); } BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId); // 发送提醒信息 if (workFlowManager != null) { if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId)) { workFlowActivityEntity.AuditDepartmentId = null; workFlowActivityEntity.AuditRoleId = null; } workFlowManager.OnAutoAuditPass(workFlowCurrentEntity); workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowActivityEntity.AuditUserId }, workFlowActivityEntity.AuditDepartmentId, workFlowActivityEntity.AuditRoleId); } this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode); return(returnValue); } }
/// <summary> /// 添加工作流 /// </summary> /// <param name="userInfo">当前用户</param> /// <param name="entity">工作流定义实体</param> /// <returns>主键</returns> public string Add(BaseUserInfo userInfo, BaseWorkFlowActivityEntity entity) { string result = string.Empty; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessWorkFlowDb(userInfo, parameter, (dbHelper) => { var workFlowActivityManager = new BaseWorkFlowActivityManager(dbHelper, userInfo); result = workFlowActivityManager.Add(entity); }); return(result); }
/// <summary> /// 通过编号获取选项的显示内容 /// 这里是进行了内存缓存处理,减少数据库的I/O处理,提高程序的运行性能, /// 若有数据修改过,重新启动一下程序就可以了,这些基础数据也不是天天修改来修改去的, /// 所以没必要过度担忧,当然有需要时也可以写个刷新缓存的程序 /// </summary> /// <param name="id">主键</param> /// <returns>显示值</returns> public static string GetFullName(string id) { string result = id; if (!string.IsNullOrEmpty(id)) { BaseWorkFlowActivityEntity workFlowActivityEntity = GetEntities().FirstOrDefault(entity => entity.Id.HasValue && entity.Id.ToString().Equals(id)); if (workFlowActivityEntity != null) { result = workFlowActivityEntity.FullName; } } return(result); }
/// <summary> /// 通过编号获取选项的显示内容 /// 这里是进行了内存缓存处理,减少数据库的I/O处理,提高程序的运行性能, /// 若有数据修改过,重新启动一下程序就可以了,这些基础数据也不是天天修改来修改去的, /// 所以没必要过度担忧,当然有需要时也可以写个刷新缓存的程序 /// </summary> /// <param name="code">编号</param> /// <returns>显示值</returns> public new static string GetFullNameByCode(string code) { string result = code; if (!string.IsNullOrEmpty(code)) { BaseWorkFlowActivityEntity workFlowActivityEntity = GetEntities().FirstOrDefault(entity => !string.IsNullOrEmpty(entity.Code) && entity.Code.Equals(code)); if (workFlowActivityEntity != null) { result = workFlowActivityEntity.FullName; } } 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.GetEntity(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); BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo); BaseWorkFlowActivityEntity workFlowActivityEntity = workFlowActivityManager.GetEntity(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.GetEntity(toUserId); workFlowCurrentEntity.ToUserId = userEntity.Id; workFlowCurrentEntity.ToUserRealName = userEntity.RealName; workFlowCurrentEntity.ToDepartmentId = userEntity.DepartmentId; workFlowCurrentEntity.ToDepartmentName = userEntity.DepartmentName; } //workFlowCurrentEntity.SortCode = null; } workFlowCurrentEntity.SendDate = DateTime.Now; workFlowCurrentEntity.Enabled = 0; // 4.生成审核结束的记录 this.UpdateEntity(workFlowCurrentEntity); return(workFlowCurrentEntity); }
/// <summary> /// 更新实体 /// </summary> /// <param name="baseWorkFlowActivityEntity">实体</param> public int UpdateEntity(BaseWorkFlowActivityEntity baseWorkFlowActivityEntity) { SQLBuilder sqlBuilder = new SQLBuilder(DbHelper); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetEntity(sqlBuilder, baseWorkFlowActivityEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowActivityEntity.FieldModifiedOn); sqlBuilder.SetWhere(BaseWorkFlowActivityEntity.FieldId, baseWorkFlowActivityEntity.Id); return(sqlBuilder.EndUpdate()); }
/// <summary> /// 添加工作流 /// </summary> /// <param name="userInfo">当前用户</param> /// <param name="workFlowActivityEntity">工作流定义实体</param> /// <param name="statusCode">状态码</param> /// <param name="statusMessage">状态信息</param> /// <returns>主键</returns> public string Add(BaseUserInfo userInfo, BaseWorkFlowActivityEntity workFlowActivityEntity) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif string returnValue = string.Empty; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.WorkFlowDbType)) { try { dbHelper.Open(WorkFlowDbConnection); // 数据库事务开始 // dbHelper.BeginTransaction(); BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(dbHelper, userInfo); returnValue = workFlowActivityManager.Add(workFlowActivityEntity); // 写入日志信息 BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); // 数据库事务提交 // dbHelper.CommitTransaction(); } catch (Exception ex) { // 数据库事务回滚 // dbHelper.RollbackTransaction(); // 记录异常信息 BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 批量保存 /// </summary> /// <param name="result">数据表</param> /// <returns>影响行数</returns> public override int BatchSave(DataTable dt) { int result = 0; BaseWorkFlowActivityEntity workFlowActivityEntity = new BaseWorkFlowActivityEntity(); foreach (DataRow dr in dt.Rows) { // 删除状态 if (dr.RowState == DataRowState.Deleted) { string id = dr[BaseRoleEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { result += this.Delete(id); } } // 被修改过 if (dr.RowState == DataRowState.Modified) { string id = dr[BaseRoleEntity.FieldId, DataRowVersion.Original].ToString(); if (!String.IsNullOrEmpty(id)) { workFlowActivityEntity.GetFrom(dr); result += this.UpdateObject(workFlowActivityEntity); } } // 添加状态 if (dr.RowState == DataRowState.Added) { workFlowActivityEntity.GetFrom(dr); result += this.AddObject(workFlowActivityEntity).Length > 0 ? 1 : 0; } if (dr.RowState == DataRowState.Unchanged) { continue; } if (dr.RowState == DataRowState.Detached) { continue; } } return(result); }
/// <summary> /// 设置实体 /// </summary> /// <param name="baseWorkFlowActivityEntity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, BaseWorkFlowActivityEntity baseWorkFlowActivityEntity) { sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldWorkFlowId, baseWorkFlowActivityEntity.WorkFlowId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldCode, baseWorkFlowActivityEntity.Code); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldFullName, baseWorkFlowActivityEntity.FullName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditDepartmentId, baseWorkFlowActivityEntity.AuditDepartmentId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditDepartmentName, baseWorkFlowActivityEntity.AuditDepartmentName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditUserId, baseWorkFlowActivityEntity.AuditUserId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditUserCode, baseWorkFlowActivityEntity.AuditUserCode); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditUserRealName, baseWorkFlowActivityEntity.AuditUserRealName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditRoleId, baseWorkFlowActivityEntity.AuditRoleId); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAuditRoleRealName, baseWorkFlowActivityEntity.AuditRoleRealName); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldActivityType, baseWorkFlowActivityEntity.ActivityType); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowPrint, baseWorkFlowActivityEntity.AllowPrint); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldAllowEditDocuments, baseWorkFlowActivityEntity.AllowEditDocuments); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldSortCode, baseWorkFlowActivityEntity.SortCode); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldEnabled, baseWorkFlowActivityEntity.Enabled); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldDeletionStateCode, baseWorkFlowActivityEntity.DeletionStateCode); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldDescription, baseWorkFlowActivityEntity.Description); }
/// <summary> /// 审核通过(不需要再发给别人了) /// </summary> /// <param name="currentId">当前主键</param> /// <param name="auditIdea">批示</param> /// <returns>影响行数</returns> private int StepAuditPass(string currentId, string auditIdea, BaseWorkFlowActivityEntity workFlowActivityEntity) { BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId); // 1.记录当前的审核时间、审核人信息 workFlowCurrentEntity.AuditDate = DateTime.Now; workFlowCurrentEntity.AuditIdea = auditIdea; workFlowCurrentEntity.AuditUserId = this.UserInfo.Id; workFlowCurrentEntity.AuditUserRealName = this.UserInfo.RealName; workFlowCurrentEntity.AuditStatus = AuditStatus.AuditPass.ToString(); workFlowCurrentEntity.AuditStatusName = AuditStatus.AuditPass.ToDescription(); // 2.记录审核日志 this.AddHistory(workFlowCurrentEntity); // 3.上一个审核结束了,新的审核又开始了,更新待审核情况 workFlowCurrentEntity.ActivityId = workFlowActivityEntity.Id; workFlowCurrentEntity.ToRoleId = workFlowActivityEntity.AuditRoleId; workFlowCurrentEntity.ToRoleRealName = workFlowActivityEntity.AuditRoleRealName; workFlowCurrentEntity.ToDepartmentId = workFlowActivityEntity.AuditDepartmentId; workFlowCurrentEntity.ToDepartmentName = workFlowActivityEntity.AuditDepartmentName; workFlowCurrentEntity.ToUserId = workFlowActivityEntity.AuditUserId; workFlowCurrentEntity.ToUserRealName = workFlowActivityEntity.AuditUserRealName; workFlowCurrentEntity.SortCode = workFlowActivityEntity.SortCode; return(this.UpdateEntity(workFlowCurrentEntity)); }
/// <summary> /// (点通过时)当审核通过时 /// </summary> /// <param name="currentId">审批流当前主键</param> /// <param name="auditIdea">批示</param> /// <returns>成功失败</returns> public int AutoAuditPass(IWorkFlowManager workFlowManager, string currentId, string auditIdea) { int returnValue = 0; // 这里要加锁,防止并发提交 // 这里用锁的机制,提高并发控制能力 lock (WorkFlowCurrentLock) { // using (TransactionScope transactionScope = new TransactionScope()) //{ //try //{ // 1. 先获得现在的状态?当前的工作流主键、当前的审核步骤主键? BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(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(returnValue); } // 是不是给当前人审核的,或者当前人在委托的人? if (!string.IsNullOrEmpty(workFlowCurrentEntity.ToUserId)) { if (!(workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.Id) || workFlowCurrentEntity.ToUserId.ToString().Equals(this.UserInfo.TargetUserId))) { return(returnValue); } } BaseWorkFlowActivityEntity workFlowActivityEntity = this.GetNextWorkFlowActivity(workFlowCurrentEntity); // 3. 进行下一步流转?转给角色?还是传给用户? if (workFlowActivityEntity == null || workFlowActivityEntity.Id == null) { // 4. 若没下一步了,那就得结束流程了?审核结束了 returnValue = this.AuditComplete(workFlowManager, currentId, auditIdea); } else { // 审核进入下一步 // 当前是哪个步骤? // 4. 是否已经在工作流里了? // 5. 若已经在工作流里了,那就进行更新操作? if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId)) { // 若是任意人可以审核的,需要进行一次人工选任的工作 if (workFlowActivityEntity.AuditUserId.Equals("Anyone")) { return(returnValue); } } // 按用户审核,审核通过 returnValue = AuditPass(workFlowManager, currentId, auditIdea, workFlowActivityEntity); } //} //catch (System.Exception ex) //{ // 在本地记录异常 // FileUtil.WriteException(UserInfo, ex); //} //finally //{ //} // transactionScope.Complete(); //} } return(returnValue); }
/// <summary> /// 审核通过 /// </summary> /// <param name="id">当前主键</param> /// <param name="auditIdea">批示</param> /// <returns>影响行数</returns> public int AuditPass(IWorkFlowManager workFlowManager, string currentId, string auditIdea, BaseWorkFlowActivityEntity workFlowActivityEntity) { int returnValue = 0; // 进行更新操作 returnValue = this.StepAuditPass(currentId, auditIdea, workFlowActivityEntity); if (returnValue == 0) { // 数据可能被删除 this.ReturnStatusCode = StatusCode.ErrorDeleted.ToString(); } BaseWorkFlowCurrentEntity workFlowCurrentEntity = this.GetEntity(currentId); // 发送提醒信息 if (workFlowManager != null) { if (!string.IsNullOrEmpty(workFlowActivityEntity.AuditUserId)) { workFlowActivityEntity.AuditDepartmentId = null; workFlowActivityEntity.AuditRoleId = null; } workFlowManager.OnAutoAuditPass(workFlowCurrentEntity); workFlowManager.SendRemindMessage(workFlowCurrentEntity, AuditStatus.AuditPass, new string[] { workFlowCurrentEntity.CreateUserId, workFlowActivityEntity.AuditUserId }, workFlowActivityEntity.AuditDepartmentId, workFlowActivityEntity.AuditRoleId); } this.ReturnStatusMessage = this.GetStateMessage(this.ReturnStatusCode); return(returnValue); }
/// <summary> /// 添加 /// </summary> /// <param name="baseWorkFlowActivityEntity">实体</param> /// <param name="identity">自增量方式</param> /// <param name="returnId">返回主鍵</param> /// <returns>主键</returns> public string Add(BaseWorkFlowActivityEntity baseWorkFlowActivityEntity, bool identity, bool returnId) { this.Identity = identity; this.ReturnId = returnId; return(this.AddEntity(baseWorkFlowActivityEntity)); }
public BaseWorkFlowActivityEntity GetNextWorkFlowActivity(BaseWorkFlowCurrentEntity workFlowCurrentEntity) { BaseWorkFlowActivityEntity workFlowActivityEntity = null; DataTable dataTable = null; // 工作流主键 string workFlowId = workFlowCurrentEntity.WorkFlowId.ToString(); // 1. 从工作流审核步骤里选取审核步骤 BaseWorkFlowStepManager workFlowStepManager = new BaseWorkFlowStepManager(this.DbHelper, this.UserInfo); 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.FieldWorkFlowId, workFlowId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowStepEntity.FieldDeletionStateCode, 0)); dataTable = workFlowStepManager.GetDataTable(parameters, BaseWorkFlowStepEntity.FieldSortCode); if (dataTable.Rows.Count > 0) { dataTable.Columns.Remove(BaseWorkFlowStepEntity.FieldId); dataTable.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.FieldWorkFlowId, workFlowId)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldDeletionStateCode, 0)); dataTable = workFlowActivityManager.GetDataTable(parameters, BaseWorkFlowActivityEntity.FieldSortCode); } // 审核步骤主键 string activityId = string.Empty; if (workFlowCurrentEntity.ActivityId != null) { activityId = workFlowCurrentEntity.ActivityId.ToString(); } if (dataTable.Rows.Count == 0) { return(workFlowActivityEntity); } string nextActivityId = string.Empty; if (!string.IsNullOrEmpty(activityId)) { nextActivityId = BaseSortLogic.GetNextId(dataTable, activityId.ToString()); } else { nextActivityId = dataTable.Rows[0][BaseWorkFlowActivityEntity.FieldId].ToString(); } if (!string.IsNullOrEmpty(nextActivityId)) { // workFlowActivityEntity = workFlowActivityManager.GetEntity(nextActivityId); DataRow dataRow = BaseBusinessLogic.GetDataRow(dataTable, nextActivityId); workFlowActivityEntity = new BaseWorkFlowActivityEntity(dataRow); } return(workFlowActivityEntity); }
/// <summary> /// 更新 /// </summary> /// <param name="baseWorkFlowActivityEntity">实体</param> public int Update(BaseWorkFlowActivityEntity baseWorkFlowActivityEntity) { return(this.UpdateEntity(baseWorkFlowActivityEntity)); }
//----------------------------------------------------- // 启动工作流 步骤流 //----------------------------------------------------- /// <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); }
/// <summary> /// 添加 /// </summary> /// <param name="baseWorkFlowActivityEntity">实体</param> /// <returns>主键</returns> public string Add(BaseWorkFlowActivityEntity baseWorkFlowActivityEntity) { return(this.AddEntity(baseWorkFlowActivityEntity)); }
/// <summary> /// 添加实体 /// </summary> /// <param name="workFlowActivityEntity">实体</param> public string AddEntity(BaseWorkFlowActivityEntity 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, BaseWorkFlowActivityEntity.FieldId); if (!this.Identity) { sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldId, workFlowActivityEntity.Id); } else { if (!this.ReturnId && (DbHelper.CurrentDbType == CurrentDbType.Oracle || DbHelper.CurrentDbType == CurrentDbType.DB2)) { if (DbHelper.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(BaseWorkFlowActivityEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DbHelper.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(BaseWorkFlowActivityEntity.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(BaseWorkFlowActivityEntity.FieldId, workFlowActivityEntity.Id); } } } this.SetEntity(sqlBuilder, workFlowActivityEntity); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldCreateUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldCreateBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowActivityEntity.FieldCreateOn); if (UserInfo != null) { sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldModifiedUserId, UserInfo.Id); sqlBuilder.SetValue(BaseWorkFlowActivityEntity.FieldModifiedBy, UserInfo.RealName); } sqlBuilder.SetDBNow(BaseWorkFlowActivityEntity.FieldModifiedOn); if (DbHelper.CurrentDbType == CurrentDbType.SqlServer && this.Identity) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 获取实体 /// </summary> /// <param name="id">主键</param> public BaseWorkFlowActivityEntity GetEntity(string id) { BaseWorkFlowActivityEntity baseWorkFlowActivityEntity = new BaseWorkFlowActivityEntity(this.GetDataTable(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldId, id))); return(baseWorkFlowActivityEntity); }
/// <summary> /// 获取第一步审核的 /// </summary> /// <param name="categoryCode">单据分类</param> /// <param name="workFlowCode">审批流程编号</param> /// <returns>审核步骤</returns> public BaseWorkFlowActivityEntity GetFirstActivityEntity(string workFlowCode, string categoryCode = null) { BaseWorkFlowActivityEntity workFlowActivityEntity = null; string workFlowId = string.Empty; DataTable dt = null; List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >(); // 这里是获取用户的工作流, 按用户主键,按模板编号 if (string.IsNullOrEmpty(workFlowCode)) { parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowBillTemplateEntity.FieldCategoryCode, categoryCode)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowBillTemplateEntity.FieldDeletionStateCode, 0)); BaseWorkFlowBillTemplateManager templateManager = new BaseWorkFlowBillTemplateManager(this.DbHelper, this.UserInfo); dt = templateManager.GetDataTable(parameters); BaseWorkFlowBillTemplateEntity templateEntity = BaseEntity.Create <BaseWorkFlowBillTemplateEntity>(dt); if (!string.IsNullOrEmpty(templateEntity.Id)) { workFlowCode = this.UserInfo.Id + "_" + templateEntity.Id; } } if (string.IsNullOrEmpty(workFlowCode)) { return(null); } // 1. 先检查工作流是否存在? BaseWorkFlowProcessManager workFlowProcessManager = new BaseWorkFlowProcessManager(this.DbHelper, this.UserInfo); parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldCode, workFlowCode)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowProcessEntity.FieldDeletionStateCode, 0)); string[] names = new string[] { BaseWorkFlowProcessEntity.FieldCode, BaseWorkFlowProcessEntity.FieldEnabled, BaseWorkFlowProcessEntity.FieldDeletionStateCode }; // 2010.01.25 LiangMingMing 将 BaseWorkFlowProcessEntity.FieldCode 改 BaseWorkFlowProcessEntity.FieldId object[] values = new object[] { workFlowCode, 1, 0 }; workFlowId = workFlowProcessManager.GetId(parameters); if (string.IsNullOrEmpty(workFlowId)) { return(null); } // 2. 查找第一步是按帐户审核?还是按角色审核? BaseWorkFlowActivityManager workFlowActivityManager = new BaseWorkFlowActivityManager(this.DbHelper, this.UserInfo); // 2010.01.25 LiangMingMing 新加了两个参数new string[] { BaseWorkFlowActivityEntity.FieldProcessId }, new string[] { Convert.ToString(workFlowId) },(具体获取哪个流程的步骤) parameters = new List <KeyValuePair <string, object> >(); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldProcessId, workFlowId.ToString())); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldEnabled, 1)); parameters.Add(new KeyValuePair <string, object>(BaseWorkFlowActivityEntity.FieldDeletionStateCode, 0)); dt = workFlowActivityManager.GetDataTable(parameters); // 3. 取第一个排序的数据 if (dt.Rows.Count == 0) { return(null); } workFlowActivityEntity = BaseEntity.Create <BaseWorkFlowActivityEntity>(dt.Rows[0]); if ((workFlowActivityEntity.AuditUserId == null) && (workFlowActivityEntity.AuditRoleId == null)) { return(null); } return(workFlowActivityEntity); }
/// <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); }