public async Task <ActionResult> Index(TableSource src, long proInsId = 0, long currActInsId = 0, long id = 0)
        {
            var result = new JsonModel();

            result.statusCode = 300;
            var process = await WorkflowSvc.GetProcessBySource(src);

            if (process == null)
            {
                result.message = $"请假流程还未创建,请先创建{src}流程!";
                return(Json(result, JsonRequestBehavior.AllowGet));
            }

            var model = await GetModel(src, id, result);

            if (model == null)
            {
                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            model.Id                = id;
            model.ProcessId         = process.Id;
            model.ProcessInstanceId = proInsId;
            model.CurrActInsId      = currActInsId;
            model.DealActivityList  = new List <WfActivityInstance>();
            model.TableSource       = src;

            if (proInsId != 0)
            {
                model.DealActivityList = await WorkflowSvc.GetDealActivityListAsync(proInsId);
            }
            return(View(model));
        }
Пример #2
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));
        }