コード例 #1
0
        //В эксельку кто когда сваливает с депо
        public async Task <ReportResponse> EscapeFromDepoReport(ExcelDataRequest input)
        {
            var sqlRPlaneTrain   = new PlanedRouteTrainsRepository(_logger);
            var sqlRRoute        = new RoutesRepository(_logger);
            var sqlRTrain        = new TrainRepository(_logger);
            var sqlRTrip         = new TripsRepository(_logger);
            var sqlRUser         = new UserRepository(_logger);
            var sqlRPlaneStation = new PlanedStationOnTripsRepository(_logger);
            var sqlRPlaneBrigade = new PlaneBrigadeTrainsRepository(_logger);

            if (input.Date == null)
            {
                throw new ValidationException("Не задан StartDate");
            }

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

            result.Columns = new List <Column>
            {
                new Column("col0", "Маршрут", "string"),
                //№ поезда(Походу рейс https://alcodevelop.atlassian.net/browse/CPPK-4)
                new Column("col1", "№ поезда", "string"),
                new Column("col2", "Машинист", "string"),
                new Column("col3", "Состав", "string"),
                new Column("col4", "КП", "string"),
            };

            //Бля ну получим все поезда наверно
            var planeTrains = await sqlRPlaneTrain.GetAll();

            //За указанные сутки
            planeTrains = planeTrains.Where(x => x.Date.Date == input.Date.Date).ToList();
            foreach (var planeTrain in planeTrains)
            {
                var route = await sqlRRoute.ById(planeTrain.RouteId);

                var train = await sqlRTrain.ById(planeTrain.TrainId);

                //Берем все станки маршрута
                var planeStations = await sqlRPlaneStation.ByPlannedRouteTrainId(planeTrain.Id);

                var startStation = planeStations.OrderBy(x => x.OutTime).FirstOrDefault();

                var trip = new Trip();
                if (startStation != null)
                {
                    trip = await sqlRTrip.ById(startStation.TripId);
                }
                var planeBrigades = await sqlRPlaneBrigade.ByPlanedRouteTrainId(planeTrain.Id);

                //TODO брать 1-го юзера и делать машинистом, както неправильно) хДД
                User motorman = null;
                if (planeBrigades.Count != 0)
                {
                    motorman = await sqlRUser.ById(planeBrigades.First().UserId);
                }

                var toadd = new Row
                {
                    Id       = new RowId(DateTime.Now.Ticks.GetHashCode(), 2),
                    HasItems = false.ToString(),
                    ParentId = null,
                    //Маршрут
                    Col0 = route.Name,
                    //№ поезда(Походу рейс https://alcodevelop.atlassian.net/browse/CPPK-4)
                    Col1 = trip.Name,
                    //Машинист
                    Col2 = motorman?.Name,
                    //Состав
                    Col3 = train.Name,
                    //КП
                    Col4 = startStation?.OutTime.ToStringTimeOnly()
                };

                result.Rows.Add(toadd);
            }


            return(result);
        }
コード例 #2
0
        public async Task <List <PlanedRouteTrainDto> > PlanedRouteTrainsTable(DateTime startTime, DateTime EndTime)
        {
            var sqlRPlanedRouteTrains    = new PlanedRouteTrainsRepository(_logger);
            var sqlRRoutes               = new RoutesRepository(_logger);
            var sqlRTrains               = new TrainRepository(_logger);
            var sqlRUsers                = new UserRepository(_logger);
            var sqlRDayOfROutes          = new DayOfRoutesRepoisitory(_logger);
            var sqlRStations             = new StantionsRepository(_logger);
            var sqlRPlaneStationsOnTrips = new PlanedStationOnTripsRepository(_logger);
            var sqlRPlaneBrigadeTrains   = new PlaneBrigadeTrainsRepository(_logger);
            var planedRouteTrains        = await sqlRPlanedRouteTrains.GetAll();

            planedRouteTrains = planedRouteTrains.Where(x => x.Date >= startTime && x.Date < EndTime).ToList();
            //var result = new List<PlanedRouteTrainDto>();

            var dictionary = new Dictionary <int, PlanedRouteTrainDto>();
            //var routeDictionary = planedRouteTrains.ToDictionary(e => e.RouteId);

            //Собственно надо набить словарик доступными роутами
            var routes = await sqlRRoutes.GetAll(0, Int32.MaxValue, null);

            routes.Data = routes.Data.Where(x => x.TurnoverId != null).ToList();

            foreach (var route in routes.Data)
            {
                var planedRouteTrainDto = new PlanedRouteTrainDto
                {
                    Route     = route,
                    RouteDays = new List <DayOfWeek>(),
                    DaysData  = new List <DayData>()
                };


                if (route.TurnoverId != null)
                {
                    var daysOfRoutes = await sqlRDayOfROutes.DaysByTurnoverId((int)route.TurnoverId);

                    var days = daysOfRoutes.Select(x => x.Day);
                    planedRouteTrainDto.RouteDays.AddRange(days);
                    var proccesDate = startTime;

                    while (proccesDate <= EndTime)
                    {
                        var currentDay = proccesDate.DayOfWeek;
                        if (days.Contains(currentDay))
                        {
                            planedRouteTrainDto.DaysData.Add(new DayData
                            {
                                Date = proccesDate.Date, DateString = proccesDate.Date.ToString()
                            });
                        }
                        proccesDate = proccesDate.AddDays(1);
                    }
                }

                if (dictionary.ContainsKey(route.Id))
                {
                    dictionary[route.Id].DaysData.AddRange(planedRouteTrainDto.DaysData);
                }
                else
                {
                    dictionary.Add(route.Id, planedRouteTrainDto);
                }
            }

            foreach (var planedRouteTrain in planedRouteTrains)
            {
                //достаем роут
                var route = await sqlRRoutes.ById(planedRouteTrain.RouteId);

                //var currentRouteItems = planedRouteTrains.Where(e => e.RouteId == route.Id);
                var planedRouteTrainDto = new PlanedRouteTrainDto
                {
                    Route    = route,
                    DaysData = new List <DayData>()
                };

                var toAdd = new DayData
                {
                    Train = await sqlRTrains.ById(planedRouteTrain.TrainId),
                    PlanedRouteTrainId = planedRouteTrain.Id,
                    Date = planedRouteTrain.Date
                };
                toAdd.DateString = toAdd.Date.ToString("yyyy-MM-ddTHH:mm:ssZ");
                var planeBrigadeTrains = await sqlRPlaneBrigadeTrains.ByPlanedRouteTrainId(planedRouteTrain.Id);

                toAdd.Users = new List <DaysUser>();
                foreach (var planeBrigadeTrain in planeBrigadeTrains)
                {
                    var user = await sqlRUsers.ById(planeBrigadeTrain.UserId);

                    var userToAdd = new DaysUser
                    {
                        UserId = user.Id, Name = user.Name, PlaneBrigadeTrainsId = planeBrigadeTrain.Id
                    };
                    userToAdd.UserStations = new UserStations();
                    var planedStationInput = await sqlRPlaneStationsOnTrips.ById(planeBrigadeTrain.StantionStartId);

                    userToAdd.UserStations.InputTime = planedStationInput.OutTime;
                    userToAdd.UserStations.InputName = (await sqlRStations.ById(planedStationInput.StantionId)).Name;

                    var planedStationOutput = await sqlRPlaneStationsOnTrips.ById(planeBrigadeTrain.StantionEndId);

                    userToAdd.UserStations.OutputTime = planedStationOutput.InTime;
                    userToAdd.UserStations.OutputName = (await sqlRStations.ById(planedStationOutput.StantionId)).Name;
                    //userToAdd.UserStations.InputName = (await sqlRStations.ById(planeBrigadeTrain.StantionStartId)).Name;
                    //userToAdd.UserStations.OutputName = (await sqlRStations.ById(planeBrigadeTrain.StantionEndId)).Name;
                    toAdd.Users.Add(userToAdd);
                }

                planedRouteTrainDto.DaysData.Add(toAdd);


                if (dictionary.ContainsKey(route.Id))
                {
                    //надо взять текущие деньки роута и проверить что такого еще нет. кстати если его нет надо нахуй послать, а если есть заменить.
                    var currentDays = dictionary[route.Id].DaysData;
                    var day         = currentDays.FirstOrDefault(x =>
                                                                 x.Date.Date.Equals(planedRouteTrainDto.DaysData.First().Date.Date));
                    if (day == null)
                    {
                        dictionary[route.Id].DaysData.AddRange(planedRouteTrainDto.DaysData);
                        continue;
                    }

                    //throw new ValidationException("На этот день нельзя добавить поезд");
                    var index = dictionary[route.Id].DaysData.IndexOf(day);
                    dictionary[route.Id].DaysData[index] = planedRouteTrainDto.DaysData.First();
                    //dictionary[route.Id].DaysData.AddRange(planedRouteTrainDto.DaysData);
                }
                else
                {
                    dictionary.Add(route.Id, planedRouteTrainDto);
                }
            }


            //var train = await sqlRTrains.ByIdWithStations(planedRouteTrain.TrainId);

            var result = new List <PlanedRouteTrainDto>();

            result.AddRange(dictionary.Values);

            return(result);
        }