Ejemplo 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));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 选择下一步骤及人员
        /// </summary>
        /// <param name="type"></param>
        /// <param name="processId"></param>
        /// <param name="currActId"></param>
        /// <param name="conditions"></param>
        /// <returns></returns>
        public async Task <ActionResult> FlowStepSelect(WfActivityType type,
                                                        long processId,
                                                        string currActId,
                                                        string conditions,
                                                        long proInsId = 0)
        {
            var jsonResult = new JsonModel();

            jsonResult.statusCode = 300;

            #region 找流程
            var process = await WorkflowSvc.GetProcessById(processId);

            if (process == null)
            {
                jsonResult.message = $"找不到id为{processId}的流程!";
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }
            #endregion

            #region 找当前节点
            WfActivity currAct = null;
            switch (type)
            {
            case WfActivityType.Start:
                currAct = process.GetFirstActivity();
                break;

            case WfActivityType.Task:
                if (string.IsNullOrEmpty(currActId))
                {
                    jsonResult.message = "请输入当前节点Id!";
                    return(Json(jsonResult, JsonRequestBehavior.AllowGet));
                }
                currAct = process.GetActivity(currActId);
                break;

            default:
                break;
            }
            if (currAct == null)
            {
                jsonResult.message = "当前节点不存在!";
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }
            #endregion

            #region 找可选节点列表
            var condition = GetCondition(conditions);
            var nextList  = process.GetNextActivityList(currAct.key, condition);
            if (nextList == null || nextList.Count == 0)
            {
                jsonResult.message = "可选节点为空!请重新编辑流程!";
                return(Json(jsonResult, JsonRequestBehavior.AllowGet));
            }

            List <Users> launchUsers = new List <Users>();

            var model = new List <WfActivitySelectModel>();
            foreach (var act in nextList)
            {
                switch (act.dealType)
                {
                case WfActivityDealType.Creater:
                    var getResult = await GetLaunchUser(proInsId, launchUsers, model, act, jsonResult);

                    if (!getResult)
                    {
                        return(Json(jsonResult, JsonRequestBehavior.AllowGet));
                    }
                    break;

                case WfActivityDealType.Role:
                    await GetRoleUsers(model, act);

                    break;

                default:
                    break;
                }
            }

            #endregion

            return(View(model));
        }
Ejemplo n.º 3
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));
        }