예제 #1
0
        /// <summary>
        /// 创建一个实例
        /// </summary>
        /// <returns></returns>
        public bool CreateInstance(JObject obj)
        {
            var flowInstance = obj.ToObject <FlowInstance>();

            if (flowInstance.FrmType == 0)
            {
                //动态表单的数据
                var frmdata = new JObject();
                foreach (var property in obj.Properties().Where(U => U.Name.Contains("data_")))
                {
                    frmdata[property.Name] = property.Value;
                }
                flowInstance.FrmData = JsonHelper.Instance.Serialize(frmdata);
            }

            //创建运行实例
            var wfruntime = new FlowRuntime(flowInstance);
            var user      = _auth.GetCurrentUser();

            #region 根据运行实例改变当前节点状态

            flowInstance.ActivityId     = wfruntime.nextNodeId;
            flowInstance.ActivityType   = wfruntime.GetNextNodeType();
            flowInstance.ActivityName   = wfruntime.nextNode.name;
            flowInstance.PreviousId     = wfruntime.currentNodeId;
            flowInstance.CreateUserId   = user.User.Id;
            flowInstance.CreateUserName = user.User.Account;
            flowInstance.MakerList      = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
            flowInstance.IsFinish       = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);

            UnitWork.Add(flowInstance);
            wfruntime.flowInstanceId = flowInstance.Id;

            if (flowInstance.FrmType == 1)
            {
                var           t   = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App");
                ICustomerForm icf = (ICustomerForm)AutofacExt.GetFromFac(t);
                icf.Add(flowInstance.Id, flowInstance.FrmData);
            }

            #endregion 根据运行实例改变当前节点状态

            #region 流程操作记录

            FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
            {
                InstanceId     = flowInstance.Id,
                CreateUserId   = user.User.Id,
                CreateUserName = user.User.Name,
                CreateDate     = DateTime.Now,
                Content        = "【创建】"
                                 + user.User.Name
                                 + "创建了一个流程进程【"
                                 + flowInstance.Code + "/"
                                 + flowInstance.CustomName + "】"
            };
            UnitWork.Add(processOperationHistoryEntity);

            #endregion 流程操作记录

            AddTransHistory(wfruntime);
            UnitWork.Save();
            return(true);
        }
        /// <summary>
        /// 创建一个实例
        /// </summary>
        /// <returns></returns>
        public bool CreateInstance(AddFlowInstanceReq addFlowInstanceReq)
        {
            FlowScheme scheme = null;

            if (!string.IsNullOrEmpty(addFlowInstanceReq.SchemeId))
            {
                scheme = _flowSchemeApp.Get(addFlowInstanceReq.SchemeId);
            }

            if ((scheme == null) && !string.IsNullOrEmpty(addFlowInstanceReq.SchemeCode))
            {
                scheme = _flowSchemeApp.FindByCode(addFlowInstanceReq.SchemeCode);
            }

            if (scheme == null)
            {
                throw new Exception("该流程模板已不存在,请重新设计流程");
            }

            addFlowInstanceReq.SchemeContent = scheme.SchemeContent;

            var form = _formApp.FindSingle(scheme.FrmId);

            if (form == null)
            {
                throw new Exception("该流程模板对应的表单已不存在,请重新设计流程");
            }

            addFlowInstanceReq.FrmContentData  = form.ContentData;
            addFlowInstanceReq.FrmContentParse = form.ContentParse;
            addFlowInstanceReq.FrmType         = form.FrmType;
            addFlowInstanceReq.FrmId           = form.Id;

            var flowInstance = addFlowInstanceReq.MapTo <FlowInstance>();

            //创建运行实例
            var wfruntime = new FlowRuntime(flowInstance);
            var user      = _auth.GetCurrentUser();

            #region 根据运行实例改变当前节点状态

            flowInstance.ActivityId     = wfruntime.nextNodeId;
            flowInstance.ActivityType   = wfruntime.GetNextNodeType();
            flowInstance.ActivityName   = wfruntime.nextNode.name;
            flowInstance.PreviousId     = wfruntime.currentNodeId;
            flowInstance.CreateUserId   = user.User.Id;
            flowInstance.CreateUserName = user.User.Account;
            flowInstance.MakerList      = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : "");
            flowInstance.IsFinish       = (wfruntime.GetNextNodeType() == 4 ? 1 : 0);

            UnitWork.Add(flowInstance);
            wfruntime.flowInstanceId = flowInstance.Id;

            if (flowInstance.FrmType == 1)
            {
                var           t   = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App");
                ICustomerForm icf = (ICustomerForm)AutofacExt.GetFromFac(t);
                icf.Add(flowInstance.Id, flowInstance.FrmData);
            }

            #endregion 根据运行实例改变当前节点状态

            #region 流程操作记录

            FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory
            {
                InstanceId     = flowInstance.Id,
                CreateUserId   = user.User.Id,
                CreateUserName = user.User.Name,
                CreateDate     = DateTime.Now,
                Content        = "【创建】"
                                 + user.User.Name
                                 + "创建了一个流程进程【"
                                 + addFlowInstanceReq.Code + "/"
                                 + addFlowInstanceReq.CustomName + "】"
            };
            UnitWork.Add(processOperationHistoryEntity);

            #endregion 流程操作记录

            AddTransHistory(wfruntime);
            UnitWork.Save();
            return(true);
        }