Example #1
0
        private async Task CompleteProcess(WfProcessInstance processInstance)
        {
            processInstance.ProcessState     = WfProcessState.Completed;
            processInstance.CurrActivityName = "结束";

            //TODO:更新数据源的状态
            var src = await GetSourceAsync(processInstance.TableSource, processInstance.SourceId);

            src.CommonStatus = CommonStatus.Enabled;
            await WfProcessInstanceRepository.SaveAsync(processInstance);
        }
Example #2
0
        public async Task <JsonModel> StartProcess(long processId,
                                                   long sourceId,
                                                   string condition,
                                                   string nextStepId,
                                                   string assignToUserIds,
                                                   string assignToUserNames)
        {
            var result = new JsonModel();
            //创建流程实例
            var process = await GetProcessById(processId);

            if (result == null)
            {
                result.statusCode = 300;
                result.message    = "流程不存在!processId:" + processId;
                return(result);
            }
            var processInstance = new WfProcessInstance()
            {
                CommonStatus = CommonStatus.Enabled,
                ProcessName  = process.Name,
                ProcessState = WfProcessState.Running,
                SourceId     = sourceId,
                TableSource  = process.TableSource,
                WfProcessId  = process.Id,
                Conditions   = condition
            };
            await WfProcessInstanceRepository.SaveAsync(processInstance);

            //创建流程节点
            var firstAct = process.GetFirstActivity();

            if (firstAct == null)
            {
                result.statusCode = 300;
                result.message    = $"流程 {process.Name}的第一个节点找不到!";
                return(result);
            }
            WfActivityInstance firstActInstance = CreateActivityInstance(process,
                                                                         processInstance,
                                                                         firstAct,
                                                                         WfActivityState.Completed,
                                                                         User.UserInfo.UserId,
                                                                         User.UserInfo.RealName);

            firstActInstance.DealTime     = DateTime.Now;
            firstActInstance.DealUserId   = User.UserInfo.UserId;
            firstActInstance.DealUserName = User.UserInfo.RealName;
            await WfActivityInstanceRepository.SaveAsync(firstActInstance);

            //创建下一步节点
            var nextAct = process.GetActivity(nextStepId);

            if (nextAct == null)
            {
                result.statusCode = 300;
                result.message    = $"流程 {process.Name}的节点 {nextStepId} 找不到!";
                return(result);
            }
            var nextActInstance = CreateActivityInstance(process,
                                                         processInstance,
                                                         nextAct,
                                                         WfActivityState.Running,
                                                         assignToUserIds,
                                                         assignToUserNames);

            nextActInstance.PreActInstanceId = firstActInstance.Id;
            await WfActivityInstanceRepository.SaveAsync(nextActInstance);

            processInstance.CurrActivityName = nextActInstance.ActivityName;
            await WfProcessInstanceRepository.SaveAsync(processInstance);

            return(result);
        }