Ejemplo n.º 1
0
        public void Create()
        {
            // 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置)
            var options = new IdGeneratorOptions()
            {
                Method   = 1,
                WorkerId = 1
            };

            YitIdHelper.SetIdGenerator(options);
            var code = YitIdHelper.NextId().ToString();

            var app         = _autofacServiceProvider.GetService <FlowInstanceApp>();
            var instanceReq = new AddFlowInstanceReq
            {
                SchemeId   = "0dac17c2-fec7-4bcd-a391-4ff74de8506a",
                FrmType    = 1,
                DbName     = "FrmLeaveReq",
                FrmData    = "{\"id\":\"\",\"userName\":\"周翔宇\",\"requestType\":\"病假\",\"startDate\":\"2021-03-08T16:00:00.000Z\",\"startTime\":\"2021-03-16T15:11:28.000Z\",\"endDate\":\"2021-03-24T16:00:00.000Z\",\"endTime\":\"2021-03-16T15:11:31.000Z\",\"requestComment\":\"1111\",\"attachment\":\"\",\"files\":[],\"extendInfo\":\"\"}",
                CustomName = DateTime.Now.ToString(),
                Code       = code
            };

            app.CreateInstance(instanceReq);
        }
 public string Add(AddFlowInstanceReq obj)
 {
     try
     {
         _app.CreateInstance(obj);
     }
     catch (Exception ex)
     {
         Result.Code    = 500;
         Result.Message = ex.InnerException?.Message ?? ex.Message;
     }
     return(JsonHelper.Instance.Serialize(Result));
 }
Ejemplo n.º 3
0
        public Response Add([FromBody] AddFlowInstanceReq obj)
        {
            var result = new Response();

            try
            {
                _app.CreateInstance(obj);
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.InnerException?.Message ?? ex.Message;
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <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)_serviceProvider.GetService(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);
        }