private static bool CheckGeofence(Coche vehiculo, Accion accion, DAOFactory daoFactory) { if (!accion.EvaluaGeocerca) { return(true); } var estados = GeocercaManager.GetEstadoVehiculo(vehiculo, daoFactory); var dentroDeAlguna = estados.GeocercasDentro.Any(geo => geo.Geocerca.TipoReferenciaGeograficaId == accion.TipoGeocerca.Id); return((accion.DentroGeocerca && dentroDeAlguna) || (!accion.DentroGeocerca && !dentroDeAlguna)); }
private void CalcularEstadisticasHoy(Coche coche, IEnumerable <int> idPoiBase) { if ((coche.Dispositivo != null && DAOFactory.TicketDAO.FindEnCurso(coche.Dispositivo) != null) || DAOFactory.ViajeDistribucionDAO.FindEnCurso(coche) != null) { _movilesActivos++; } var ultimaPos = coche.RetrieveLastPosition(); if (ultimaPos != null && ultimaPos.Velocidad > 0) { _movilesEnMovimiento++; } else { _movilesDetenidos++; //var cercas = GeofenceManager.GetGeocercas(coche); var cercasDentro = GeocercaManager.GetEstadoVehiculo(coche, DAOFactory); //var cercasDentro = GeofenceManager.GetGeocercasInside(coche); var maxMonths = coche.Empresa != null ? coche.Empresa.MesesConsultaPosiciones : 3; var entradaEnCerca = ReportFactory.MobileEventDAO.GetMobilesEvents(new List <int> { coche.Id }, new List <int> { _codigoEntrada }, new List <int> { 0 }, _desdeHoy, _hastaHoy, maxMonths); foreach (var cerca in cercasDentro.GeocercasDentro) { if (idPoiBase.Contains(cerca.Geocerca.Id)) { _movilesEnBase++; _detalleBases[cerca.Geocerca.Id] += 1; var ciclo = CicloLogisticoFactory.GetCiclo(coche, null); if (ciclo != null) { _movilesInactivosBase++; } if (entradaEnCerca.Count > 0 && entradaEnCerca[entradaEnCerca.Count - 1].EventTime < DateTime.UtcNow.AddHours(-1)) { _movilesEnBaseMas1Hora++; } } else { _movilesEnGeocerca++; if (entradaEnCerca.Count > 0 && entradaEnCerca[entradaEnCerca.Count - 1].EventTime < DateTime.UtcNow.AddHours(-1)) { _movilesEnGeocercaMas1Hora++; } } } } ///// TICKETS ///// var enServicio = 0; var tickets = DAOFactory.TicketDAO.FindByCocheYFecha(new[] { coche.Empresa != null ? coche.Empresa.Id : coche.Linea != null ? coche.Linea.Empresa.Id : -1 }, new[] { coche.Linea != null ? coche.Linea.Id : -1 }, new[] { coche.Id }, _desdeHoy, _hastaHoy); foreach (var ticket in tickets) { var diferencia = 0; var ultimoEstado = ticket.Detalles.Cast <DetalleTicket>() .Where(d => d.Automatico.HasValue) .LastOrDefault(); if (ultimoEstado != null) { diferencia = Convert.ToInt32(ultimoEstado.Automatico.Value.Subtract(ultimoEstado.Programado.Value).TotalMinutes); } if (Math.Abs(diferencia) <= 5) { _movilesEnHoraHoy++; } else if (diferencia > 0) { _movilesDemoradosHoy++; } else { _movilesAdelantadosHoy++; } if (ticket.Estado == Ticket.Estados.EnCurso && ticket.FechaTicket < DateTime.UtcNow) { enServicio++; var idBase = 0; var idClientes = new List <int>(); if (ticket.Linea != null && ticket.Linea.ReferenciaGeografica != null) { idBase = ticket.Linea.ReferenciaGeografica.Id; } idClientes.Add(ticket.PuntoEntrega.ReferenciaGeografica.Id); if (idBase > 0) { var state = GeocercaManager.GetEstadoGeocerca(coche, idBase, DAOFactory); if (state != null && state.Estado == EstadosGeocerca.Dentro) { _movilesEnPlanta++; } } if (idClientes.Count > 0) { var withGeo = idClientes.Select(c => GeocercaManager.GetEstadoGeocerca(coche, c, DAOFactory)) .Where(s => s != null); if (withGeo.Any(st => st != null && st.Estado == EstadosGeocerca.Dentro)) { _movilesEnCliente++; } } } } _movilesEnViaje = enServicio - _movilesEnPlanta - _movilesEnCliente; }