예제 #1
0
        /// <summary>
        ///  Инциденты – вкладка с перечнем открытых инцидентов на составе, с возможностью перехода в форму инцидента при клике по нему. Информация будет выводится в табличном виде, со следующим набором полей:
        /// </summary>
        private static async Task <ReportResponse> GetNotClosedTrainTaskTable(ReportRequest input, int planedRouteTrainId, ILogger logger)
        {
            var sqlRTrains            = new TrainRepository(logger);
            var sqlRTask              = new TaskRepository(logger);
            var sqlRPlanedRouteTrains = new PlanedRouteTrainsRepository(logger);
            var sqlRRoute             = new RoutesRepository(logger);
            var sqlRInspections       = new InspectionRepository(logger);
            var sqlRTaskAttributes    = new TrainTaskAttributesRepository(logger);
            var sqlREquipmentModel    = new EquipmentModelsRepository(logger);
            var sqlREquipment         = new EquipmentRepository(logger);
            var sqlRCarriage          = new CarriageRepository(logger);
            var sqlRTaskStatus        = new TaskStatusRepository(logger);

            var result = new ReportResponse {
                Rows = new List <Row>()
            };

            result.Columns = new List <Column>
            {
                new Column("col0", "Номер", "number"),
                new Column("col1", "Статус", "string"),
                new Column("col2", "Тип", "string"),
                new Column("col3", "Вагон", "string"),
                new Column("col4", "Оборудование", "string"),
                new Column("col5", "Дата", "date"),
            };

            var planedRouteTrain = await sqlRPlanedRouteTrains.ById(planedRouteTrainId);

            //var route = await sqlRRoute.ById(planedRouteTrain.RouteId);

            var trainTasks = await sqlRTask.ByTrainId(planedRouteTrain.TrainId);

            var notClosedTasks = new List <TrainTask>();

            foreach (var trainTask in trainTasks)
            {
                var status = await sqlRTaskStatus.ByTaskId(trainTask.Id);

                if (status.Length == 0)
                {
                    continue;
                }
                if (status.Last().Status != TaskStatus.Closed)
                {
                    notClosedTasks.Add(trainTask);
                }
            }

            foreach (var notClosedTask in notClosedTasks)
            {
                var taskAtributes = await sqlRTaskAttributes.ByTaskId(notClosedTask.Id);

                var lastStatus = await sqlRTaskStatus.ByTaskId(notClosedTask.Id);

                var carriage = await sqlRCarriage.GetById(notClosedTask.CarriageId);

                var equipmentModel = await sqlREquipmentModel.ById(notClosedTask.EquipmentModelId);

                var equpment = await sqlREquipment.ById(equipmentModel.EquipmentId);


                foreach (var taskAtribute in taskAtributes)
                {
                    var row = new Row
                    {
                        Id       = new RowId(notClosedTask.Id, 1),
                        HasItems = false.ToString(),
                        ParentId = null,
                        //Номер
                        Col0 = $"И{notClosedTask.Id}",
                        //Статус
                        Col1 = GetStringTaskStatus(lastStatus.Last().Status),
                        //Тип
                        Col2 = GetStringTaskType(notClosedTask.TaskType),
                        //Вагон
                        Col3 = $"{carriage.Number} - {carriage.Serial}",
                        //Оборудование
                        Col4 = equpment.Name,
                        //Дата
                        Col5 = notClosedTask.CreateDate.ToStringDateTime(),
                    };

                    result.Rows.Add(row);
                }
            }
            return(result);
        }