예제 #1
0
        public bool CreateOrUpdate(ITPurchaseViewModel viewModel, WFInstanceViewModel wFInstanceView, Guid userId, string userName)
        {
            if (viewModel.Id == new Guid())
            {
                viewModel = mapper.Map(exampleContext.ITPurchase.Add(mapper.Map <ITPurchase>(viewModel)).Entity, viewModel);
            }
            else
            {
                viewModel = mapper.Map(exampleContext.ITPurchase.Update(mapper.Map <ITPurchase>(viewModel)).Entity, viewModel);
            }

            if (viewModel.AssetItem != null)
            {
                for (int i = 0; i < viewModel.AssetItem.Count; i++)
                {
                    viewModel.AssetItem[i].BillId = viewModel.Id;
                    if (viewModel.AssetItem[i].Id == new Guid())
                    {
                        viewModel.AssetItem[i] = mapper.Map(exampleContext.AssetPuchase.Add(mapper.Map <AssetPuchase>(viewModel.AssetItem[i])).Entity, viewModel.AssetItem[i]);
                    }
                    else
                    {
                        viewModel.AssetItem[i] = mapper.Map(exampleContext.AssetPuchase.Update(mapper.Map <AssetPuchase>(viewModel.AssetItem[i])).Entity, viewModel.AssetItem[i]);
                    }
                }
            }
            exampleContext.SaveChanges();
            wFContext.SaveChanges();

            wFInstanceView.Desc  = $"{viewModel.ApplicantName}发起采购申请,总金额{viewModel.EstimatedAmount}";
            wFInstanceView.BId   = viewModel.Id;
            wFInstanceView.BType = typeof(ITPurchase).Name;

            var wf = iWFInstanceServer.CreateWFInstance(wFInstanceView, userId, userName);

            if (wf == null)
            {
                //没有创建成功
                return(false);
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// 根据模板创建空白的流程实例
        /// </summary>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public WFInstanceViewModel GetWFWhiteByTemplate(Guid templateId)
        {
            var wfTemplate = templateServer.GetTemplateById(templateId);
            var instance   = new WFInstanceViewModel();

            instance.BId   = new Guid();
            instance.BType = "";

            instance.Id    = new Guid();
            instance.WFId  = templateId;
            instance.Lines = wfTemplate.Lines;
            instance.Nodes = new List <WFNodeInstanceViewModel>();

            if (wfTemplate.Nodes != null)
            {
                foreach (var item in wfTemplate.Nodes)
                {
                    var nodeInstance = new WFNodeInstanceViewModel();
                    nodeInstance.Id           = new Guid();
                    nodeInstance.ActionLogs   = "";
                    nodeInstance.BType        = "";
                    nodeInstance.BId          = new Guid();
                    nodeInstance.WFId         = templateId;
                    nodeInstance.InLines      = item.InLines;
                    nodeInstance.OutLines     = item.OutLines;
                    nodeInstance.State        = WFState.Undefine;
                    nodeInstance.WFInstanceId = instance.Id;
                    nodeInstance.WFNodeId     = item.NodeDefine.Id;
                    nodeInstance.NodeDefine   = item.NodeDefine;
                    nodeInstance.NodeLogs     = new List <NodeActionLog>();
                    nodeInstance.UserId       = string.IsNullOrEmpty(nodeInstance.NodeDefine.UserId)? new Guid():new Guid(nodeInstance.NodeDefine.UserId);
                    nodeInstance.UserName     = string.IsNullOrEmpty(nodeInstance.NodeDefine.UserId) ?"": nodeInstance.NodeDefine.UserName;

                    instance.Nodes.Add(nodeInstance);
                }
            }

            return(instance);
        }
예제 #3
0
 public WFInstanceViewModel CreateWFInstance([FromBody] WFInstanceViewModel viewModel, Guid userId, String userName)
 {
     //解析token,获取用户id,用户名称
     return(iWFInstanceServer.CreateWFInstance(viewModel, userId, userName));
 }
예제 #4
0
        /// <summary>
        /// 新增工作流实例
        /// 将实例存入运行实例池
        /// 将实例信息入库
        /// </summary>
        /// <returns></returns>
        public WFInstanceViewModel CreateWFInstance(WFInstanceViewModel wFInstanceViewModel, Guid userId, string userName)
        {
            wFInstanceViewModel.Id = new Guid();

            if (wFInstanceViewModel.BId == new Guid())
            {
                throw new Exception("关联单据必填");
            }

            if (string.IsNullOrWhiteSpace(wFInstanceViewModel.BType))
            {
                throw new Exception("单据类型必填");
            }

            if (wFInstanceViewModel.WFId == new Guid())
            {
                throw new Exception("流程模板必填");
            }

            var wfTemplate = GetWFWhiteByTemplate(wFInstanceViewModel.WFId);

            if (wfTemplate == null)
            {
                return(null);
            }

            //判断该单据是否已经参与流程管理,如果参与了,则不允许再创建新的流程。

            var wfInstance = mapper.Map <WFInstance>(wFInstanceViewModel);

            wfInstance.Id = Guid.NewGuid();
            wFContext.WFInstance.BulkInsert(new List <WFInstance> {
                wfInstance
            });
            wFInstanceViewModel = mapper.Map(wfInstance, wFInstanceViewModel);
            Guid nextNodeId = new Guid();

            var startNode = wFInstanceViewModel.Nodes.FirstOrDefault(p => NodeType.Start == p.NodeDefine.NodeType);

            if (startNode != null)
            {
                startNode.NodeLogs.Add(new NodeActionLog()
                {
                    Action      = WFOperation.Create,
                    OperateTime = TimeHelper.GetTimeStamp(),
                    Opinions    = "",
                    UserName    = userName
                });
                startNode.State        = WFState.Created;
                startNode.UserId       = userId;
                startNode.BId          = wFInstanceViewModel.BId;
                startNode.BType        = wFInstanceViewModel.BType;
                startNode.WFInstanceId = wfInstance.Id;
                startNode.WFId         = wFInstanceViewModel.WFId;

                nextNodeId = startNode.OutLines[0].ENodeId;

                var nodeInstance = mapper.Map <WFNodeInstance>(startNode);
                nodeInstance.Id = Guid.NewGuid();
                wFContext.WFNodeInstance.BulkInsert(new List <WFNodeInstance> {
                    nodeInstance
                });
                startNode = mapper.Map(nodeInstance, startNode);
            }
            else
            {
                throw new Exception("开始节点未定义,请联系管理员~");
            }

            for (int i = 0; i < wFInstanceViewModel.Nodes.Count; i++)
            {
                if (wFInstanceViewModel.Nodes[i].NodeDefine.NodeType != NodeType.Start)
                {
                    wFInstanceViewModel.Nodes[i].Id       = new Guid();
                    wFInstanceViewModel.Nodes[i].NodeLogs = new List <NodeActionLog>();

                    if (wFInstanceViewModel.Nodes[i].WFNodeId == nextNodeId)
                    {
                        if (wFInstanceViewModel.Nodes[i].UserId == new Guid() && string.IsNullOrEmpty(wFInstanceViewModel.Nodes[i].NodeDefine.UserId))
                        {
                            wFInstanceViewModel.Nodes[i].UserId   = userId;
                            wFInstanceViewModel.Nodes[i].UserName = userName;
                        }

                        wFInstanceViewModel.Nodes[i].State        = WFState.WaitSend;
                        wFInstanceViewModel.Nodes[i].WFInstanceId = wfInstance.Id;
                        wFInstanceViewModel.Nodes[i].BId          = wFInstanceViewModel.BId;
                        wFInstanceViewModel.Nodes[i].BType        = wFInstanceViewModel.BType;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(wFInstanceViewModel.Nodes[i].NodeDefine.UserId))
                        {
                            wFInstanceViewModel.Nodes[i].UserId   = new Guid();
                            wFInstanceViewModel.Nodes[i].UserName = "";
                        }
                        else
                        {
                            wFInstanceViewModel.Nodes[i].UserId   = new Guid(wFInstanceViewModel.Nodes[i].NodeDefine.UserId);
                            wFInstanceViewModel.Nodes[i].UserName = wFInstanceViewModel.Nodes[i].NodeDefine.UserName;
                        }
                        wFInstanceViewModel.Nodes[i].State = WFState.Undefine;

                        wFInstanceViewModel.Nodes[i].WFInstanceId = wfInstance.Id;
                        wFInstanceViewModel.Nodes[i].BId          = wFInstanceViewModel.BId;
                        wFInstanceViewModel.Nodes[i].BType        = wFInstanceViewModel.BType;
                    }
                    wFInstanceViewModel.Nodes[i].Desc = wfInstance.Desc;
                    var nodeInstance = mapper.Map <WFNodeInstance>(wFInstanceViewModel.Nodes[i]);
                    nodeInstance.Id = Guid.NewGuid();
                    wFContext.WFNodeInstance.BulkInsert(new List <WFNodeInstance> {
                        nodeInstance
                    });
                    wFInstanceViewModel.Nodes[i] = mapper.Map(nodeInstance, wFInstanceViewModel.Nodes[i]);
                }
            }

            if (!iWFPool.WFs.TryAdd(wFInstanceViewModel.Id, wFInstanceViewModel))
            {
                return(null);
            }

            return(wFInstanceViewModel);
        }