public async Task <IActionResult> Post(StartWorkFlowModel model) { if (ModelState.IsValid) { //实体元数据 var entityMetas = _entityFinder.FindById(model.EntityId); //查找记录 var entity = _dataFinder.RetrieveById(entityMetas.Name, model.RecordId); if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Processing) { return(JError(T["workflow_processing_notallowtwice"])); } if (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Passed) { return(JError(T["workflow_stop_notallowtwice"])); } if (entity.GetIntValue("ProcessState", -1) != -1 && (entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Waiting || entity.GetIntValue("ProcessState") == (int)WorkFlowProcessState.Disabled)) { return(JError(T["workflow_state_notallowtwice"])); } //找到审批流程 var workFlow = _workFlowFinder.FindById(model.WorkflowId); if (workFlow == null) { return(JError(T["workflow_notfound"])); } var result = await _workFlowStarter.StartAsync(new WorkFlowStartUpContext() { User = CurrentUser , ApplicantId = CurrentUser.SystemUserId , Description = model.Description , ObjectId = model.RecordId , EntityMetaData = entityMetas , WorkFlowMetaData = workFlow , ObjectData = entity , Attachments = model.Attachments != null ? model.Attachments.Count : 0 , AttachmentFiles = model.Attachments }).ConfigureAwait(false); if (!result.IsSuccess) { return(JError(result.Message)); } return(JOk(T["workflow_start_success"])); } return(JModelError(T["workflow_start_failure"])); }
public IActionResult EditWorkFlow(Guid id) { if (id.Equals(Guid.Empty)) { return(NotFound()); } EditWorkFlowModel model = new EditWorkFlowModel(); var entity = _workFlowFinder.FindById(id); if (entity == null) { return(NotFound()); } entity.CopyTo(model); model.Steps = _workFlowStepService.Query(n => n.Where(f => f.WorkFlowId == id).Sort(s => s.SortAscending(f => f.StepOrder))); model.StepData = model.Steps.SerializeToJson(); model.EntityMetas = _entityFinder.FindById(entity.EntityId); return(View(model)); }
public bool Import(Guid solutionId, IList <WorkFlow> workFlows) { if (workFlows.NotEmpty()) { foreach (var item in workFlows) { var entity = _workFlowFinder.FindById(item.WorkFlowId); if (entity != null) { entity.Description = item.Description; entity.Name = item.Name; entity.StateCode = item.StateCode; _workFlowUpdater.Update(entity); //steps if (item.Category == 1) { _workFlowStepService.DeleteByParentId(item.WorkFlowId); foreach (var st in item.Steps) { st.WorkFlowId = item.WorkFlowId; } _workFlowStepService.CreateMany(item.Steps); } else if (item.Category == 2) { _processStageService.DeleteByParentId(item.WorkFlowId); foreach (var st in item.Stages) { st.WorkFlowId = item.WorkFlowId; } _processStageService.CreateMany(item.Stages); } } else { item.SolutionId = solutionId; item.ComponentState = 0; item.CreatedBy = _appContext.GetFeature <ICurrentUser>().SystemUserId; item.OrganizationId = _appContext.OrganizationId; _workFlowCreater.Create(item); if (item.Category == 1 && item.Steps.NotEmpty()) { _workFlowStepService.CreateMany(item.Steps); } else if (item.Category == 2 && item.Stages.NotEmpty()) { _processStageService.CreateMany(item.Stages); } } } } return(true); }
public IActionResult WorkFlowInstanceDetail(Guid entityid, Guid recordid) { var instances = _workFlowInstanceService.Query(n => n .Where(f => f.EntityId == entityid && f.ObjectId == recordid) .Sort(s => s.SortDescending(f => f.CreatedOn)) ); if (instances.IsEmpty()) { return(NotFound()); } var entityMeta = _entityFinder.FindById(entityid); if (entityMeta == null) { return(NotFound()); } foreach (var instance in instances) { var steps = _workFlowProcessFinder.Query(n => n .Where(f => f.WorkFlowInstanceId == instance.WorkFlowInstanceId && f.StateCode != WorkFlowProcessState.Disabled) .Sort(s => s.SortAscending(f => f.StepOrder)).Sort(s => s.SortAscending(f => f.StateCode))); instance.Steps = steps; } WorkFlowInstanceDetailModel model = new WorkFlowInstanceDetailModel(); model.Items = instances; var workFlowId = instances.First().WorkFlowId; model.FlowInfo = _workFlowFinder.FindById(workFlowId); var allSteps = _workFlowStepService.Query(n => n.Where(f => f.WorkFlowId == workFlowId).Sort(s => s.SortAscending(f => f.StepOrder))); model.Steps = allSteps; return(View(model)); }
public IActionResult UpdateProcessStage(UpdateProcessStageModel model) { if (model.EntityId.Equals(Guid.Empty) || model.RecordId.Equals(Guid.Empty) || model.WorkflowId.Equals(Guid.Empty) || model.StageId.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } var entityMeta = _entityFinder.FindById(model.EntityId); if (entityMeta == null) { return(NotFound()); } var flowInfo = _workFlowFinder.FindById(model.WorkflowId); if (flowInfo == null) { return(NotFound()); } var data = _dataFinder.RetrieveById(entityMeta.Name, model.RecordId); if (data.IsEmpty()) { return(NotFound()); } var stages = _processStageService.Query(n => n .Where(f => f.WorkFlowId == flowInfo.WorkFlowId) .Sort(s => s.SortAscending(f => f.StageOrder))); var currentStage = stages.Find(n => n.ProcessStageId == model.StageId); var entityIds = stages.Select(n => n.EntityId).Distinct().ToList(); int entityIndex = entityIds.FindIndex(n => n.Equals(currentStage.EntityId)) + 1; BusinessProcessFlowInstance bpfInstance = null; if (model.InstanceId.HasValue && !model.InstanceId.Value.Equals(Guid.Empty)) { bpfInstance = _businessProcessFlowInstanceService.Find(n => n.BusinessProcessFlowInstanceId == model.InstanceId && n.WorkFlowId == model.WorkflowId); if (bpfInstance == null) { return(NotFound()); } } if (bpfInstance == null) { bpfInstance = new BusinessProcessFlowInstance(); bpfInstance.BusinessProcessFlowInstanceId = Guid.NewGuid(); bpfInstance.WorkFlowId = model.WorkflowId; bpfInstance.ProcessStageId = currentStage.ProcessStageId; bpfInstance.Entity1Id = model.FromRecordId; bpfInstance.Entity2Id = model.RecordId; bpfInstance.ProcessEntityId = model.EntityId; _businessProcessFlowInstanceService.Create(bpfInstance); } else { var originalStage = stages.Find(n => n.ProcessStageId == bpfInstance.ProcessStageId); var isForward = currentStage.StageOrder > originalStage.StageOrder; if (isForward) { _businessProcessFlowInstanceUpdater.UpdateForward(model.WorkflowId, bpfInstance.BusinessProcessFlowInstanceId, model.StageId, model.RecordId); } //如果后退并且阶段不在同一实体,更新实例对应的记录id else if (!isForward) { if (!model.InstanceId.HasValue || model.InstanceId.Equals(Guid.Empty)) { return(JError(T["parameter_error"])); } _businessProcessFlowInstanceUpdater.UpdateBack(model.WorkflowId, model.InstanceId.Value, model.StageId, model.RecordId); } } //更新当前记录的业务阶段 var updData = new Entity(data.Name); updData.SetIdValue(data.GetIdValue()); updData.SetAttributeValue("stageid", model.StageId); _dataUpdater.Update(updData); return(SaveSuccess()); }
public IActionResult Get(Guid id) { return(JOk(_workFlowFinder.FindById(id))); }