예제 #1
0
        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"]));
        }
예제 #2
0
        public IActionResult StartWorkFlow(Guid entityId, Guid recordId)
        {
            StartWorkFlowModel model = new StartWorkFlowModel
            {
                EntityId = entityId,
                RecordId = recordId
            };
            //实体元数据
            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 wfs = _workFlowFinder.QueryAuthorized(model.EntityId, FlowType.Approval);

            if (wfs.IsEmpty())
            {
                return(NotFound());
            }
            model.WorkFlows = wfs;
            return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", model));
        }