/// <summary> /// 更新实体 /// </summary> /// <param name="operatorInstanceEntity">实体</param> public int UpdateEntity(OperatorInstanceEntity operatorInstanceEntity) { var sqlBuilder = new SQLBuilder(DBProvider); sqlBuilder.BeginUpdate(this.CurrentTableName); this.SetEntity(sqlBuilder, operatorInstanceEntity); sqlBuilder.SetWhere(OperatorInstanceTable.FieldOperatorInsId, operatorInstanceEntity.OperatorInsId); return(sqlBuilder.EndUpdate()); }
/// <summary> /// 创建处理者实例 /// </summary> /// <param name="userInfo">用户</param> /// <param name="entity">创建处理者实例实体</param> /// <returns>主键</returns> public string CreateOperatorInstance(UserInfo userInfo, OperatorInstanceEntity entity) { string returnValue = string.Empty; var parameter = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.WorkFlowInstanceService_CreateOperatorInstance); ServiceUtil.ProcessWorkFlowDbWithTransaction(userInfo, parameter, dbProvider => { var manager = new OperatorInstanceManager(dbProvider, userInfo); // 调用方法,并且返回运行结果 returnValue = manager.Create(entity); }); return(returnValue); }
/// <summary> /// 创建处理者实例 /// </summary> /// <param name="entity">实体</param> /// <returns></returns> public string Create(OperatorInstanceEntity entity) { string returnStr = string.Empty; try { if (OperatorExists(entity.WorkFlowInsId, entity.WorkTaskId, entity.OperContent, 0)) { return(string.Empty);//不重复添加 } if (OperatorIsExclude(entity.WorkFlowId, entity.WorkTaskId, entity.OperContent, 0)) { return(string.Empty);//排除的在外的处理人不添加 } returnStr = this.AddEntity(entity); } catch (Exception ex) { throw ex; } return(returnStr); }
/// <summary> /// 设置实体 /// </summary> /// <param name="operatorInstanceEntity">实体</param> private void SetEntity(SQLBuilder sqlBuilder, OperatorInstanceEntity operatorInstanceEntity) { sqlBuilder.SetValue(OperatorInstanceTable.FieldWorkFlowId, operatorInstanceEntity.WorkFlowId); sqlBuilder.SetValue(OperatorInstanceTable.FieldWorkTaskId, operatorInstanceEntity.WorkTaskId); sqlBuilder.SetValue(OperatorInstanceTable.FieldWorkFlowInsId, operatorInstanceEntity.WorkFlowInsId); sqlBuilder.SetValue(OperatorInstanceTable.FieldWorkTaskInsId, operatorInstanceEntity.WorkTaskInsId); sqlBuilder.SetValue(OperatorInstanceTable.FieldUserId, operatorInstanceEntity.UserId); sqlBuilder.SetValue(OperatorInstanceTable.FieldOperType, operatorInstanceEntity.OperType); sqlBuilder.SetValue(OperatorInstanceTable.FieldOperRealtion, operatorInstanceEntity.OperRealtion); sqlBuilder.SetValue(OperatorInstanceTable.FieldOperContent, operatorInstanceEntity.OperContent); sqlBuilder.SetValue(OperatorInstanceTable.FieldOperContentText, operatorInstanceEntity.OperContentText); sqlBuilder.SetValue(OperatorInstanceTable.FieldOperStatus, operatorInstanceEntity.OperStatus); if (DBProvider.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetValue(OperatorInstanceTable.FieldOperDateTime, operatorInstanceEntity.OperDateTime != null ? BusinessLogic.GetOracleDateFormat(System.DateTime.Parse(operatorInstanceEntity.OperDateTime.ToString()), "yyyy-mm-dd hh24:mi:ss") : operatorInstanceEntity.OperDateTime); } else { sqlBuilder.SetValue(OperatorInstanceTable.FieldOperDateTime, operatorInstanceEntity.OperDateTime); } sqlBuilder.SetValue(OperatorInstanceTable.FieldChangeOperator, operatorInstanceEntity.ChangeOperator); }
/// <summary> /// 流程启动,草稿和启动两种状态 /// </summary> public string Start() { try { if (string.IsNullOrEmpty(WorkFlowInstanceId)) { WorkFlowInstanceId = BusinessLogic.NewGuid(); } if (string.IsNullOrEmpty(WorkTaskInstanceId)) { WorkTaskInstanceId = BusinessLogic.NewGuid(); } if (string.IsNullOrEmpty(OperatorInstanceId)) { OperatorInstanceId = BusinessLogic.NewGuid(); } if (string.IsNullOrEmpty(UserId)) { return(WorkFlowConst.IsNullUserIdCode); } if (CurrentUser == null) { return(WorkFlowConst.IsNullUser); } if (string.IsNullOrEmpty(WorkFlowId)) { return(WorkFlowConst.IsNullWorkFlowIdCode); } if (string.IsNullOrEmpty(WorkTaskId)) { return(WorkFlowConst.IsNullWorkTaskIdCode); } if (string.IsNullOrEmpty(CommandName)) { return(WorkFlowConst.IsNullCommandNameCode); } if (string.IsNullOrEmpty(WorkFlowNo)) { return(WorkFlowConst.IsNullWorkFlowNoCode); } if (string.IsNullOrEmpty(WorkflowInsCaption)) { return(WorkFlowConst.IsNullWorkflowInsCaption); } if (RDIFrameworkService.Instance.WorkFlowHelperService.IsTaskInsCompleted(this.CurrentUser, WorkTaskInstanceId)) { return(WorkFlowConst.InstanceIsCompletedCode);//流程实例已完成,不能重复提交 } //检查是否已经保存过草稿。如果已经保存过则不需要再创建实例,只保存业务表单数据, //此处的处理与交互节点的处理不同,需要加判断。 if (RDIFrameworkService.Instance.WorkFlowInstanceService.WorkTaskInstanceExist(this.CurrentUser, WorkTaskInstanceId) == false)//实例不存在,说明未保存过 { //创建流程实例 var workflowInstance = new WorkFlowInstanceEntity() { WorkFlowId = WorkFlowId, WorkFlowInsId = WorkFlowInstanceId, WorkFlowNo = WorkFlowNo, FlowInsCaption = WorkflowInsCaption, Description = Description, Priority = Priority, Status = Status, NowTaskId = WorkTaskId,//当前流程所处流程模板的位置 IsSubWorkflow = IsSubWorkflow ? 1: 0, MainWorkflowInsId = MainWorkflowInsId, MainWorktaskId = MainWorktaskId, MainWorkflowId = MainWorkflowId, MainWorktaskInsId = MainWorktaskInsId }; RDIFrameworkService.Instance.WorkFlowInstanceService.CreateWorkFlowInstance(this.CurrentUser, workflowInstance); //创建启动节点的任务实例 var workTaskInstance = new WorkTaskInstanceEntity { WorkFlowId = WorkFlowId, WorkTaskId = WorkTaskId, WorkFlowInsId = WorkFlowInstanceId, WorkTaskInsId = WorkTaskInstanceId, TaskInsCaption = RDIFrameworkService.Instance.WorkFlowTemplateService.GetWorkTaskCaption(this.CurrentUser, WorkTaskId) }; if (IsSubWorkflow)//是子流程调用,需要放到未认领任务中 { workTaskInstance.PreviousTaskId = WorkTaskInstanceId; workTaskInstance.Status = "1"; } else//不是子流程调用,启动节点直接放入已认领任务中 { workTaskInstance.PreviousTaskId = WorkTaskInstanceId;//开始节点的前一节点等于自己 workTaskInstance.Status = "2"; } RDIFrameworkService.Instance.WorkFlowInstanceService.CreateWorkTaskInstance(this.CurrentUser, workTaskInstance); //创建启动节点的处理人实例 var operatorInstance = new OperatorInstanceEntity { OperatorInsId = OperatorInstanceId, WorkFlowId = WorkFlowId, WorkTaskId = WorkTaskId, WorkFlowInsId = WorkFlowInstanceId, WorkTaskInsId = WorkTaskInstanceId, UserId = UserId, OperRealtion = 0, OperContent = UserId }; var userEnity = RDIFrameworkService.Instance.UserService.GetEntity(this.CurrentUser, UserId); var userName = userEnity == null || string.IsNullOrEmpty(userEnity.UserName) ? "未找到处理人" : userEnity.UserName; operatorInstance.OperContentText = userName; operatorInstance.OperType = 3; if (IsSubWorkflow) //是子流程调用,需要放到未认领任务中 { operatorInstance.OperStatus = "0"; } else //不是子流程调用,启动节点直接放入已认领任务中 { operatorInstance.OperStatus = "3"; } RDIFrameworkService.Instance.WorkFlowInstanceService.CreateOperatorInstance(this.CurrentUser, operatorInstance); } if (!IsDraft)//不是草稿状态,提交任务 { var result = RDIFrameworkService.Instance.WorkFlowHelperService.CreateNextTaskInstance(this.CurrentUser, UserId, WorkFlowId, WorkTaskId, WorkFlowInstanceId, WorkTaskInstanceId, OperatorInstanceId, CommandName); if (result != WorkFlowConst.SuccessCode) { var e = new WorkFlowEventArgs(this) { ResultMsg = result }; OnRunFail(this, e); return(result); } else { var e = new WorkFlowEventArgs(this) { ResultMsg = WorkFlowConst.SuccessMsg }; OnRunSuccess(this, e); } } return(WorkFlowConst.SuccessCode); } catch (Exception ex) { var msg = string.Format(WorkFlowConst.EngineErrorMsg, ex.Message); var e = new WorkFlowEventArgs(this) { ResultMsg = msg }; OnRunFail(this, e); return(WorkFlowConst.OtherErrorCode); } }
/// <summary> /// 指定处理人 /// </summary> /// <param name="userId">用户Id</param> /// <param name="workFlowId">流程模板Id</param> /// <param name="workTaskId">任务模板Id</param> /// <param name="workFlowInstanceId">流程实例Id</param> /// <param name="workTaskInstanceId">任务实例Id</param> /// <param name="operParam">处理者参数</param> /// <returns>是否成功</returns> public bool AssignUser(string userId, string workFlowId, string workTaskId, string workFlowInstanceId, string workTaskInstanceId, OperParameter operParam) { if (string.IsNullOrEmpty(operParam.OperContent)) { return(false); } switch (operParam.OperRule) { case "1": { //创建处理人实例 var operInsEntity = new OperatorInstanceEntity() { OperatorInsId = BusinessLogic.NewGuid(), WorkFlowId = workFlowId, WorkTaskId = workTaskId, WorkFlowInsId = workFlowInstanceId, WorkTaskInsId = workTaskInstanceId, //此时是新任务Id UserId = "", OperRealtion = operParam.OperRelation, OperContent = operParam.OperContent, OperContentText = operParam.OperContenText, OperType = operParam.OperType//此处保留原来的处理类型 }; string successCode = new OperatorInstanceManager(this.DBProvider).Create(operInsEntity); //给处理者发送信息 if (!string.IsNullOrEmpty(successCode) && successCode.Length > 0) { var messageEntity = new CiMessageEntity { Id = BusinessLogic.NewGuid(), FunctionCode = MessageFunction.Remind.ToString(), ReceiverId = DefaultRole.Administrator.ToString(), Title = "业务流程消息", MSGContent = "你有一待办任务,请到未认领任务界面认领。", IsNew = 1, ReadCount = 0, Enabled = 1, DeleteMark = 0 }; var messageManager = new CiMessageManager(DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType, SystemInfo.RDIFrameworkDbConectionString), this.UserInfo); messageManager.BatchSend(operInsEntity.OperContent, null, null, messageEntity, false); } if ((userId == operParam.OperContent) && (operParam.IsJumpSelf)) //处理者是提交人,自动处理 { var wfrun = new WorkFlowRuntime(); wfrun.Run(userId, operInsEntity.OperatorInsId, "提交"); } } break; case "2": { //创建任务实例 var newTaskId = BusinessLogic.NewGuid();//新任务实例Id var workTaskInsEntity = new WorkTaskInstanceEntity() { WorkFlowId = workFlowId, WorkTaskId = workTaskId, WorkFlowInsId = workFlowInstanceId, WorkTaskInsId = newTaskId, PreviousTaskId = workTaskInstanceId, //此时是当前任务Id TaskInsCaption = new WorkTaskManager(this.DBProvider).GetTaskCaption(workTaskId), Status = "1", }; new WorkTaskInstanceManager(this.DBProvider).Create(workTaskInsEntity); //创建处理人实例 var operInsEntity = new OperatorInstanceEntity() { OperatorInsId = BusinessLogic.NewGuid(), WorkFlowId = workFlowId, WorkTaskId = workTaskId, WorkFlowInsId = workFlowInstanceId, WorkTaskInsId = newTaskId, UserId = "", OperRealtion = operParam.OperRelation, OperContent = operParam.OperContent, OperContentText = operParam.OperContenText, OperType = 3,//此处修改为指定处理人 }; string successCode = new OperatorInstanceManager(this.DBProvider).Create(operInsEntity); //给处理者发送信息 if (!string.IsNullOrEmpty(successCode) && successCode.Length > 0) { var messageEntity = new CiMessageEntity { Id = BusinessLogic.NewGuid(), FunctionCode = MessageFunction.Remind.ToString(), ReceiverId = DefaultRole.Administrator.ToString(), Title = "业务流程消息", MSGContent = "你有一待办任务,请到未认领任务界面认领。", IsNew = 1, ReadCount = 0, Enabled = 1, DeleteMark = 0 }; var messageManager = new CiMessageManager(DbFactoryProvider.GetProvider(SystemInfo.RDIFrameworkDbType, SystemInfo.RDIFrameworkDbConectionString), this.UserInfo); messageManager.BatchSend(operInsEntity.OperContent, null, null, messageEntity, false); } if ((userId == operParam.OperContent) && (operParam.IsJumpSelf)) //处理者是提交人,自动处理 { var wfrun = new WorkFlowRuntime(); wfrun.Run(userId, operInsEntity.OperatorInsId, "提交"); } } break; } return(true); }
/// <summary> /// 添加实体 /// </summary> /// <param name="operatorInstanceEntity">实体</param> public string AddEntity(OperatorInstanceEntity operatorInstanceEntity) { var sequence = string.Empty; this.Identity = false; if (operatorInstanceEntity.OperatorInsId != null) { sequence = operatorInstanceEntity.OperatorInsId.ToString(); } var sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId); sqlBuilder.BeginInsert(this.CurrentTableName, OperatorInstanceTable.FieldOperatorInsId); if (!this.Identity) { if (string.IsNullOrEmpty(operatorInstanceEntity.OperatorInsId)) { sequence = BusinessLogic.NewGuid(); operatorInstanceEntity.OperatorInsId = sequence; } sqlBuilder.SetValue(OperatorInstanceTable.FieldOperatorInsId, operatorInstanceEntity.OperatorInsId); } else { if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (DBProvider.CurrentDbType == CurrentDbType.Oracle) { sqlBuilder.SetFormula(OperatorInstanceTable.FieldOperatorInsId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL "); } if (DBProvider.CurrentDbType == CurrentDbType.DB2) { sqlBuilder.SetFormula(OperatorInstanceTable.FieldOperatorInsId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper()); } } else { if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2)) { if (string.IsNullOrEmpty(operatorInstanceEntity.OperatorInsId)) { if (string.IsNullOrEmpty(sequence)) { var sequenceManager = new CiSequenceManager(DBProvider, this.Identity); sequence = sequenceManager.GetSequence(this.CurrentTableName); } operatorInstanceEntity.OperatorInsId = sequence; } sqlBuilder.SetValue(OperatorInstanceTable.FieldOperatorInsId, operatorInstanceEntity.OperatorInsId); } } } this.SetEntity(sqlBuilder, operatorInstanceEntity); if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.SqlServer || DBProvider.CurrentDbType == CurrentDbType.Access)) { sequence = sqlBuilder.EndInsert().ToString(); } else { sqlBuilder.EndInsert(); } return(sequence); }
/// <summary> /// 更新 /// </summary> /// <param name="operatorInstanceEntity">实体</param> public int Update(OperatorInstanceEntity operatorInstanceEntity) { return(this.UpdateEntity(operatorInstanceEntity)); }
/// <summary> /// 添加 /// </summary> /// <param name="operatorInstanceEntity">实体</param> /// <param name="identity">自增量方式</param> /// <param name="returnId">返回主键</param> /// <returns>主键</returns> public string Add(OperatorInstanceEntity operatorInstanceEntity, bool identity, bool returnId) { this.Identity = identity; this.ReturnId = returnId; return(this.AddEntity(operatorInstanceEntity)); }
/// <summary> /// 添加 /// </summary> /// <param name="operatorInstanceEntity">实体</param> /// <returns>主键</returns> public string Add(OperatorInstanceEntity operatorInstanceEntity) { return(this.AddEntity(operatorInstanceEntity)); }