Ejemplo n.º 1
0
        /// <summary>
        /// Добавить выполнение работы к задаче
        /// </summary>
        /// <param name="performance"></param>
        /// <param name="saveAttachedFile"></param>
        public void Save(AbstractPerformanceRecord performance, bool saveAttachedFile = true)
        {
            if (performance == null)
            {
                return;
            }

            var type = AuditOperation.Created;

            if (performance.ItemId > 0)
            {
                type = AuditOperation.Changed;
            }

            performance.CorrectorId = _casEnvironment.IdentityUser.ItemId;

            _casEnvironment.Keeper.Save(performance, saveAttachedFile);
            _auditRepository.WriteAsync(performance, type, _casEnvironment.IdentityUser);

            if (performance.Parent.PerformanceRecords.GetItemById(performance.ItemId) == null)
            {
                performance.Parent.PerformanceRecords.Add(performance);
            }

            if (performance.Parent is MaintenanceDirective)
            {
                DirectiveRecord ddr = _casEnvironment.NewLoader.GetObjectListAll <DirectiveRecordDTO, DirectiveRecord>(new Filter("MaintenanceDirectiveRecordId", performance.ItemId)).FirstOrDefault();

                if (ddr != null)
                {
                    ComponentDirective dd = _casEnvironment.NewLoader.GetObject <ComponentDirectiveDTO, ComponentDirective>(new Filter("ItemId", ddr.ParentId));
                    if (dd != null)
                    {
                        BaseComponent bd = _componentCore.GetBaseComponentById(dd.ComponentId);
                        if (bd != null)
                        {
                            ddr.OnLifelength =
                                _casEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(bd, performance.RecordDate);
                        }
                        else
                        {
                            General.Accessory.Component d = _componentCore.GetComponentById(dd.ComponentId);
                            if (d != null)
                            {
                                ddr.OnLifelength = _casEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(d, performance.RecordDate);
                            }
                        }
                    }
                    ddr.RecordDate = performance.RecordDate;
                    _casEnvironment.NewKeeper.Save(ddr, saveAttachedFile);
                }
            }
            else if (performance.Parent is ComponentDirective)
            {
                DirectiveRecord ddr = performance as DirectiveRecord;
                if (ddr != null)
                {
                    DirectiveRecord mpdRecord = _casEnvironment.NewLoader.GetObject <DirectiveRecordDTO, DirectiveRecord>(new Filter("ItemId", ddr.MaintenanceDirectiveRecordId));
                    if (mpdRecord != null)
                    {
                        MaintenanceDirective md = _maintenanceCore.GetMaintenanceDirective(mpdRecord.ParentId);
                        if (md != null)
                        {
                            mpdRecord.OnLifelength = _casEnvironment.Calculator.GetFlightLifelengthOnStartOfDay(md.ParentBaseComponent, ddr.RecordDate);
                        }
                        mpdRecord.RecordDate = ddr.RecordDate;
                        _casEnvironment.NewKeeper.Save(mpdRecord, saveAttachedFile);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <TransferRecord> GetTransferRecord(int aircraftId)
        {
            var records = _newLoader.GetObjectListAll <TransferRecordDTO, TransferRecord>(new List <Filter>()
            {
                new Filter("FromAircraftID", aircraftId),
                new Filter("ReplaceComponentId", FilterType.Grather, 0),
            });

            foreach (var transferRecord in records)
            {
                transferRecord.ReplaceComponent =
                    _componentCore.GetBaseComponentById(transferRecord.ReplaceComponentId) ??
                    _componentCore.GetComponentById(transferRecord.ReplaceComponentId);

                foreach (var record in transferRecord.ReplaceComponent.TransferRecords)
                {
                    #region Откуда перемещен

                    if (record.FromAircraftId > 0)
                    {
                        var a = _aircraftsCore.GetAircraftById(record.FromAircraftId) ??
                                new Aircraft
                        {
                            ItemId             = record.FromAircraftId,
                            IsDeleted          = true,
                            RegistrationNumber = "Can't Find Aircraft with id = " + record.FromAircraftId
                        };
                        record.FromAircraft = a;
                    }


                    if (record.FromBaseComponentId > 0)
                    {
                        var bd = _componentCore.GetBaseComponentById(record.FromBaseComponentId) ??
                                 new BaseComponent
                        {
                            ItemId       = record.FromBaseComponentId,
                            IsDeleted    = true,
                            Description  = "Can't Find Base Component with id = " + record.FromBaseComponentId,
                            PartNumber   = "Unknown",
                            SerialNumber = "Unknown"
                        };

                        var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                        if (a != null)
                        {
                            bd.Aircraft = a.ToString();
                        }

                        record.FromBaseComponent = bd;
                    }

                    if (record.FromStoreId > 0)
                    {
                        var store = _storeCore.GetStoreById(record.FromStoreId) ??
                                    new Store
                        {
                            ItemId    = record.FromStoreId,
                            IsDeleted = true,
                            Name      = "Can't Find Store with id = " + record.FromStoreId,
                        };

                        record.FromStore = store;
                    }

                    #endregion

                    #region Куда перемещен
                    if (record.DestinationObjectType == SmartCoreType.Store)
                    {
                        var store = _storeCore.GetStoreById(record.DestinationObjectId) ??
                                    new Store
                        {
                            ItemId    = record.DestinationObjectId,
                            IsDeleted = true,
                            Name      = "Can't Find Store with id = " + record.DestinationObjectId,
                        };

                        record.DestinationObject = store;
                    }

                    if (record.DestinationObjectType == SmartCoreType.BaseComponent)
                    {
                        var bd = _componentCore.GetBaseComponentById(record.DestinationObjectId) ??
                                 new BaseComponent
                        {
                            ItemId       = record.DestinationObjectId,
                            IsDeleted    = true,
                            Description  = "Can't Find Base Component with id = " + record.DestinationObjectId,
                            PartNumber   = "Unknown",
                            SerialNumber = "Unknown"
                        };

                        var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                        if (a != null)
                        {
                            bd.Aircraft = a.ToString();
                        }

                        record.DestinationObject = bd;
                    }
                    if (record.DestinationObjectType == SmartCoreType.Aircraft)
                    {
                        var a = _aircraftsCore.GetAircraftById(record.DestinationObjectId) ??
                                new Aircraft
                        {
                            ItemId             = record.DestinationObjectId,
                            IsDeleted          = true,
                            RegistrationNumber = "Can't Find Aircraft with id = " + record.DestinationObjectId
                        };
                        record.DestinationObject = a;
                    }
                    #endregion
                }

                #region  одительский объект

                if (transferRecord.ParentType == SmartCoreType.BaseComponent)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.ParentId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.ParentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    transferRecord.ParentComponent = bd;
                }
                else if (transferRecord.ParentType == SmartCoreType.Component)
                {
                    var d = _componentCore.GetComponentById(transferRecord.ParentId) ??
                            new Entities.General.Accessory.Component
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Component with id = " + transferRecord.ParentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };
                    transferRecord.ParentComponent = d;
                }
                else
                {
                    var d = new Entities.General.Accessory.Component
                    {
                        ItemId       = transferRecord.ParentId,
                        IsDeleted    = true,
                        Description  = "Can't Find object with type = " + transferRecord.ParentType,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };
                    transferRecord.ParentComponent = d;
                }

                #endregion

                #region Откуда перемещен

                if (transferRecord.FromAircraftId > 0)
                {
                    var a = _aircraftsCore.GetAircraftById(transferRecord.FromAircraftId) ??
                            new Aircraft
                    {
                        ItemId             = transferRecord.FromAircraftId,
                        IsDeleted          = true,
                        RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.FromAircraftId
                    };
                    transferRecord.FromAircraft = a;
                }

                if (transferRecord.FromBaseComponentId > 0)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.FromBaseComponentId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.FromBaseComponentId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.FromBaseComponentId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                    if (a != null)
                    {
                        bd.Aircraft = a.ToString();
                    }

                    transferRecord.FromBaseComponent = bd;
                }

                if (transferRecord.FromStoreId > 0)
                {
                    var store = _storeCore.GetStoreById(transferRecord.FromStoreId) ??
                                new Store
                    {
                        ItemId    = transferRecord.FromStoreId,
                        IsDeleted = true,
                        Name      = "Can't Find Store with id = " + transferRecord.FromStoreId,
                    };

                    transferRecord.FromStore = store;
                }

                #endregion

                #region Куда перемещен
                if (transferRecord.DestinationObjectType == SmartCoreType.Store)
                {
                    var store = _storeCore.GetStoreById(transferRecord.DestinationObjectId) ??
                                new Store
                    {
                        ItemId    = transferRecord.DestinationObjectId,
                        IsDeleted = true,
                        Name      = "Can't Find Store with id = " + transferRecord.DestinationObjectId,
                    };

                    transferRecord.DestinationObject = store;
                }

                if (transferRecord.DestinationObjectType == SmartCoreType.BaseComponent)
                {
                    var bd = _componentCore.GetBaseComponentById(transferRecord.DestinationObjectId) ??
                             new BaseComponent
                    {
                        ItemId       = transferRecord.DestinationObjectId,
                        IsDeleted    = true,
                        Description  = "Can't Find Base Component with id = " + transferRecord.DestinationObjectId,
                        PartNumber   = "Unknown",
                        SerialNumber = "Unknown"
                    };

                    var a = _aircraftsCore.GetAircraftById(bd.ParentAircraftId);
                    if (a != null)
                    {
                        bd.Aircraft = a.ToString();
                    }

                    transferRecord.DestinationObject = bd;
                }
                if (transferRecord.DestinationObjectType == SmartCoreType.Aircraft)
                {
                    var a = _aircraftsCore.GetAircraftById(transferRecord.DestinationObjectId) ??
                            new Aircraft
                    {
                        ItemId             = transferRecord.DestinationObjectId,
                        IsDeleted          = true,
                        RegistrationNumber = "Can't Find Aircraft with id = " + transferRecord.DestinationObjectId
                    };
                    transferRecord.DestinationObject = a;
                }
                #endregion
            }

            return(records);
        }
Ejemplo n.º 3
0
        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);
        }