SELECT COUNT(*) FROM `reportes_integracion`
WHERE reporte_idempresa = 26 AND reporte_procesado = 1

SELECT * FROM `reportes_integracion`
WHERE reporte_idempresa = 26 AND reporte_procesado = 1
ORDER BY reporte_fechagps DESC

SELECT reporte_idempresa,COUNT(*) FROM 
gps_reportes.reportes_integracion
WHERE reporte_procesado = 0
GROUP BY reporte_idempresa
ORDER BY COUNT(*) DESC

SELECT DATE_FORMAT(reporte_fechagps, '%Y-%m-%d %H:%i') AS minuto,COUNT(*) FROM 
gps_reportes.reportes_integracion
WHERE reporte_idempresa = 26 AND reporte_procesado = 1 
GROUP BY DATE_FORMAT(reporte_fechagps, '%Y-%m-%d %H:%i')
ORDER BY reporte_fechagps DESC LIMIT 100


SELECT  a.IdReporte, Reporte_fecharecibido, Reporte_recibido, d.Movil_Dominio, c.AsigDisp_IdMovil, a.Reporte_Evento, 
                   a.Reporte_Latitud, a.Reporte_Longitud, 
                   a.Reporte_Velocidad, DATE_FORMAT(DATE_ADD(a.Reporte_FechaGPS, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   DATE_FORMAT(DATE_ADD(a.Reporte_FechaServidor, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   LOWER(a.Reporte_EventoDescripcion) ,a.Reporte_Rumbo, a.Reporte_Direccion
                   ,Reporte_Ignicion, f.Clie_RazonSocial 
                   FROM gps_reportes.reportes_integracion AS a 
                   LEFT JOIN gps.dispositivos AS b ON b.Disp_ID = a.Reporte_IdDisp AND Disp_Estado = 2 
                   LEFT JOIN gps.asignacion_dispositivo AS c ON c.AsigDisp_IdDispositivo = b.IdDispositivo AND AsigDisp_Estado = 1 
                   LEFT JOIN gps.moviles AS d ON d.IdMovil = c.AsigDisp_IdMovil AND Movil_Estado = 1 
                   LEFT JOIN gps.clientes f ON d.Movil_IdCliente = f.IdCliente 
                   WHERE a.Reporte_Procesado = 1 AND a.Reporte_IdEmpresa = 26 
                   ORDER BY Reporte_recibido DESC  LIMIT 500
                    

SELECT * FROM `reportes_integracion_test`



SELECT * FROM `ultima_posicion` 
WHERE reporte_puerto = '7002' ORDER BY reporte_fechagps DESC

DELETE FROM `ultima_posicion` 
WHERE reporte_puerto = '7020' AND reporte_fechagps < '2025-05-22'




SELECT * FROM gps_reportes.LOG_868574040446523 ORDER BY reporte_fechagps DESC LIMIT 100

+RESP:GTFRI,270D04,867162029614856,gv300w,14243,10,1,1,12.0,155,11.5,-58.486834,-34.710622,20250527151645,0722,0007,1165,37B985,00,0.0,,,,100,220900,,,,20250527151631,12DD


SELECT  a.IdReporte, Reporte_fecharecibido, Reporte_recibido, d.Movil_Dominio, c.AsigDisp_IdMovil, a.Reporte_Evento, 
                   a.Reporte_Latitud, a.Reporte_Longitud, 
                   a.Reporte_Velocidad, DATE_FORMAT(DATE_ADD(a.Reporte_FechaGPS, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   DATE_FORMAT(DATE_ADD(a.Reporte_FechaServidor, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   LOWER(a.Reporte_EventoDescripcion) ,a.Reporte_Rumbo, a.Reporte_Direccion
                   ,Reporte_Ignicion, f.Clie_RazonSocial 
                   FROM gps_reportes.reportes_integracion AS a 
                   LEFT JOIN gps.dispositivos AS b ON b.Disp_ID = a.Reporte_IdDisp AND Disp_Estado = 2 
                   LEFT JOIN gps.asignacion_dispositivo AS c ON c.AsigDisp_IdDispositivo = b.IdDispositivo AND AsigDisp_Estado = 1 
                   LEFT JOIN gps.moviles AS d ON d.IdMovil = c.AsigDisp_IdMovil AND Movil_Estado = 1 
                   LEFT JOIN gps.clientes f ON d.Movil_IdCliente = f.IdCliente 
                   WHERE Movil_Dominio = 'CQB905' 
                   ORDER BY Reporte_fechagps DESC  LIMIT 500
                   
                   
 SELECT * FROM  `alertas_controles` LIMIT 10                 
SELECT a.Reporte_Recibido,a.Reporte_FechaRecibido,a.IdReporte, d.Movil_Dominio, c.AsigDisp_IdMovil, a.Reporte_Evento, 
                   a.Reporte_Latitud, a.Reporte_Longitud, 
                   a.Reporte_Velocidad, DATE_FORMAT(DATE_ADD(a.Reporte_FechaGPS, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   DATE_FORMAT(DATE_ADD(a.Reporte_FechaServidor, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   LOWER(a.Reporte_EventoDescripcion) ,a.Reporte_Rumbo, a.Reporte_Direccion 
                   ,Reporte_Ignicion, f.Clie_RazonSocial  
                   FROM gps_reportes.reportes_integracion AS a 
                   LEFT JOIN gps.dispositivos AS b ON b.Disp_ID = a.Reporte_IdDisp AND Disp_Estado = 2 
                   LEFT JOIN gps.asignacion_dispositivo AS c ON c.AsigDisp_IdDispositivo = b.IdDispositivo AND AsigDisp_Estado = 1 
                   LEFT JOIN gps.moviles AS d ON d.IdMovil = c.AsigDisp_IdMovil AND Movil_Estado = 1 
                   LEFT JOIN gps.clientes f ON d.Movil_IdCliente = f.IdCliente 
                   WHERE a.Reporte_Procesado = 1 AND a.Reporte_IdEmpresa = 26 
                   ORDER BY a.Reporte_Recibido DESC  LIMIT 10500;
                   
  SELECT *
                   FROM gps_reportes.reportes_integracion AS a 
                  
                   WHERE a.Reporte_Procesado = 1 AND a.Reporte_IdEmpresa = 26 
                  ORDER BY Reporte_Recibido DESC


SELECT a.Reporte_Recibido,a.Reporte_FechaRecibido,a.IdReporte, d.Movil_Dominio, c.AsigDisp_IdMovil, a.Reporte_Evento, 
                   a.Reporte_Latitud, a.Reporte_Longitud, 
                   a.Reporte_Velocidad, DATE_FORMAT(DATE_ADD(a.Reporte_FechaGPS, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   DATE_FORMAT(DATE_ADD(a.Reporte_FechaServidor, INTERVAL 3 HOUR), '%Y-%m-%dT%H:%i:%s'), 
                   LOWER(a.Reporte_EventoDescripcion) ,a.Reporte_Rumbo, a.Reporte_Direccion 
                   ,Reporte_Ignicion, f.Clie_RazonSocial  
                   FROM gps_reportes.reportes_integracion AS a 
                   LEFT JOIN gps.dispositivos AS b ON b.Disp_ID = a.Reporte_IdDisp AND Disp_Estado = 2 
                   LEFT JOIN gps.asignacion_dispositivo AS c ON c.AsigDisp_IdDispositivo = b.IdDispositivo AND AsigDisp_Estado = 1 
                   LEFT JOIN gps.moviles AS d ON d.IdMovil = c.AsigDisp_IdMovil AND Movil_Estado = 1 
                   LEFT JOIN gps.clientes f ON d.Movil_IdCliente = f.IdCliente 
                   WHERE a.Reporte_Procesado = 1 AND a.Reporte_IdEmpresa = 26 
                   ORDER BY a.Reporte_Recibido DESC  LIMIT 10500;
                   
  SELECT *
                   FROM gps_reportes.reportes_integracion AS a 
                  
                   WHERE a.Reporte_Procesado = 1 AND a.Reporte_IdEmpresa = 26 
                  ORDER BY Reporte_Recibido DESC
SELECT DISTINCT
IdControlAlerta,IdAlerControl, Movil_Dominio, Movil_Nombre , AlerControl_FechaGPS, AlerControl_TextoInforme, AlerControl_Velocidad, TRIM(Destinatario_Email) AS Destinatario_Email,
Informe_Nombre, Informe_Texto, AlerControl_IdInforme, AsignacionDestinatarios_IdDestinatario, AlerControl_Tipo, Clie_RazonSocial, Destinatario_IdCliente,
AlerControl_Mail, AlerControl_Latitud, AlerControl_Longitud, IdMovil, Destinatario_Nombre 
FROM gps.alertas_controles
LEFT JOIN gps.control_alertas ON IdControlAlerta = AlerControl_IdControl
LEFT JOIN gps.moviles ON AlerControl_Movil = IdMovil AND Movil_Estado = 1
LEFT JOIN gps.dispositivos_configuracion ON AlerControl_Evento = DispConf_NroEvento
LEFT JOIN gps.asignacion_destinatarios ON AsignacionDestinatarios_IdControl = AlerControl_IdControl
LEFT JOIN gps.destinatarios ON AsignacionDestinatarios_IdDestinatario = IdDestinatario AND Destinatario_IdUsuario = ControlAlerta_IdUsuario
LEFT JOIN gps.clientes ON Destinatario_IdCliente = IdCliente
LEFT JOIN gps.informes ON AlerControl_IdInforme = IdInforme
LEFT JOIN gps.lista_negra ON ListaNegra_Email = LENGTH(TRIM(Destinatario_Email)) 
WHERE  Movil_Dominio IS NOT NULL
AND LENGTH(TRIM(Destinatario_Email)) > 6 
AND Movil_Dominio = 'AC750QW' AND Clie_Estado = 1  AND AlerControl_FechaGPS >= DATE_SUB(NOW(), INTERVAL 8 DAY)
AND AlerControl_FechaGPS > '2025-06-06 19:54:50'
ORDER BY AlerControl_FechaGPS DESC, AsignacionDestinatarios_IdDestinatario DESC
LIMIT 100

SELECT * FROM asignacion_controles WHERE asignacioncontroles_idcontrol = 3608

SELECT * FROM `control_alertas` WHERE `IdControlAlerta` = 3608

SELECT * FROM `criterios` WHERE `IdCriterio` IN(3946,4961)

SELECT reporte_completo FROM gps_reportes.LOG_867162026038539 WHERE reporte_fechagps > '2025-06-06 09:54:50' AND  reporte_fechagps < '2025-06-08 18:54:50' ORDER BY reporte_fechagps DESC LIMIT 100

