public void UpdateOnRecordDeleted(Guid entityId, Guid recordId) { var bpfInstances = _businessProcessFlowInstanceRepository.Query(f => (f.Entity1Id.IsNotNull() && f.Entity1Id == recordId) || (f.Entity2Id.IsNotNull() && f.Entity2Id == recordId) || (f.Entity3Id.IsNotNull() && f.Entity3Id == recordId) || (f.Entity4Id.IsNotNull() && f.Entity4Id == recordId) || (f.Entity5Id.IsNotNull() && f.Entity5Id == recordId) ); foreach (var bpfInstance in bpfInstances) { var stages = _processStageService.Query(n => n .Where(f => f.WorkFlowId == bpfInstance.WorkFlowId) .Sort(s => s.SortAscending(f => f.StageOrder))); var entityIds = stages.Select(n => n.EntityId).Distinct().ToList(); int entityIndex = entityIds.FindIndex(n => n.Equals(entityId)) + 1; if (entityIndex == 1) { _businessProcessFlowInstanceRepository.DeleteById(bpfInstance.BusinessProcessFlowInstanceId); } //前一实体的最后一个阶段 else { var prevStage = stages.Where(n => n.EntityId == entityIds[entityIndex - 2]).ToList().Last(); UpdateBack(bpfInstance.WorkFlowId, bpfInstance.BusinessProcessFlowInstanceId, prevStage.ProcessStageId, recordId); } } }
public bool DeleteById(Guid id) { return(_businessProcessFlowInstanceRepository.DeleteById(id)); }