Exemple #1
0
        private static async Task <List <Row> > GetTaskData(List <TrainTask> tasks, ILogger logger)
        {
            var sqlRUsers               = new UserRepository(logger);
            var sqlRTaskStatus          = new TaskStatusRepository(logger);
            var sqlRTaskExecutors       = new ExecutorRepository(logger);
            var sqlRTaskComment         = new CommentRepository(logger);
            var sqlRCarriages           = new CarriageRepository(logger);
            var sqlREquipmentModel      = new EquipmentModelsRepository(logger);
            var sqlREquipment           = new EquipmentRepository(logger);
            var sqlRTrains              = new TrainRepository(logger);
            var sqlRTrainTaskAttributes = new TrainTaskAttributesRepository(logger);
            var sqlRFault               = new FaultsRepository(logger);

            var rows = new List <Row>();

            foreach (var task in tasks)
            {
                var currentTaskStatus = (await sqlRTaskStatus.ByTaskId(task.Id)).Last();
                var carriage          = await sqlRCarriages.ById(task.CarriageId);

                var user = GetUserById(sqlRUsers, task.UserId);

                var taskExecutor   = (await sqlRTaskExecutors.GetByTaskId(task.Id)).Last();
                var equipmentModel = await sqlREquipmentModel.ById(task.EquipmentModelId);

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

                var taskAttributes = await sqlRTrainTaskAttributes.ByTaskId(task.Id);

                var lastComment = (await sqlRTaskComment.GetByTaskId(task.Id)).LastOrDefault();
                var fault       = new Fault();
                if (taskAttributes.Count == 1 && taskAttributes.First().FaultId.HasValue)
                {
                    fault = await sqlRFault.ById(taskAttributes.First().FaultId.Value);
                }


                var updateData = GetTaskLastUpdate(lastComment, taskExecutor, currentTaskStatus);

                var toadd = new Row
                {
                    Id       = new RowId(task.Id, 2),
                    HasItems = false.ToString(),
                    ParentId = null,
                    //Ид
                    Col0 = "И" + task.Id,
                    //Статус
                    Col1 = GetStringTaskStatus(currentTaskStatus.Status),
                    //Тип
                    Col2 = GetStringTaskType(task.TaskType),
                    //Состав
                    Col3 = GetTrainById(sqlRTrains, carriage.TrainId).Name,
                    //Инициатор
                    Col4 = user.Name,
                    //Исполнитель
                    Col5 = GetStringBrigadeType(taskExecutor.BrigadeType),
                    //Дата
                    Col6 = task.CreateDate.ToStringDateTime(),
                    ////Вагон
                    Col7 = carriage.Number.ToString(),
                    //Оборудование
                    Col8 = equipment.Name,
                    ////Типовая Неисправность
                    Col9 = fault?.Name,
                    //Обновлено
                    Col10 = updateData?.Date.ToStringDateTime(),
                    //Обновил
                    Col11 = updateData?.User.Name
                };
                if (taskAttributes.Count > 1)
                {
                    toadd.HasItems = true.ToString();
                }

                rows.Add(toadd);
            }

            return(rows);
        }
Exemple #2
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);
        }
Exemple #3
0
        public async Task <ReportResponse> GetTaskAndInspections(ReportRequest input)
        {
            var sqlRTrainTaskAttributes = new TrainTaskAttributesRepository(_logger);

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

            if (input.ReportId == null)
            {
                throw new ValidationException("reportId null");
            }

            //Отчет всех тасок
            if (int.Parse(input.ReportId) == (int)ReportsTableEnum.Tasks)
            {
                //атрибуты на 2-й уровень
                if (input.ParentId?.Type == (int)EventTableEnum.TrainTask)
                {
                    CreateTaskAttributesChildTableColumbs(result);
                    var trainTaskAttributesByTaskId = await sqlRTrainTaskAttributes.ByTaskId(input.ParentId.Id);

                    var taskAttributesData =
                        GetTaskAttributesData(trainTaskAttributesByTaskId, input.ParentId, _logger).Result;
                    result.Rows.AddRange(taskAttributesData);

                    return(result);
                }

                //Все таски
                CreateMainTableColumbs(result);

                var taskReportData = await FilterPaginate(input, _logger, isFillInspection : false);

                var reportTasks = new List <TrainTask>();
                foreach (var task in taskReportData.TrainTask)
                {
                    var attributes = await sqlRTrainTaskAttributes.ByTaskId(task.Id);

                    if (attributes.Any())
                    {
                        reportTasks.Add(task);
                    }
                }

                result.Rows.AddRange(GetTaskData(reportTasks, _logger).Result);

                result.Total = taskReportData.Total.ToString();
                return(result);
            }


            switch (input.ParentId?.Type)
            {
            //Судя по всему задачи без инспекций для списка с инспекциями
            case (int)EventTableEnum.Inspection:
                CreateTaskAttributesChildTableColumbs(result);

                var taskWihoutInspForInspList = (await FilterPaginate(input, _logger)).TrainTask;
                var taskWihoutIns             = new List <TrainTask>();
                foreach (var task in taskWihoutInspForInspList)
                {
                    var attributes = await sqlRTrainTaskAttributes.ByTaskId(task.Id);

                    var attributesWithOutInspections = attributes.Where(x => x.InspectionId == input.ParentId.Id).ToList();
                    if (attributesWithOutInspections.Any())
                    {
                        taskWihoutIns.Add(task);
                    }
                }
                result.Rows.AddRange(GetTaskDataChildInspection(taskWihoutIns, input.ParentId, _logger).Result);
                return(result);

            //Атрибуты для задачи
            case (int)EventTableEnum.TrainTask:
                CreateTaskAttributesChildTableColumbs(result);
                var traintTaskAttributesByTaskId = await sqlRTrainTaskAttributes.ByTaskId(input.ParentId.Id);

                var taskAttributesData =
                    GetTaskAttributesData(traintTaskAttributesByTaskId, input.ParentId, _logger).Result;
                result.Rows.AddRange(taskAttributesData);
                return(result);
            }

            //Дефолтный отчет вроде как с инспекциями
            CreateMainTableColumbs(result);
            var afterFilterPaginate = await FilterPaginate(input, _logger);

            var inspections = afterFilterPaginate.Inspections;
            var tasks       = afterFilterPaginate.TrainTask;

            //Инспекции
            result.Rows.AddRange(GetInspectionsData(inspections, _logger));

            var tasksWithOutInspections = new List <TrainTask>();

            foreach (var item in tasks)
            {
                var attributes = await sqlRTrainTaskAttributes.ByTaskId(item.Id);

                var attributesWithOutInspections = attributes.Where(x => x.InspectionId == null).ToList();
                if (attributesWithOutInspections.Any())
                {
                    tasksWithOutInspections.Add(item);
                }
            }
            result.Rows.AddRange(GetTaskData
                                     (tasksWithOutInspections, _logger).Result);


            result.Total = afterFilterPaginate.Total.ToString();
            return(result);
        }