Exemple #1
0
        public async Task <JsonResult> GetEquipmentsByCarriage(int carriage_id, bool isMark = false, bool sortToTaskList = false)
        {
            await CheckPermission();

            var cr = new CarriageRepository(_logger);
            var mr = new ModelRepository(_logger);

            var carriage = await cr.GetById(carriage_id);

            if (carriage == null)
            {
                throw new Exception("carriage not found");
            }

            var eq = await mr.GetEquipmentByModel(carriage.Model);

            var result = eq.Select(row => new ModelRepository.EquipmentTmp
            {
                EquipmentId      = row.Equipment.Id,
                EquipmentModelId = row.Id,
                EquipmentName    = row.Equipment.Name,
                IsMark           = row.IsMark,
                ParentId         = row.ParentId,
                Id = row.Id
            }).ToArray();

            if (isMark)
            {
                result = result.Where(e => e.IsMark).ToArray();
            }

            if (sortToTaskList)
            {
                var main       = result.Where(e => e.ParentId == 0).ToArray();
                var sortResult = new List <ModelRepository.EquipmentTmp>();
                foreach (var item in main)
                {
                    sortResult.Add(item);
                    sortResult.AddRange(result.Where(e => e.ParentId == item.Id).OrderBy(q => q.EquipmentName));
                }
                foreach (var item in sortResult)
                {
                    if (item.ParentId != 0)
                    {
                        item.EquipmentName = $"  {item.EquipmentName}";
                    }
                }

                result = sortResult.ToArray();
            }

            return(Json(result));
        }
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);
        }