public IList <NonRoutineJobDTO> GetNonRoutineJobDTOs(IEnumerable <int> nonRoutineIds) { return(_loader.GetObjectListAll <NonRoutineJobDTO>(new ICommonFilter[] { new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, nonRoutineIds.ToArray()) } , true)); }
/// <summary> /// Загружает все элементы рабочего пакета /// </summary> /// <param name="package"></param> public void LoadPackageItems <T, TV>(T package) where T : AbstractPackage <TV>, new() where TV : BasePackageRecord, new() { // Компоненты package.PackageRecords.Clear(); package.PackageRecords.AddRange(_loader.GetObjectListAll <TV>(BasePackageRecord.ParentPackageIdProperty, package.ItemId)); foreach (TV record in package.PackageRecords) { record.ParentPackage = package; } IEnumerable <IGrouping <SmartCoreType, TV> > groupedRecordsByTaskType = package.PackageRecords .Where(pr => pr.PackageItemType != SmartCoreType.Unknown) .GroupBy(pr => pr.PackageItemType); foreach (IGrouping <SmartCoreType, TV> groupedRecords in groupedRecordsByTaskType) { if (groupedRecords.Key.ObjectType == null) { continue; } Type objectType = groupedRecords.Key.ObjectType; ICommonFilter filter = new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, groupedRecords.Select(wpr => wpr.PackageItemId).ToArray()); IList directiveCollection = _loader.GetObjectList(objectType, new[] { filter }, true, true, ignoreConditions: true); if (directiveCollection.Count > 0) { foreach (TV adWpr in groupedRecords) { BaseEntityObject d = directiveCollection .OfType <BaseEntityObject>() .FirstOrDefault(i => i.ItemId == adWpr.PackageItemId); if (d != null) { adWpr.PackageItem = d; } else { package.PackageRecords.RemoveById(adWpr.ItemId); } } } } // ставим флаг о том, что все элементы рабочего пакета считаны package.PackageItemsLoaded = true; }
public void LoadAllAircrafts() { if (_aircrafts.Count > 0) { _aircrafts.Clear(); } _aircrafts.AddRange(_loader.GetObjectListAll <Aircraft>(loadChild: true)); }
/// <summary> /// Возвращает все директивы базового агрегата, самолета, или задачи созданные в рамках страницы бортжурнала /// </summary> /// <returns></returns> public DirectiveCollection GetDeferredItems(BaseComponent parentBaseComponent = null, Aircraft parentAircraft = null, AircraftFlight parentFlight = null, IEnumerable <ICommonFilter> filters = null) { if (parentAircraft == null && parentBaseComponent == null && parentFlight == null && filters == null) { throw new ArgumentNullException(); } List <DbQuery> qrs; if (parentBaseComponent != null) { qrs = DeferredItemQueries.GetSelectQuery(parentBaseComponent, filters, true); } else if (parentAircraft != null) { qrs = DeferredItemQueries.GetSelectQuery(parentAircraft.ItemId, filters, true); } else if (parentFlight != null) { qrs = DeferredItemQueries.GetSelectQuery(parentFlight, filters, true); } else { qrs = BaseQueries.GetSelectQueryWithWhereAll <DeferredItem>(filters.ToArray(), true); } var directives = new DirectiveCollection(); directives.AddRange(_loader.GetObjectListAll <DeferredItem>(qrs, true).ToArray()); if (directives.Count == 0) { return(directives); } var directiveIds = directives.Select(d => d.ItemId).ToList(); var itemsRelations = _itemsRelationsDataAccess.GetRelations(directiveIds, SmartCoreType.Directive.ItemId); if (itemsRelations.Count > 0) { foreach (var directive in directives) { directive.ItemRelations.AddRange(itemsRelations.Where(i => i.FirstItemId == directive.ItemId || i.SecondItemId == directive.ItemId)); } } return(directives); }
public List <Document> GetDocuments(BaseEntityObject parent, DocumentType docType, bool onlyOperatorDocs = false) { if (parent is Aircraft) { var filters = new List <Filter> { new Filter("ParentAircraftId", parent.ItemId) }; if (docType != DocumentType.Other) { filters.Add(new Filter("DocTypeId", docType.ItemId)); } var result = _newLoader.GetObjectListAll <DocumentDTO, Document>(filters, true); var resId = result.Select(r => r.ItemId); var links = _newLoader.GetObjectListAll <ItemFileLinkDTO, ItemFileLink>(new List <Filter>() { new Filter("ParentTypeId", SmartCoreType.Document.ItemId), new Filter("ParentId", resId) }); foreach (Document doc in result) { doc.Parent = parent; } return(result.ToList()); } if (parent is Specialist || parent is Supplier) { var filters = new List <Filter> { new Filter("ParentTypeId", parent.SmartCoreObjectType.ItemId), new Filter("ParentID", parent.ItemId) }; if (docType != DocumentType.Other) { filters.Add(new Filter("DocTypeId", docType.ItemId)); } var result = _newLoader.GetObjectListAll <DocumentDTO, Document>(filters, true); foreach (Document doc in result) { doc.Parent = parent; } return(result.ToList()); } else { var filters = new List <Filter>(); if (docType != DocumentType.Other) { filters.Add(new Filter("DocTypeId", docType.ItemId)); } if (onlyOperatorDocs) { filters.AddRange(new[] { new Filter("ParentTypeId", parent.SmartCoreObjectType.ItemId), new Filter("ParentID", parent.ItemId) }); } else { var types = new[] { SmartCoreType.Aircraft.ItemId, SmartCoreType.Operator.ItemId, SmartCoreType.Employee.ItemId, SmartCoreType.Component.ItemId, SmartCoreType.WorkPackage.ItemId, SmartCoreType.ComponentDirective.ItemId, SmartCoreType.DirectiveRecord.ItemId, SmartCoreType.AircraftFlight.ItemId, SmartCoreType.FlightNumberPeriod.ItemId, SmartCoreType.FlightPlanOpsRecords.ItemId }; filters.AddRange(new[] { new Filter("ParentTypeId", types) }); } var emp = new List <Specialist>(); var directiveRecords = new List <DirectiveRecord>(); var result = _newLoader.GetObjectListAll <DocumentDTO, Document>(filters, true); var empDocumentIds = result.Where(x => x.ParentTypeId == SmartCoreType.Employee.ItemId).Select(x => x.ParentId).Distinct().ToArray(); if (empDocumentIds.Length > 0) { emp.AddRange(_newLoader.GetObjectListAll <SpecialistDTO, Specialist>(new Filter("ItemId", empDocumentIds))); } var directiveRecorIds = result.Where(x => x.ParentTypeId == SmartCoreType.DirectiveRecord.ItemId).Select(x => x.ParentId).Distinct().ToArray(); if (directiveRecorIds.Length > 0) { directiveRecords.AddRange(_newLoader.GetObjectListAll <DirectiveRecordDTO, DirectiveRecord>(new Filter("ItemId", directiveRecorIds))); } //TODO:(Важно) Зря грузим компоненты и рабочие пакеты только для того что бы взять воздушное судно(подумать в сторону того чтобы Parent присваивать компнент либо раб пакет) var compDocumentIds = result.Where(x => x.ParentTypeId == SmartCoreType.Component.ItemId).Select(x => x.ParentId).Distinct().ToArray(); var components = new List <Entities.General.Accessory.Component>(); if (compDocumentIds.Length > 0) { components = _newLoader.GetObjectListAll <ComponentDTO, Entities.General.Accessory.Component>(new List <Filter>() { new Filter("IsBaseComponent", false), new Filter("ItemId", compDocumentIds) }, true).ToList(); } var compDirectiveIds = result.Where(x => x.ParentTypeId == SmartCoreType.ComponentDirective.ItemId).Select(x => x.ParentId).ToList(); compDirectiveIds.AddRange(directiveRecords.Where(d => d.ParentType.ItemId == SmartCoreType.ComponentDirective.ItemId).Select(x => x.ParentId)); var componentDirctivess = new List <ComponentDirective>(); if (compDirectiveIds.Count > 0) { componentDirctivess = _componentCore.GetComponentDirectives(compDirectiveIds); } var directiveIds = directiveRecords.Where(d => d.ParentType.ItemId == SmartCoreType.Directive.ItemId).Select(x => x.ParentId).ToArray(); var dirctives = new List <Directive>(); //if (directiveIds.Length > 0) //dirctives = _newLoader.GetObjectListAll<DirectiveDTO, Directive>(new Filter("ItemId", directiveIds)).ToList(); if (directiveIds.Length > 0) { dirctives = _loader.GetObjectListAll <Directive>(new ICommonFilter[] { new CommonFilter <int>(Directive.ItemIdProperty, FilterType.In, directiveIds), }).ToList(); } var wptIds = result.Where(x => x.ParentTypeId == SmartCoreType.WorkPackage.ItemId).Select(x => x.ParentId).ToArray(); var wps = new List <WorkPackage>(); if (wptIds.Length > 0) { wps.AddRange(_newLoader.GetObjectListAll <WorkPackageDTO, WorkPackage>(new Filter("ItemId", wptIds))); } var resId = result.Select(r => r.ItemId); var links = _newLoader.GetObjectListAll <ItemFileLinkDTO, ItemFileLink>(new List <Filter>() { new Filter("ParentTypeId", SmartCoreType.Document.ItemId), new Filter("ParentId", resId) }); var aircraftFlights = new List <AircraftFlight>(); var aircraftFlightids = result.Where(x => x.ParentTypeId == SmartCoreType.AircraftFlight.ItemId).Select(x => x.ParentId).ToArray(); if (aircraftFlightids.Length > 0) { aircraftFlights.AddRange(_newLoader.GetObjectListAll <AircraftFlightDTO, AircraftFlight>(new Filter("ItemId", aircraftFlightids))); } var planOpsRecordIds = result.Where(x => x.ParentTypeId == SmartCoreType.FlightPlanOpsRecords.ItemId).Select(x => x.ParentId).ToArray(); var planOpsRecords = new List <FlightPlanOpsRecords>(); if (planOpsRecordIds.Length > 0) { planOpsRecords.AddRange(_newLoader.GetObjectListAll <FlightPlanOpsRecordsDTO, FlightPlanOpsRecords>(new Filter("ItemId", planOpsRecordIds))); } foreach (Document document in result) { if (document.ParentTypeId == SmartCoreType.Aircraft.ItemId) { var a = _aircraftsCore.GetAircraftById(document.ParentId); if (a != null) { document.Parent = a; } else { document.Parent = new Aircraft { IsDeleted = true, RegistrationNumber = "Can't find aircraft with id = " + document.ParentId } }; } else if (document.ParentTypeId == SmartCoreType.Employee.ItemId) { document.Specialist = emp.FirstOrDefault(e => e.ItemId == document.ParentId); } else if (document.ParentTypeId == SmartCoreType.Component.ItemId) { var comp = components.FirstOrDefault(e => e.ItemId == document.ParentId); if (comp != null) { _componentCore.SetDestinations(comp); if (comp.ParentAircraftId > 0) { document.Parent = _aircraftsCore.GetAircraftById(comp.ParentAircraftId); } else if (comp.ParentStoreId > 0) { document.Parent = _casEnvironment.Stores.GetItemById(comp.ParentStoreId); } } } else if (document.ParentTypeId == SmartCoreType.ComponentDirective.ItemId) { var cd = componentDirctivess.FirstOrDefault(c => c.ItemId == document.ParentId); if (cd != null) { try { if (cd.ParentComponent?.ParentAircraftId > 0) { document.Parent = _aircraftsCore.GetAircraftById(cd.ParentComponent.ParentAircraftId); } else if (cd.ParentComponent?.ParentStoreId > 0) { document.Parent = _casEnvironment.Stores.GetItemById(cd.ParentComponent.ParentStoreId); } } catch (Exception e) { Console.WriteLine(e); throw; } } } else if (document.ParentTypeId == SmartCoreType.WorkPackage.ItemId) { var wp = wps.FirstOrDefault(w => w.ItemId == document.ParentId); if (wp != null) { document.Parent = _aircraftsCore.GetAircraftById(wp.ParentId); } } else if (document.ParentTypeId == SmartCoreType.DirectiveRecord.ItemId) { var directive = directiveRecords.FirstOrDefault(d => d.ItemId == document.ParentId); if (directive != null) { if (directive.ParentType == SmartCoreType.ComponentDirective) { var cd = componentDirctivess.FirstOrDefault(e => e.ItemId == directive.ParentId); if (cd != null) { if (cd.ParentComponent?.ParentAircraftId > 0) { document.Parent = _aircraftsCore.GetAircraftById(cd.ParentComponent.ParentAircraftId); } else if (cd.ParentComponent?.ParentStoreId > 0) { document.Parent = _casEnvironment.Stores.GetItemById(cd.ParentComponent.ParentStoreId); } } } else if (directive.ParentType == SmartCoreType.Directive) { var d = dirctives.FirstOrDefault(e => e.ItemId == directive.ParentId); if (d != null) { if (d.ParentBaseComponent?.ParentAircraftId > 0) { document.Parent = _aircraftsCore.GetAircraftById(d.ParentBaseComponent.ParentAircraftId); } } } } } else if (document.ParentTypeId == SmartCoreType.AircraftFlight.ItemId) { var flight = aircraftFlights.FirstOrDefault(d => d.ItemId == document.ParentId); if (flight != null) { document.Parent = _aircraftsCore.GetAircraftById(flight.AircraftId); } } else if (document.ParentTypeId == SmartCoreType.FlightPlanOpsRecords.ItemId) { document.Parent = planOpsRecords.FirstOrDefault(d => d.ItemId == document.ParentId); } else { var a = _casEnvironment.Operators.GetItemById(document.ParentId); if (a != null) { document.Parent = a; } else { document.Parent = new Operator { IsDeleted = true, Name = "Can't find operator with id = " + document.ParentId } }; } document.Files = new CommonCollection <ItemFileLink>(links.Where(i => i.ParentId == document.ItemId)); } return(result.ToList()); } }
public List <Product> GetProducts() { return(_loader.GetObjectListAll <Product>(loadChild: true, ignoreConditions: true)); }
///// <param name="status">Фильтр статуса рабочего пакета. (По умолчанию = WorkPackageStatus.All)</param> ///// <param name="loadWorkPackageItems">Флаг загрузки элементов рабочих пакетов</param> ///// <param name="includedTasks">Задачи, которые должны содержать пакеты (при передаче пустои коллекции запрос вернет 0 рабочих пакетов)</param> /// <returns></returns> public List <Discrepancy> GetDiscrepancies(Aircraft aircraft = null, DiscFilterType filterType = DiscFilterType.All, DateTime?from = null, DateTime?to = null) //TODO: Переделать на int? aircraftId = null { var resultList = new List <Discrepancy>(); var preResultList = new List <Discrepancy>(); var filters = new List <ICommonFilter>(); if (filterType == DiscFilterType.Defect) { filters.Add(new CommonFilter <bool>(Discrepancy.IsReliabilityProperty, true)); } else if (filterType == DiscFilterType.Occurrence) { filters.Add(new CommonFilter <bool>(Discrepancy.IsOccurrenceProperty, true)); } else if (from.HasValue && to.HasValue) { var flights = _loader.GetObjectList <AircraftFlight>(new ICommonFilter[] { new CommonFilter <DateTime>(AircraftFlight.FlightDateProperty, FilterType.GratherOrEqual, new [] { from.Value.Date }), new CommonFilter <DateTime>(AircraftFlight.FlightDateProperty, FilterType.LessOrEqual, new [] { to.Value.Date }), }); if (flights.Count > 0) { filters.Add(new CommonFilter <int>(Discrepancy.FlightIdProperty, FilterType.In, flights.Select(i => i.ItemId).ToArray())); } } if (aircraft != null) { preResultList.AddRange(_loader.GetObjectList <Discrepancy>(new[] { new CommonFilter <string>(Discrepancy.FlightIdProperty, FilterType.In, new [] { $"(Select ItemId from AircraftFlights where AircraftId = {aircraft.ItemId} and IsDeleted = 0)" }), })); //Строка запроса, выдающая идентификаторы родительских задач КИТов //Фильтр по ключевому полю таблицы обозначающий //что значения ключевого поля таблицы должны быть //среди идентификаторов родительских задач КИТов } else { if (filters.Count > 0) { preResultList.AddRange(_loader.GetObjectListAll <Discrepancy>(filters.ToArray(), loadChild: true)); } } #region //заполнение Discrepancies CorrectiveAction в Discrepancies нового полета// int[] deferredsIds = preResultList .Where(i => i.DirectiveId > 0) .Select(i => i.DirectiveId) .ToArray(); var deffereds = new DirectiveCollection(); if (deferredsIds.Length > 0) { deffereds = _directiveCore.GetDeferredItems(filters: new ICommonFilter[] { new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, deferredsIds) }); } var parentFlights = new List <AircraftFlight>(); var flightIds = preResultList.Select(i => i.FlightId).Distinct().ToArray(); if (aircraft != null) { foreach (var id in flightIds) { var fl = _aircraftFlightCore.GetAircraftFlightById(aircraft.ItemId, id); if (fl != null) { parentFlights.Add(fl); resultList.Add(preResultList.FirstOrDefault(i => i.FlightId == id)); } } } else { if (flightIds.Length > 0) { var flights = _newLoader.GetObjectList <AircraftFlightDTO, AircraftFlight>(new Filter("ItemId", flightIds)); foreach (var id in flightIds) { var fl = flights.FirstOrDefault(i => i.ItemId == id); if (fl != null) { parentFlights.Add(fl); resultList.Add(preResultList.FirstOrDefault(i => i.FlightId == id)); } } } } var atlbs = new List <ATLB>(); var atlbIds = parentFlights.Select(i => i.ATLBId).Distinct().ToArray(); if (atlbIds.Length > 0) { //atlbs.AddRange(_loader.GetObjectList<ATLB>(new CommonFilter<int>(BaseEntityObject.ItemIdProperty, FilterType.In, atlbIds))); atlbs.AddRange(_newLoader.GetObjectList <ATLBDTO, ATLB>(new Filter("ItemId", atlbIds))); } var correctiveActions = new List <CorrectiveAction>(); var discrepancyIds = resultList.Select(i => i.ItemId).Distinct().ToArray(); if (discrepancyIds.Length > 0) { //correctiveActions.AddRange(_loader.GetObjectList<CorrectiveAction>(new CommonFilter<int>(CorrectiveAction.DiscrepancyIdProperty, FilterType.In, discrepancyIds), true)); correctiveActions.AddRange(_newLoader.GetObjectList <CorrectiveActionDTO, CorrectiveAction>(new Filter("DiscrepancyID", discrepancyIds), true)); } var cetificates = new List <CertificateOfReleaseToService>(); var crsIds = correctiveActions.Select(i => i.CRSID).Distinct().ToArray(); if (crsIds.Length > 0) { cetificates.AddRange(_loader.GetObjectList <CertificateOfReleaseToService>(new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, crsIds), true)); } //cetificates.AddRange(_newLoader.GetObjectList<CertificateOfReleaseToServiceDTO, CertificateOfReleaseToService>(new Filter("ItemId", crsIds), true)); foreach (var t in resultList) { t.ParentFlight = parentFlights.FirstOrDefault(i => i.ItemId == t.FlightId); if (t.ParentFlight != null) { t.ParentFlight.ParentATLB = atlbs.FirstOrDefault(i => i.ItemId == t.ParentFlight.ATLBId); } t.DeferredItem = deffereds.GetDirectiveById(t.DirectiveId) as DeferredItem; t.CorrectiveActionCollection = new CorrectiveActionCollection(); t.CorrectiveActionCollection.AddRange(correctiveActions.Where(i => t.ItemId == i.DiscrepancyId)); t.CorrectiveAction.CertificateOfReleaseToService = cetificates.FirstOrDefault(i => i.ItemId == t.CorrectiveAction.CRSID); } #endregion return(resultList.Where(i => i.ParentFlight != null && i.ParentFlight.ParentATLB != null).ToList()); }
public List <AbstractAccessory> GetAllAircraftKits(int aircraftId, int aircraftModelId) { var resultKits = new List <AbstractAccessory>(); #region Поиск Директив летной годности с КИТами //Строка запроса, выдающая идентификаторы родительских задач КИТов var accessoryParentId = BaseQueries.GetSelectQueryColumnOnly <AccessoryRequired> (AccessoryRequired.ParentIdProperty, new ICommonFilter[] { new CommonFilter <int>(AccessoryRequired.ParentTypeIdProperty, SmartCoreType.Directive.ItemId) } ); //Фильтр по ключевому полю таблицы обозначающий //что значения ключевого поля таблицы должны быть //среди идентификаторов родительских задач КИТов ICommonFilter idFilter = new CommonFilter <string>(BaseEntityObject.ItemIdProperty, FilterType.In, new[] { accessoryParentId }); //создаются запросы на выборку задач по компонентам с заданного ВС //дополнительно фильтрую ключевое поле. значение ключевого поля //задач по компонентам ВС должно быть среди идентификатор родительских задач КИТов var qrs = DirectiveQueries.GetAircraftDirectivesSelectQuery(aircraftId, DirectiveType.All, new[] { idFilter }, true); var directives = _loader.GetObjectListAll <Directive>(qrs, true); //связь КИТов с родительскими деталями foreach (var directive in directives) { resultKits.AddRange(directive.Kits.ToArray()); } #endregion #region Поиск Директив деталей с КИТами //Строка запроса, выдающая идентификаторы родительских задач КИТов accessoryParentId = BaseQueries.GetSelectQueryColumnOnly <AccessoryRequired> (AccessoryRequired.ParentIdProperty, new ICommonFilter[] { new CommonFilter <int>(AccessoryRequired.ParentTypeIdProperty, SmartCoreType.ComponentDirective.ItemId) } ); //Фильтр по ключевому полю таблицы обозначающий //что значения ключевого поля таблицы должны быть //среди идентификаторов родительских задач КИТов idFilter = new CommonFilter <string>(BaseEntityObject.ItemIdProperty, FilterType.In, new[] { accessoryParentId }); //создаются запросы на выборку задач по компонентам с заданного ВС //дополнительно фильтрую ключевое поле. значение ключевого поля //задач по компонентам ВС должно быть среди идентификатор родительских задач КИТов qrs = ComponentDirectiveQueries.GetAircraftDirectivesSelectQuery(aircraftId, new[] { idFilter }, true); var componentDirectives = _loader.GetObjectListAll <ComponentDirective>(qrs, true); //связь КИТов с родительскими деталями foreach (var dd in componentDirectives) { dd.ParentComponent = _componentCore.GetComponentById(dd.ComponentId); resultKits.AddRange(dd.Kits.ToArray()); } #endregion #region Поиск КИТ-ов Maintenance чеков //Строка запроса, выдающая идентификаторы родительских задач КИТов accessoryParentId = BaseQueries.GetSelectQueryColumnOnly <AccessoryRequired> (AccessoryRequired.ParentIdProperty, new ICommonFilter[] { new CommonFilter <int>(AccessoryRequired.ParentTypeIdProperty, SmartCoreType.MaintenanceCheck.ItemId) } ); //Фильтр по ключевому полю таблицы обозначающий //что значения ключевого поля таблицы должны быть //среди идентификаторов родительских задач КИТов idFilter = new CommonFilter <string>(BaseEntityObject.ItemIdProperty, FilterType.In, new[] { accessoryParentId }); //создаются запросы на выборку чеков с заданного ВС //дополнительно фильтрую ключевое поле. значение ключевого поля //чека ВС должно быть среди идентификатор родительских задач КИТов var checks = _loader.GetObjectListAll <MaintenanceCheck>(new[] { new CommonFilter <int>(MaintenanceCheck.ParentAircraftIdProperty, aircraftId), idFilter }, true); //связь КИТов с родительскими деталями foreach (var dd in checks) { resultKits.AddRange(dd.Kits.ToArray()); } #endregion #region Поиск КИТ-ов NonRoutine Job-ов var jobDTOs = _nonRoutineJobDataAccess.GetNonRoutineJobDTOsWithKits(); //связь КИТов с родительскими деталями foreach (var jobDTO in jobDTOs) { var nonRoutineJob = NonRoutineJobHelper.Convert(jobDTO, _casEnvironment); resultKits.AddRange(nonRoutineJob.Kits.ToArray()); } #endregion #region Поиск КИТ-ов Базовых деталей //TODO:(Evgenii Babak) выделить в отдельный класс и не использовать рукописные запросы //TODO:(Evgenii Babak) нужно реализовать TablePrefix в методе BaseComponentQueries.GetSelectQueryPrimaryColumnOnly var bdFilter = $"Select ComponentsItemId from ({BaseQueries.GetSelectQueryWithWhere<BaseComponent>() + $" and (Select top 1 DestinationObjectId from dbo.TransferRecords Where \r\n \t\t\t\t\tParentType = {SmartCoreType.BaseComponent.ItemId} \r\n \t\t\t\t\tand ParentId = dbo.Components.ItemId \r\n \t\t\t\t\tand IsDeleted = 0\r\n \t\t\t\t\torder by dbo.TransferRecords.TransferDate Desc) = {aircraftId}"}) directiveSelect "; var preResult = _loader.GetObjectListAll <AccessoryRequired>(new ICommonFilter[] { new CommonFilter <int>(AccessoryRequired.ParentTypeIdProperty, SmartCoreType.BaseComponent.ItemId), new CommonFilter <string>(AccessoryRequired.ParentIdProperty, FilterType.In, new [] { bdFilter }) }); // поиск поставщиков и связей с ними var kitsIds = preResult.Select(k => k.ItemId).ToArray(); var ksrs = new List <KitSuppliersRelation>(); if (kitsIds.Length > 0) { _loader.GetObjectListAll <KitSuppliersRelation>(new CommonFilter <int>(KitSuppliersRelation.KitIdProperty, FilterType.In, kitsIds)); } var kitSupplierIds = ksrs.Select(k => k.SupplierId).ToArray(); var suppliers = new List <Supplier>(); if (kitSupplierIds.Length > 0) { suppliers = _loader.GetObjectListAll <Supplier>(new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, kitSupplierIds)); } foreach (var kit in preResult) { var supls = (from sup in suppliers from k in ksrs where k.KitId == kit.ItemId && sup.ItemId == k.SupplierId select sup).ToList(); kit.Suppliers.AddRange(supls.ToArray()); } //поиск чеков, который пренадлежат КИТы var kitParentIds = preResult.Select(k => k.ParentId).ToArray(); var baseComponents = new List <BaseComponent>(); if (kitParentIds.Length > 0) { baseComponents = _loader.GetObjectListAll <BaseComponent>(new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, kitParentIds)); } //связь КИТов с родительскими деталями foreach (var baseComponent in baseComponents) { baseComponent.Kits.Clear(); baseComponent.Kits.AddRange(preResult.Where(k => k.ParentId == baseComponent.ItemId)); foreach (var kit in baseComponent.Kits) { kit.ParentObject = baseComponent; } } resultKits.AddRange(preResult.ToArray()); #endregion #region поиск КИТ-ов деталей var componentQuery = $"(Select ComponentsItemId from ({ComponentQueries.GetSelectQuery(aircraftId)}) directiveSelect )"; preResult = _loader.GetObjectListAll <AccessoryRequired>(new ICommonFilter[] { new CommonFilter <int>(AccessoryRequired.ParentTypeIdProperty, SmartCoreType.Component.ItemId), new CommonFilter <string>(AccessoryRequired.ParentIdProperty, FilterType.In, new [] { componentQuery }), }); //поиск деталей, который пренадлежат КИТы kitParentIds = preResult.Select(k => k.ParentId).ToArray(); var components = new List <BaseComponent>(); if (kitParentIds.Length > 0) { components = _loader.GetObjectListAll <BaseComponent>(new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, kitParentIds)); } //связь КИТов с родительскими деталями foreach (var baseComponent in components) { baseComponent.Kits.Clear(); baseComponent.Kits.AddRange(preResult.Where(k => k.ParentId == baseComponent.ItemId)); foreach (var kit in baseComponent.Kits) { kit.ParentObject = baseComponent; } } resultKits.AddRange(preResult.ToArray()); #endregion #region Поиск MPD с КИТами //Строка запроса, выдающая идентификаторы родительских задач КИТов accessoryParentId = BaseQueries.GetSelectQueryColumnOnly <AccessoryRequired> (AccessoryRequired.ParentIdProperty, new ICommonFilter[] { new CommonFilter <int>(AccessoryRequired.ParentTypeIdProperty, SmartCoreType.MaintenanceDirective.ItemId) } ); //Фильтр по ключевому полю таблицы обозначающий //что значения ключевого поля таблицы должны быть //среди идентификаторов родительских задач КИТов idFilter = new CommonFilter <string>(BaseEntityObject.ItemIdProperty, FilterType.In, new[] { accessoryParentId }); //создаются запросы на выборку задач с заданного ВС //дополнительно фильтруя ключевое поле. значение ключевого поля //задач по компонентам ВС должно быть среди идентификатор родительских задач КИТов qrs = MaintenanceDirectiveQueries.GetAircraftDirectivesSelectQuery(aircraftId, new[] { idFilter }, true); var maintenanceDirectives = _loader.GetObjectListAll <MaintenanceDirective>(qrs, true); //связь КИТов с родительскими деталями foreach (var mpd in maintenanceDirectives) { resultKits.AddRange(mpd.Kits.ToArray()); } #endregion #region Поиск Нерутинных КИТов //добавление не рутинных кит-ов preResult = _loader.GetObjectListAll <AccessoryRequired>(new CommonFilter <int>(AccessoryRequired.AircraftModelIdProperty, aircraftModelId)); // поиск поставщиков и связей с ними kitsIds = preResult.Select(k => k.ItemId).ToArray(); if (kitsIds.Length > 0) { ksrs = _loader.GetObjectListAll <KitSuppliersRelation>(new CommonFilter <int>(KitSuppliersRelation.KitIdProperty, FilterType.In, kitsIds)); } kitSupplierIds = ksrs.Select(k => k.SupplierId).ToArray(); if (kitSupplierIds.Length > 0) { suppliers = _loader.GetObjectListAll <Supplier>(new CommonFilter <int>(BaseEntityObject.ItemIdProperty, FilterType.In, kitSupplierIds)); } foreach (var kit in preResult) { var supls = (from sup in suppliers from k in ksrs where k.KitId == kit.ItemId && sup.ItemId == k.SupplierId select sup).ToList(); kit.Suppliers.AddRange(supls.ToArray()); } resultKits.AddRange(preResult.ToArray()); #endregion return(resultKits); }