Exemplo n.º 1
0
        /// <summary>
        /// 处理节点
        /// </summary>
        /// <param name="proInsId"></param>
        /// <param name="actInsId"></param>
        /// <returns></returns>
        public async Task <ActionResult> DealActivity(long proInsId, long actInsId)
        {
            var jsonModel = new JsonModel();

            jsonModel.statusCode = 300;
            #region //获取流程实例
            var processInstance = await WorkflowSvc.GetProcessInstanceAsync(proInsId);

            if (processInstance == null)
            {
                jsonModel.message = $"找不到id为{proInsId}的流程实例!";
                return(Json(jsonModel, JsonRequestBehavior.AllowGet));
            }
            #endregion

            #region  //判断显示哪些按钮:1:回退;2:发送;3:完成。

            var process = await WorkflowSvc.GetProcessById(processInstance.WfProcessId);

            if (process == null)
            {
                jsonModel.message = $"找不到id为{processInstance.WfProcessId}的流程!";
                return(Json(jsonModel, JsonRequestBehavior.AllowGet));
            }

            var currActIns = await WorkflowSvc.GetActivityAsync(proInsId, actInsId);

            if (currActIns == null)
            {
                jsonModel.message = $"流程{processInstance.ProcessName}({proInsId})中找不到id为{actInsId}的节点实例!";
                return(Json(jsonModel, JsonRequestBehavior.AllowGet));
            }

            if (currActIns.ActivityState != WfActivityState.Running)
            {
                jsonModel.message = $"该节点实例[{currActIns.ActivityName}(id:{currActIns.Id})]已经处理,状态为[{currActIns.ActivityState.GetDescriotion()}]!";
                return(Json(jsonModel, JsonRequestBehavior.AllowGet));
            }

            //如果是第一个节点,这跳转到对应的申请页面
            var firstAct = process.GetFirstActivity();
            if (firstAct.key == currActIns.ActivityGuid)
            {
                return(RedirectToAction("Index", "WorkflowApply", new
                {
                    proInsId = processInstance.Id,
                    id = processInstance.SourceId,
                    currActInsId = currActIns.Id,
                    src = processInstance.TableSource
                }));
            }

            WfActivityButton buttons = WfActivityButton.None;
            //是否有回退按钮
            if (currActIns.PreActInstanceId != 0)
            {
                buttons = buttons | WfActivityButton.FallBack;
            }
            var conditions = GetCondition(processInstance.Conditions);
            var nextList   = process.GetNextActivityList(currActIns.ActivityGuid, conditions);

            if (nextList == null || nextList.Count == 0)
            {
                jsonModel.message = "可选节点为空!请重新编辑流程!";
                return(Json(jsonModel, JsonRequestBehavior.AllowGet));
            }
            if (nextList.Any(m => m.activityType == WfActivityType.End))
            {
                buttons = buttons | WfActivityButton.Complete;
            }
            if (nextList.Any(m => m.activityType == WfActivityType.Task))
            {
                buttons = buttons | WfActivityButton.Send;
            }
            #endregion

            #region 获取历史处理信息
            var dealActivityList = await WorkflowSvc.GetDealActivityListAsync(processInstance.Id);

            #endregion

            #region  //获取展示信息
            var src = await WorkflowSvc.GetSourceAsync(processInstance.TableSource, processInstance.SourceId);

            if (src == null)
            {
                jsonModel.message = $"找不到id为{processInstance.SourceId}的数据源{processInstance.TableSource}!";
                return(Json(jsonModel, JsonRequestBehavior.AllowGet));
            }
            #endregion

            var model = new DealActivityViewModel()
            {
                ActivityInstance = currActIns,
                Buttons          = buttons,
                SourceData       = src,
                TableSource      = processInstance.TableSource,
                DealActivityList = dealActivityList,
                ProcessInstance  = processInstance
            };
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> BackStepSelect(long proInsId,
                                                        long actInsId)
        {
            var result = new JsonModel();

            result.statusCode = 300;
            #region 检查数据完整性
            var processInstance = await WorkflowSvc.GetProcessInstanceAsync(proInsId);

            if (processInstance == null)
            {
                result.message = $"找不到Id为{proInsId}的流程实例!";
                return(Json(result));
            }
            var process = await WorkflowSvc.GetProcessById(processInstance.WfProcessId);

            if (process == null)
            {
                result.message = $"找不到Id为{processInstance.WfProcessId}的流程";
                return(Json(result));
            }
            var currActInstance = await WorkflowSvc.GetActivityAsync(processInstance.Id, actInsId);

            if (currActInstance == null)
            {
                result.message = $"在流程实例[{processInstance.ProcessName}({processInstance.Id})]中找不到id为{actInsId}的节点实例";
                return(Json(result));
            }
            var currActivity = process.GetActivity(currActInstance.ActivityGuid);
            if (currActivity == null)
            {
                result.message = $"在流程[{process.Name}({process.Id})]中找不到key为{currActInstance.ActivityGuid}的节点";
                return(Json(result));
            }
            #endregion

            #region 获取回退节点
            WfActivity backStep = null;
            switch (currActivity.backType)
            {
            case WfActivityBackType.PreStep:
                var preActInstance = await WorkflowSvc.GetActivityAsync(processInstance.Id, currActInstance.PreActInstanceId);

                backStep = process.GetActivity(preActInstance.ActivityGuid);
                break;

            case WfActivityBackType.FirstStep:
                backStep = process.GetFirstActivity();
                break;

            case WfActivityBackType.OtherStep:
                backStep = process.GetActivity(currActivity.backStep);
                break;

            default:
                break;
            }
            #endregion

            return(View(backStep));
        }