public async Task <List <PlanByRouteModel> > GetPlannedNumberByRouteAsync(DateTime date) { var plans = await _planRepository.GetByDateAsync(date); var factObjects = await _factOfObjectRouteRepository.GetByDateAsync(date); var outBuses = await _dictionariesCacheHelper.GetOutBusesByDate(date); var projectRoutes = await _projectRouteRepository.GetAllActiveAsync(); var result = projectRoutes .Select(x => x.RouteId) .Distinct() .Select(routeId => { var plan = plans.FirstOrDefault(pl => pl.RoutId == routeId); var fact = factObjects.FirstOrDefault(f => f.RouteId == routeId); var projectRoute = projectRoutes.FirstOrDefault(pr => pr.RouteId == routeId); var item = new PlanByRouteModel { RouteId = routeId, ProjectId = projectRoute != null ? projectRoute.ProjectId : 0, FactNumber = fact != null ? fact.CountObjects : 0, PlannedNumber = plan != null ? plan.TypePlannedTotal : 0, OutBusesNumber = outBuses.Where(x => x.RouteId == routeId).Count() }; return(item); }) .ToList(); return(result); }
public async Task <List <ObjectModel> > FindForReportingInvalidAsync(int minutes, int routeId) { var startDate = DateTime.Now.AddMinutes(-minutes); var endDate = DateTime.Now.AddMinutes(1); var outBuses = await _dictionariesCacheHelper.GetOutBusesByDate(DateTime.Now); var outBusesGroup = outBuses.GroupBy(x => x.RouteId).ToList(); var activeObjects = await _objectsCacheHelper.GetActiveObjects(); var objects = activeObjects .Where(x => x.LastRouteId == routeId) .Where(entity => { var isUnavailable = !IsOnline(entity, startDate, endDate); var outBusesGr = outBusesGroup.FirstOrDefault(x => x.Key == entity.LastRouteId.Value); if (outBusesGr == null) { //нет наряда для маршрута return(isUnavailable); } else { //есть наряд для маршрута var shouldBeOnLine = outBusesGr.Any(x => x.ObjectId == entity.Id); if (shouldBeOnLine) { //автобусы В наряде и не откликается return(isUnavailable); } else { //автобусы НЕ в наряде и откликается return(!isUnavailable); } } }) .OrderByDescending(x => x.LastStationTime) .ThenByDescending(x => x.LastTime) .ToList(); var result = MapToModel <ObjectModel>(objects); return(result); }