コード例 #1
0
        public bool UpdateForward(Guid workflowId, Guid instanceId, Guid processStageId, Guid recordId)
        {
            //var _bpfService = new BusinessProcessFlowInstanceService(User);
            BusinessProcessFlowInstance bpfInstance = _businessProcessFlowInstanceRepository.Find(n => n.BusinessProcessFlowInstanceId == instanceId && n.WorkFlowId == workflowId);
            var stages = _processStageService.Query(n => n
                                                    .Where(f => f.WorkFlowId == bpfInstance.WorkFlowId)
                                                    .Sort(s => s.SortAscending(f => f.StageOrder)));
            var currentStage = stages.Find(n => n.ProcessStageId == processStageId);
            var prevStage    = stages.Find(n => n.StageOrder == currentStage.StageOrder - 1);
            var entityId     = currentStage.EntityId;
            var entityIds    = stages.Select(n => n.EntityId).Distinct().ToList();
            int entityIndex  = entityIds.FindIndex(n => n.Equals(currentStage.EntityId)) + 1;

            if (entityIndex == 1)
            {
                return(this.Update(n => n
                                   .Set(f => f.ProcessStageId, processStageId)
                                   .Set(f => f.ProcessEntityId, entityId)
                                   .Set(f => f.Entity1Id, recordId)
                                   .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                                   ));
            }
            else if (entityIndex == 2)
            {
                return(this.Update(n => n
                                   .Set(f => f.ProcessStageId, processStageId)
                                   .Set(f => f.ProcessEntityId, entityId)
                                   .Set(f => f.Entity2Id, recordId)
                                   .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                                   ));
            }
            else if (entityIndex == 3)
            {
                return(this.Update(n => n
                                   .Set(f => f.ProcessStageId, processStageId)
                                   .Set(f => f.ProcessEntityId, entityId)
                                   .Set(f => f.Entity3Id, recordId)
                                   .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                                   ));
            }
            else if (entityIndex == 4)
            {
                return(this.Update(n => n
                                   .Set(f => f.ProcessStageId, processStageId)
                                   .Set(f => f.ProcessEntityId, entityId)
                                   .Set(f => f.Entity4Id, recordId)
                                   .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                                   ));
            }
            else if (entityIndex == 5)
            {
                return(this.Update(n => n
                                   .Set(f => f.ProcessStageId, processStageId)
                                   .Set(f => f.ProcessEntityId, entityId)
                                   .Set(f => f.Entity5Id, recordId)
                                   .Where(w => w.BusinessProcessFlowInstanceId == bpfInstance.BusinessProcessFlowInstanceId)
                                   ));
            }
            return(false);
        }
コード例 #2
0
 public bool Update(BusinessProcessFlowInstance entity)
 {
     return(_businessProcessFlowInstanceRepository.Update(entity));
 }
コード例 #3
0
        public IActionResult UpdateProcessStage(UpdateProcessStageModel model)
        {
            if (model.EntityId.Equals(Guid.Empty) || model.RecordId.Equals(Guid.Empty) || model.WorkflowId.Equals(Guid.Empty) || model.StageId.Equals(Guid.Empty))
            {
                return(JError(T["parameter_error"]));
            }
            var entityMeta = _entityFinder.FindById(model.EntityId);

            if (entityMeta == null)
            {
                return(NotFound());
            }
            var flowInfo = _workFlowFinder.FindById(model.WorkflowId);

            if (flowInfo == null)
            {
                return(NotFound());
            }
            var data = _dataFinder.RetrieveById(entityMeta.Name, model.RecordId);

            if (data.IsEmpty())
            {
                return(NotFound());
            }
            var stages = _processStageService.Query(n => n
                                                    .Where(f => f.WorkFlowId == flowInfo.WorkFlowId)
                                                    .Sort(s => s.SortAscending(f => f.StageOrder)));

            var currentStage = stages.Find(n => n.ProcessStageId == model.StageId);
            var entityIds    = stages.Select(n => n.EntityId).Distinct().ToList();
            int entityIndex  = entityIds.FindIndex(n => n.Equals(currentStage.EntityId)) + 1;
            BusinessProcessFlowInstance bpfInstance = null;

            if (model.InstanceId.HasValue && !model.InstanceId.Value.Equals(Guid.Empty))
            {
                bpfInstance = _businessProcessFlowInstanceService.Find(n => n.BusinessProcessFlowInstanceId == model.InstanceId && n.WorkFlowId == model.WorkflowId);
                if (bpfInstance == null)
                {
                    return(NotFound());
                }
            }
            if (bpfInstance == null)
            {
                bpfInstance = new BusinessProcessFlowInstance();
                bpfInstance.BusinessProcessFlowInstanceId = Guid.NewGuid();
                bpfInstance.WorkFlowId      = model.WorkflowId;
                bpfInstance.ProcessStageId  = currentStage.ProcessStageId;
                bpfInstance.Entity1Id       = model.FromRecordId;
                bpfInstance.Entity2Id       = model.RecordId;
                bpfInstance.ProcessEntityId = model.EntityId;
                _businessProcessFlowInstanceService.Create(bpfInstance);
            }
            else
            {
                var originalStage = stages.Find(n => n.ProcessStageId == bpfInstance.ProcessStageId);
                var isForward     = currentStage.StageOrder > originalStage.StageOrder;
                if (isForward)
                {
                    _businessProcessFlowInstanceUpdater.UpdateForward(model.WorkflowId, bpfInstance.BusinessProcessFlowInstanceId, model.StageId, model.RecordId);
                }
                //如果后退并且阶段不在同一实体,更新实例对应的记录id
                else if (!isForward)
                {
                    if (!model.InstanceId.HasValue || model.InstanceId.Equals(Guid.Empty))
                    {
                        return(JError(T["parameter_error"]));
                    }
                    _businessProcessFlowInstanceUpdater.UpdateBack(model.WorkflowId, model.InstanceId.Value, model.StageId, model.RecordId);
                }
            }
            //更新当前记录的业务阶段
            var updData = new Entity(data.Name);

            updData.SetIdValue(data.GetIdValue());
            updData.SetAttributeValue("stageid", model.StageId);
            _dataUpdater.Update(updData);

            return(SaveSuccess());
        }
コード例 #4
0
        public IActionResult ForwardAndAppend(Guid entityid, Guid referencedrecordid, Guid workflowid, Guid stageid, Guid?instanceId, string relationshipname)
        {
            if (entityid.Equals(Guid.Empty) || referencedrecordid.Equals(Guid.Empty) || workflowid.Equals(Guid.Empty) || stageid.Equals(Guid.Empty))
            {
                return(JError(T["parameter_error"]));
            }
            var entityMeta = _entityFinder.FindById(entityid);

            if (entityMeta == null)
            {
                return(NotFound());
            }
            var flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == workflowid);

            if (flowInfo == null)
            {
                return(NotFound());
            }
            var stages = _processStageService.Query(n => n
                                                    .Where(f => f.WorkFlowId == flowInfo.WorkFlowId)
                                                    .Sort(s => s.SortAscending(f => f.StageOrder)));

            var currentStage = stages.Find(n => n.ProcessStageId == stageid);
            var prevStage    = stages.Find(n => n.StageOrder == currentStage.StageOrder - 1);

            if (currentStage.EntityId.Equals(prevStage.EntityId))
            {
                return(JError(T["parameter_error"]));
            }
            BusinessProcessFlowInstance bpfInstance = null;

            if (instanceId.HasValue && !instanceId.Value.Equals(Guid.Empty))
            {
                bpfInstance = _businessProcessFlowInstanceService.Find(n => n.BusinessProcessFlowInstanceId == instanceId && n.WorkFlowId == workflowid);
                if (bpfInstance == null)
                {
                    return(NotFound());
                }
            }
            if (bpfInstance == null)
            {
                instanceId  = Guid.NewGuid();
                bpfInstance = new BusinessProcessFlowInstance();
                bpfInstance.BusinessProcessFlowInstanceId = instanceId.Value;
                bpfInstance.WorkFlowId      = workflowid;
                bpfInstance.ProcessStageId  = stages.First().ProcessStageId;
                bpfInstance.Entity1Id       = referencedrecordid;
                bpfInstance.ProcessEntityId = entityid;
                _businessProcessFlowInstanceService.Create(bpfInstance);
            }
            //是否存在单据转换规则
            var entityMap = _entityMapFinder.Find(prevStage.EntityId, entityid);

            if (entityMap == null)
            {
                return(JOk(new
                {
                    EntityId = entityid
                    ,
                    StageId = stageid
                    ,
                    BusinessFlowId = workflowid
                    ,
                    BusinessFlowInstanceId = instanceId.Value
                    ,
                    RelationShipName = relationshipname
                    ,
                    ReferencedRecordId = referencedrecordid
                }));
            }
            var recordid = _dataMapper.Create(prevStage.EntityId, currentStage.EntityId, referencedrecordid);

            _businessProcessFlowInstanceUpdater.UpdateForward(workflowid, instanceId.Value, stageid, recordid);
            //更新当前记录的业务阶段
            var updData = new Entity(entityMeta.Name);

            updData.SetIdValue(recordid);
            updData.SetAttributeValue("stageid", stageid);
            _dataUpdater.Update(updData);

            return(JOk(new
            {
                EntityId = entityid
                ,
                RecordId = recordid
                ,
                BusinessFlowId = workflowid
                ,
                BusinessFlowInstanceId = instanceId.Value
            }));
        }
コード例 #5
0
        public IActionResult BusinessProcess([FromBody] BusinessProcessArgsModel args)
        {
            if (args.EntityId.Equals(Guid.Empty) || args.RecordId.Equals(Guid.Empty))
            {
                return(JError(T["parameter_error"]));
            }
            var entityMeta = _entityFinder.FindById(args.EntityId);

            if (entityMeta == null)
            {
                return(NotFound());
            }
            if (!entityMeta.BusinessFlowEnabled)
            {
                return(JError(T["businessflow_disabled"]));
            }
            var data = this._dataFinder.RetrieveById(entityMeta.Name, args.RecordId);

            if (data.IsEmpty())
            {
                return(NotFound());
            }
            WorkFlow flowInfo = null;
            BusinessProcessFlowInstance flowInstance = null;
            List <ProcessStage>         stages       = null;
            Guid entityStageId = data.GetGuidValue("stageid");
            int  entityIndex   = 0;

            if (args.BusinessflowId.HasValue && !args.BusinessflowId.Equals(Guid.Empty))
            {
                flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == args.BusinessflowId.Value);
            }
            else if (args.BusinessflowInstanceId.HasValue && !args.BusinessflowInstanceId.Value.Equals(Guid.Empty))
            {
                flowInstance = _businessProcessFlowInstanceService.FindById(args.BusinessflowInstanceId.Value);
                if (flowInstance != null)
                {
                    flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == flowInstance.WorkFlowId);
                }
            }
            if (flowInfo == null)
            {
                var flowList = _workFlowFinder.QueryAuthorized(args.EntityId, FlowType.Business);
                flowInfo = flowList.NotEmpty() ? flowList.First() : null;
                if (flowInfo == null && !entityStageId.Equals(Guid.Empty))
                {
                    //查找当前实体所在阶段
                    var processstage = _processStageService.Find(n => n.ProcessStageId == entityStageId);
                    if (processstage == null)
                    {
                        return(NotFound());
                    }
                    flowInfo = _workFlowFinder.Find(n => n.WorkFlowId == processstage.WorkFlowId && n.StateCode == RecordState.Enabled);
                }
            }
            if (flowInfo == null)
            {
                return(Content(""));
            }
            stages = _processStageService.Query(n => n
                                                .Where(f => f.WorkFlowId == flowInfo.WorkFlowId)
                                                .Sort(s => s.SortAscending(f => f.StageOrder))
                                                );
            var entityIds = stages.Select(n => n.EntityId).Distinct().ToList();

            entityIndex = entityIds.FindIndex(n => n.Equals(args.EntityId)) + 1;
            //查询业务流程实例
            if (flowInstance == null)
            {
                if (entityIndex == 1)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity1Id == args.RecordId);
                }

                if (entityIndex == 2)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity2Id == args.RecordId);
                }

                if (entityIndex == 3)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity3Id == args.RecordId);
                }

                if (entityIndex == 4)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity4Id == args.RecordId);
                }

                if (entityIndex == 5)
                {
                    flowInstance = _businessProcessFlowInstanceService.Find(n => n.WorkFlowId == flowInfo.WorkFlowId && n.Entity5Id == args.RecordId);
                }
            }

            if (flowInstance != null)
            {
                entityStageId = flowInstance.ProcessStageId.Value;
            }
            BusinessProcessModel model = new BusinessProcessModel
            {
                EntityId             = args.EntityId,
                RecordId             = args.RecordId,
                Data                 = data,
                BusinessFlow         = flowInfo,
                BusinessFlowInstance = flowInstance,
                Stages               = stages
            };

            model.CurrentStageId = entityStageId.Equals(Guid.Empty) ? model.Stages.First().ProcessStageId : entityStageId;
            Dictionary <string, object>    steps      = new Dictionary <string, object>();
            List <Schema.Domain.Attribute> attributes = new List <Schema.Domain.Attribute>();

            foreach (var stage in model.Stages)
            {
                var st = new List <ProcessStep>();
                st = st.DeserializeFromJson(stage.Steps);
                steps.Add(stage.ProcessStageId.ToString(), st);
                var attrs = st.Select(f => f.AttributeName).ToList();
                attributes.AddRange(_attributeFinder.Query(n => n.Where(f => f.Name.In(attrs) && f.EntityId == stage.EntityId)));
            }
            model.Steps      = steps;
            model.Attributes = attributes;
            var related = model.Stages.Where(n => n.RelationshipName.IsNotEmpty()).ToList();

            if (related.NotEmpty())
            {
                var rnames = related.Select(f => f.RelationshipName).ToList();
                model.RelationShips = _relationShipFinder.Query(n => n.Where(f => f.Name.In(rnames)));
                _relationShipFinder.WrapLocalizedLabel(model.RelationShips);
            }
            if (model.BusinessFlowInstance != null)
            {
                var rsRecords = new Dictionary <string, object>();
                int i         = 1;
                foreach (var eid in entityIds)
                {
                    var eidMeta = _entityFinder.FindById(eid);
                    var filter  = new Dictionary <string, object>();
                    if (i == 1 && flowInstance.Entity1Id.HasValue && !flowInstance.Entity1Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity1Id);
                    }

                    if (i == 2 && flowInstance.Entity2Id.HasValue && !flowInstance.Entity2Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity2Id);
                    }

                    if (i == 3 && flowInstance.Entity3Id.HasValue && !flowInstance.Entity3Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity3Id);
                    }

                    if (i == 4 && flowInstance.Entity4Id.HasValue && !flowInstance.Entity4Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity4Id);
                    }

                    if (i == 5 && flowInstance.Entity5Id.HasValue && !flowInstance.Entity5Id.Value.Equals(Guid.Empty))
                    {
                        filter.Add(eidMeta.Name + "id", flowInstance.Entity5Id);
                    }

                    if (filter.Count > 0)
                    {
                        rsRecords.Add(eid.ToString(), _dataFinder.RetrieveByAttribute(eidMeta.Name, filter));
                    }
                    else
                    {
                        rsRecords.Add(eid.ToString(), null);
                    }

                    i++;
                }
                model.RelatedRecords = rsRecords;
            }
            return(View($"~/Views/Flow/{WebContext.ActionName}.cshtml", model));
        }