Ejemplo n.º 1
0
        /// <summary>
        /// Analices changes in the current vehicle service.
        /// </summary>
        /// <param name="coche"></param>
        /// <param name="inicio"></param>
        /// <param name="codigo"></param>
        /// <param name="idPuntoDeInteres"></param>
        /// <param name="message"></param>
        private void CheckTicket(Coche coche, GPSPoint inicio, string codigo, Int32?idPuntoDeInteres, IMessage message)
        {
            try
            {
                STrace.Debug(GetType().FullName, "Procesando evento. Codigo={0} Vehiculo={1} Fecha={2} Procesar={3}", codigo, coche.Id, inicio.Date.ToString("dd/MM/yyyy HH:mm:ss"), CicloLogisticoFactory.IsAutomaticCode(codigo));
                // Si no es uno de los codigos que cambian estados automáticos, salgo directamente;))
                if (!CicloLogisticoFactory.IsAutomaticCode(codigo))
                {
                    return;
                }

                var evento = EventFactory.GetEvent(inicio, codigo, idPuntoDeInteres, message);
                if (evento == null)
                {
                    return;
                }

                var ciclo = CicloLogisticoFactory.GetCiclo(coche, new LogMensajeSaver());
                if (ciclo == null)
                {
                    return;
                }

                ciclo.ProcessEvent(evento);
            }
            catch (Exception ex)
            {
                STrace.Exception(GetType().FullName, ex);
            }
        }
Ejemplo n.º 2
0
        protected override List <RetrasoVo> GetResults()
        {
            var inicio = DateTime.UtcNow;

            try
            {
                var coches = DAOFactory.CocheDAO.GetList(new[] { ddlLocation.Selected },
                                                         new[] { ddlPlanta.Selected },
                                                         lbTipoMovil.SelectedValues,
                                                         new[] { -1 },
                                                         lbCentroCosto.SelectedValues)
                             .Where(c => QueryExtensions.IncludesAll((IEnumerable <int>)lbMovil.SelectedValues) ||
                                    lbMovil.SelectedValues.Contains(c.Id));

                var fecha = DateTime.UtcNow;
                fecha = new DateTime(fecha.Year, fecha.Month, fecha.Day, fecha.Hour, fecha.Minute, fecha.Second);

                var results = coches.Select(c => CicloLogisticoFactory.GetCiclo(c, null))
                              .Where(c => c != null)
                              .Where(c => c.Iniciado.AddMinutes(npEnCiclo.Value) < fecha ||
                                     (c.EnGeocerca &&
                                      c.EnGeocercaDesde.HasValue &&
                                      c.EnGeocercaDesde.Value.AddMinutes(npEnGeocerca.Value) < fecha))
                              .Select(c => new RetrasoVo(c, fecha))
                              .ToList();

                var duracion = (DateTime.UtcNow - inicio).TotalSeconds.ToString("##0.00");

                STrace.Trace("Reporte de Retrasos", String.Format("Duración de la consulta: {0} segundos", duracion));

                return(results);
            }
            catch (Exception e)
            {
                STrace.Exception("Reporte de Retrasos", e, String.Format("Reporte: Reporte de Retrasos. Duración de la consulta: {0:##0.00} segundos", (DateTime.UtcNow - inicio).TotalSeconds));

                throw;
            }
        }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        private void ProcessEvent(string code, Event generico)
        {
            string applicationCode;
            var    esConfirmacionUbox = false;

            ControlarInicioDistribucionPorMensaje(code, generico);

            ControlarCierreDistribucionPorMensaje(code, generico);

            if (MessageIdentifierX.IsRfidEvent(generico.Code))
            {
                applicationCode = ProcessRfidEvent(code, generico);
            }
            else if (MessageIdentifierX.IsEstadoLogistico(generico.GetData()))
            {
                applicationCode = ProcessEstadoLogistico(code, generico);
            }
            else if (MessageIdentifierX.IsPanicEvent(code))
            {
                applicationCode = ProcessPanicEvent(generico, code);
            }
            else if (code.Equals(MessageCode.SpeedingTicket.GetMessageCode()))
            {
                applicationCode = ProcessVelocidadExcedidaGenericEvent(generico);
            }
            else if (MessageIdentifierX.IsConfirmacionUbox(generico.GetData()))
            {
                applicationCode    = code;
                esConfirmacionUbox = true;
                // DEFINE EL PROCESAMIENTO CUANDO SABE SI TIENE UN PUNTO
            }
            else
            {
                applicationCode = ProcessGenericEvent(generico, code);
            }

            if (DaoFactory.DetalleDispositivoDAO.GetProcesarCicloLogisticoFlagValue(generico.DeviceId))
            {
                GPSPoint point = null;
                if (generico.GeoPoint != null)
                {
                    point = GPSPoint.Factory(generico.GeoPoint.Date, generico.GeoPoint.Lat, generico.GeoPoint.Lon);
                }
                else
                {
                    var maxMonths = Coche.Empresa != null ? Coche.Empresa.MesesConsultaPosiciones : 3;
                    var pos       = DaoFactory.LogPosicionDAO.GetFirstPositionOlderThanDate(Coche.Id, generico.Tiempo, maxMonths);
                    if (pos != null)
                    {
                        point = GPSPoint.Factory(generico.Tiempo, (float)pos.Latitud, (float)pos.Longitud);
                    }
                }

                if (point != null)
                {
                    if (esConfirmacionUbox)
                    {
                        ProcessConfirmacionUbox(code, generico, point);
                    }
                    else
                    {
                        CicloLogisticoFactory.Process(DaoFactory, applicationCode, Coche, point, generico, false, GetChofer(generico.GetRiderId()));
                        CicloLogisticoFactory.ProcessEstadoLogistico(Coche, generico, applicationCode);
                    }
                }
                else if (esConfirmacionUbox)
                {
                    ProcessGenericEvent(generico, code);
                }
            }
        }